@kent-tokyo/chematic 1.0.11 → 1.0.13

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.
package/README.md CHANGED
@@ -29,7 +29,8 @@ npm install @kent-tokyo/chematic
29
29
  deterministic input indices and partial/complete status; bounded malformed
30
30
  XYZ frames are grouped inline as rejected records when a later count-line
31
31
  boundary is recoverable (core file-backed readers remain fail-stop)
32
- - Bounded topology parsing for CML, ChemicalJSON (`mol_from_cjson`), MolJSON,
32
+ - Bounded topology parsing for CML (`mol_from_cml_strict` provides the opt-in
33
+ non-empty, balanced, single-root boundary), ChemicalJSON (`mol_from_cjson`), MolJSON,
33
34
  CDXML, MOL2, and PDB/mmCIF
34
35
  - PDBx/mmCIF, PQR, QCSchema JSON, ORCA input/output, Gaussian Cube, OpenDX,
35
36
  and LAMMPS data/dump I/O (JSON-based bindings; see `format_io.rs`)
@@ -167,12 +168,54 @@ portable across native and `wasm32-unknown-unknown`
167
168
  precision across every JS engine, only that the value is finite, non-negative,
168
169
  and enforced correctly on all of them.
169
170
 
171
+ ## V3000 SGROUP syntax view
172
+
173
+ `v3000_sgroups_json(block)` exposes bounded, typed SGROUP syntax without
174
+ expanding polymer or Markush semantics. It preserves source order for unknown
175
+ attributes and returns `kindToken` for unknown group kinds. Group IDs, parent
176
+ references, atom references, and grouped-field counts are validated before
177
+ JSON is returned.
178
+
179
+ ```js
180
+ const groups = JSON.parse(v3000_sgroups_json(v3000Block));
181
+ // [{ id, kind, parentId, atomIds, attributes, kindToken? }]
182
+ ```
183
+
184
+ This is a syntax-level API; it does not claim polymer expansion, Markush
185
+ interpretation, or cross-engine semantic compatibility.
186
+
170
187
  ## Bundle Size
171
188
 
172
- The optimized v1.0.10 candidate artifact was measured at **3.73 MB raw / 1.36 MB gzip**. Bundle size depends on features and toolchain; see [`benchmarks/2026-09-09-wasm-size-v1.0.10.md`](../../benchmarks/2026-09-09-wasm-size-v1.0.10.md) for exact tools, digest, and reproduction steps.
189
+ The optimized v1.0.12 artifact was measured at **3.93 MB raw / 1.43 MB gzip**. Bundle size depends on features and toolchain; see [`benchmarks/2026-09-11-official-rdkit-js-v1.0.12.md`](../../benchmarks/2026-09-11-official-rdkit-js-v1.0.12.md) for exact tools, digest, and reproduction steps.
173
190
 
174
191
  PNG rasterization (`tiny_skia`) is excluded from the WASM build — use SVG output instead. All SVG depiction APIs remain fully available.
175
192
 
193
+ ## Versioned document binding boundary
194
+
195
+ The `*_v1` document APIs provide a stable JSON boundary for downstream editors:
196
+
197
+ ```js
198
+ const parsed = JSON.parse(reaction_document_json_v1(JSON.stringify(document)));
199
+ const edited = JSON.parse(edit_reaction_document_json_v1(
200
+ JSON.stringify(parsed),
201
+ JSON.stringify({ kind: "set_step_condition", step_id: "step-1", key: "temperature", value: "25 C" }),
202
+ ));
203
+
204
+ const cdxmlEnvelope = JSON.parse(cdxml_document_json_v1(cdxml));
205
+ const cdxmlAgain = cdxml_document_from_json_v1(JSON.stringify(cdxmlEnvelope));
206
+ ```
207
+
208
+ `cdxml_document_json_v1` retains the exact `source` string and returns a
209
+ structural `document` summary with opaque objects and `diagnostics`. Use
210
+ `edit_cdxml_document_json_v1` for bounded page/object edits; it reparses the
211
+ result before returning. Errors are JSON-shaped with stable `code`, `path`, and
212
+ `message` fields (`malformed_input`, `resource_limit`,
213
+ `unsupported_construct`, `lossy_conversion`, or `serialization_error`).
214
+ `reaction_document_to_rxn_v1` and `cdxml_document_projection_json_v1` reject
215
+ lossy legacy projections with `lossy_conversion` diagnostics. These APIs do not claim
216
+ mechanism correctness, product prediction, complete stoichiometry, or full
217
+ ChemDraw/RXN compatibility.
218
+
176
219
  ## Building from source
177
220
 
178
221
  ```sh
@@ -593,6 +593,11 @@ export function canonical_tautomer_with_blocked_atoms_json(mol: MolHandle, block
593
593
  */
594
594
  export function canonicalize_smiles_batch_json(smiles_batch: string, delimiter: string): string;
595
595
 
596
+ /**
597
+ * Validate a versioned CDXML JSON envelope and serialize its exact source.
598
+ */
599
+ export function cdxml_document_from_json_v1(document_json: string): string;
600
+
596
601
  /**
597
602
  * Parse a CDXML document while preserving page and presentation objects.
598
603
  * The returned JSON contains an opaque `raw_xml` for each object so unknown
@@ -600,6 +605,22 @@ export function canonicalize_smiles_batch_json(smiles_batch: string, delimiter:
600
605
  */
601
606
  export function cdxml_document_json(cdxml: string): string;
602
607
 
608
+ /**
609
+ * Return a loss-preserving, versioned JSON envelope for a CDXML document.
610
+ *
611
+ * `source` is retained for exact re-serialization; `document` is the stable
612
+ * structural summary used by editors. Unknown objects remain in the summary
613
+ * and are listed under `document.diagnostics`.
614
+ */
615
+ export function cdxml_document_json_v1(cdxml: string): string;
616
+
617
+ /**
618
+ * Project a CDXML document to its first molecular fragment only when no
619
+ * presentation data would be lost. Unknown/presentation objects are reported
620
+ * as an explicit lossy conversion instead of being silently dropped.
621
+ */
622
+ export function cdxml_document_projection_json_v1(cdxml: string): string;
623
+
603
624
  /**
604
625
  * Parse all molecular fragments from a CDXML string.
605
626
  *
@@ -872,6 +893,18 @@ export function ecfp_bitvec_custom(mol: MolHandle, radius: number, nbits: number
872
893
  */
873
894
  export function edit_cdxml_document_json(cdxml: string, edit_json: string): string;
874
895
 
896
+ /**
897
+ * Apply a bounded CDXML edit to a versioned JSON envelope and return the
898
+ * updated envelope. The source is reparsed after editing, so paths and
899
+ * diagnostics cannot drift from the returned document summary.
900
+ */
901
+ export function edit_cdxml_document_json_v1(document_json: string, edit_json: string): string;
902
+
903
+ /**
904
+ * Apply a bounded, stable-ID reaction-document edit and return canonical JSON.
905
+ */
906
+ export function edit_reaction_document_json_v1(document_json: string, edit_json: string): string;
907
+
875
908
  /**
876
909
  * Run `embed_ensemble_v2` on `mol`'s own atom order (never canonicalizes/
877
910
  * reparses, same convention as `embed_pipeline_v2_json`). See the module doc
@@ -1456,7 +1489,7 @@ export function minimize_mmff94_lbfgs_json(mol: MolHandle, max_iter: number): st
1456
1489
  * `coords_json` — JSON array of `[x,y,z]` arrays (Å), one per atom.
1457
1490
  * `max_iter` — maximum iterations (0 = default 500).
1458
1491
  *
1459
- * Returns JSON: `{"coords":[[x,y,z],...], "energy":float, "iterations":int, "converged":bool, "sound":bool, "worst_bond_length":float}`
1492
+ * Returns JSON: `{"coords":[[x,y,z],...], "energy":float, "iterations":int, "converged":bool, "sound":bool, "worst_bond_length":float, "rejected_unsound_step":bool}`
1460
1493
  * or `{"error":"<msg>"}` on failure. `sound` is all-finite coordinates and
1461
1494
  * no bond stretched past a sane covalent-bond length — independent of
1462
1495
  * `converged`, since steepest descent often reports `converged:false` on
@@ -1619,6 +1652,14 @@ export function mol_from_cjson(json: string): MolHandle;
1619
1652
  */
1620
1653
  export function mol_from_cml(cml: string): MolHandle;
1621
1654
 
1655
+ /**
1656
+ * Parse a structurally valid, non-empty CML string into a `MolHandle`.
1657
+ *
1658
+ * This opt-in strict boundary rejects missing/empty molecules and malformed
1659
+ * XML while `mol_from_cml` retains its historical lenient behavior.
1660
+ */
1661
+ export function mol_from_cml_strict(cml: string): MolHandle;
1662
+
1622
1663
  /**
1623
1664
  * Parse a Gaussian Cube file and return a `MolHandle` (topology only --
1624
1665
  * element list, no bonds; Cube carries no bond table). Use
@@ -2167,6 +2208,21 @@ export function rdkit_rdk_bitvec(mol: MolHandle): Uint8Array;
2167
2208
  */
2168
2209
  export function rdkit_torsion_bitvec(mol: MolHandle): Uint8Array;
2169
2210
 
2211
+ /**
2212
+ * Validate and deterministically serialize a rich reaction document JSON.
2213
+ *
2214
+ * This is the versioned JSON boundary for WASM consumers. It preserves IDs,
2215
+ * metadata, and provenance, and rejects malformed documents before returning
2216
+ * JSON. Use [`edit_reaction_document_json_v1`] for bounded ID-addressed edits.
2217
+ */
2218
+ export function reaction_document_json_v1(document_json: string): string;
2219
+
2220
+ /**
2221
+ * Convert a rich reaction document to legacy RXN V2000 with structured loss
2222
+ * reporting. A lossy projection is never returned as if it were complete.
2223
+ */
2224
+ export function reaction_document_to_rxn_v1(document_json: string): string;
2225
+
2170
2226
  /**
2171
2227
  * Check whether a reaction SMILES matches a reaction SMARTS query.
2172
2228
  *
@@ -2237,6 +2293,17 @@ export function rgroup_decompose_json(smiles_json: string, core_smarts: string):
2237
2293
  */
2238
2294
  export function ring_families_json(mol: MolHandle): string;
2239
2295
 
2296
+ /**
2297
+ * Parse and serialize a V3000 block while preserving V3000 metadata.
2298
+ *
2299
+ * Unlike the topology-only [`mol_from_v3000_block`] + [`to_mol_v3000_block`]
2300
+ * pair, this explicit round-trip API retains `SGROUP` logical lines and
2301
+ * `COLLECTION` stereo groups. SGROUP polymer/query expansion is still out of
2302
+ * scope, but the typed syntax view is available through
2303
+ * [`v3000_sgroups_json`].
2304
+ */
2305
+ export function roundtrip_mol_v3000_block(block: string): string;
2306
+
2240
2307
  /**
2241
2308
  * Apply a SMIRKS reaction template and return product SMILES as a JSON string.
2242
2309
  *
@@ -2345,6 +2412,11 @@ export function semantic_apply_json_command(model_json: string, command_json: st
2345
2412
  */
2346
2413
  export function semantic_expand_json(base_smiles: string, model_json: string): string;
2347
2414
 
2415
+ /**
2416
+ * Expand a validated semantic model with explicit finite atom/repeat budgets.
2417
+ */
2418
+ export function semantic_expand_json_with_limits(base_smiles: string, model_json: string, max_atoms: number, max_repeat_count: number): string;
2419
+
2348
2420
  /**
2349
2421
  * Validate and normalize a typed Markush/polymer semantic model JSON.
2350
2422
  */
@@ -2472,6 +2544,14 @@ export function start(): void;
2472
2544
  */
2473
2545
  export function stereo_parent_json(mol: MolHandle): string;
2474
2546
 
2547
+ /**
2548
+ * Analyze a rich reaction document's explicit atom/isotope inventory and
2549
+ * formal charges. The returned JSON includes evidence scope, per-step
2550
+ * diagnostics, and a status that does not imply chemical completeness.
2551
+ * Returns `error:<msg>` when the document or a component is invalid.
2552
+ */
2553
+ export function stoichiometry_report_json(document_json: string): string;
2554
+
2475
2555
  /**
2476
2556
  * Compute the composed Super Parent with explicit resource limits.
2477
2557
  */
@@ -2631,6 +2711,8 @@ export function topo_path_bitvec(mol: MolHandle): Uint8Array;
2631
2711
  */
2632
2712
  export function torsion_bitvec(mol: MolHandle): Uint8Array;
2633
2713
 
2714
+ export function v3000_sgroups_json(block: string): string;
2715
+
2634
2716
  /**
2635
2717
  * Validate a vendor-neutral NMR spectrum JSON document without parsing a
2636
2718
  * vendor-specific raw file or predicting peaks.
@@ -2782,7 +2864,10 @@ export interface InitOutput {
2782
2864
  readonly canonical_tautomer: (a: number) => number;
2783
2865
  readonly canonical_tautomer_with_blocked_atoms_json: (a: number, b: number, c: number) => [number, number];
2784
2866
  readonly canonicalize_smiles_batch_json: (a: number, b: number, c: number, d: number) => [number, number, number, number];
2867
+ readonly cdxml_document_from_json_v1: (a: number, b: number) => [number, number, number, number];
2785
2868
  readonly cdxml_document_json: (a: number, b: number) => [number, number, number, number];
2869
+ readonly cdxml_document_json_v1: (a: number, b: number) => [number, number, number, number];
2870
+ readonly cdxml_document_projection_json_v1: (a: number, b: number) => [number, number, number, number];
2786
2871
  readonly cdxml_to_smiles_json: (a: number, b: number) => [number, number, number, number];
2787
2872
  readonly charge_parent_json: (a: number) => [number, number];
2788
2873
  readonly chematic_version: () => [number, number];
@@ -2835,6 +2920,8 @@ export interface InitOutput {
2835
2920
  readonly ecfp6_bitvec_with_chirality: (a: number, b: number) => [number, number];
2836
2921
  readonly ecfp_bitvec_custom: (a: number, b: number, c: number, d: number) => [number, number];
2837
2922
  readonly edit_cdxml_document_json: (a: number, b: number, c: number, d: number) => [number, number, number, number];
2923
+ readonly edit_cdxml_document_json_v1: (a: number, b: number, c: number, d: number) => [number, number, number, number];
2924
+ readonly edit_reaction_document_json_v1: (a: number, b: number, c: number, d: number) => [number, number, number, number];
2838
2925
  readonly embed_ensemble_v2_json: (a: number, b: number, c: number) => [number, number];
2839
2926
  readonly embed_pipeline_v2_json: (a: number, b: number, c: number) => [number, number];
2840
2927
  readonly enumerate_library_2way: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
@@ -2912,6 +2999,7 @@ export interface InitOutput {
2912
2999
  readonly mol_from_cdxml: (a: number, b: number) => [number, number, number];
2913
3000
  readonly mol_from_cjson: (a: number, b: number) => [number, number, number];
2914
3001
  readonly mol_from_cml: (a: number, b: number) => [number, number, number];
3002
+ readonly mol_from_cml_strict: (a: number, b: number) => [number, number, number];
2915
3003
  readonly mol_from_cube: (a: number, b: number) => [number, number, number];
2916
3004
  readonly mol_from_extxyz: (a: number, b: number) => [number, number, number];
2917
3005
  readonly mol_from_mmcif: (a: number, b: number) => [number, number, number];
@@ -2936,7 +3024,6 @@ export interface InitOutput {
2936
3024
  readonly molecule_report_json: (a: number, b: number) => [number, number, number, number];
2937
3025
  readonly molhandle_aromatic_ring_count: (a: number) => number;
2938
3026
  readonly molhandle_assign_cip_json: (a: number) => [number, number];
2939
- readonly molhandle_atom_count: (a: number) => number;
2940
3027
  readonly molhandle_bbb_passes: (a: number) => number;
2941
3028
  readonly molhandle_bbb_score: (a: number) => number;
2942
3029
  readonly molhandle_bertz_ct: (a: number) => number;
@@ -3049,11 +3136,14 @@ export interface InitOutput {
3049
3136
  readonly rdkit_path_bitvec: (a: number) => [number, number];
3050
3137
  readonly rdkit_rdk_bitvec: (a: number) => [number, number];
3051
3138
  readonly rdkit_torsion_bitvec: (a: number) => [number, number];
3139
+ readonly reaction_document_json_v1: (a: number, b: number) => [number, number, number, number];
3140
+ readonly reaction_document_to_rxn_v1: (a: number, b: number) => [number, number, number, number];
3052
3141
  readonly reaction_smarts_match: (a: number, b: number, c: number, d: number) => [number, number, number];
3053
3142
  readonly remove_hydrogens: (a: number) => number;
3054
3143
  readonly retro_disconnect_json: (a: number, b: number, c: number, d: number) => [number, number, number, number];
3055
3144
  readonly rgroup_decompose_json: (a: number, b: number, c: number, d: number) => [number, number, number, number];
3056
3145
  readonly ring_families_json: (a: number) => [number, number, number, number];
3146
+ readonly roundtrip_mol_v3000_block: (a: number, b: number) => [number, number, number, number];
3057
3147
  readonly run_reactants: (a: number, b: number, c: number, d: number) => [number, number, number, number];
3058
3148
  readonly rxn_document_from_rxn: (a: number, b: number) => [number, number, number, number];
3059
3149
  readonly rxn_document_to_rxn: (a: number, b: number) => [number, number, number, number];
@@ -3065,6 +3155,7 @@ export interface InitOutput {
3065
3155
  readonly sdf_to_smiles_json: (a: number, b: number) => [number, number];
3066
3156
  readonly semantic_apply_json_command: (a: number, b: number, c: number, d: number) => [number, number, number, number];
3067
3157
  readonly semantic_expand_json: (a: number, b: number, c: number, d: number) => [number, number, number, number];
3158
+ readonly semantic_expand_json_with_limits: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
3068
3159
  readonly semantic_model_json: (a: number, b: number) => [number, number, number, number];
3069
3160
  readonly set_dihedral_json: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
3070
3161
  readonly shape_descriptors_json: (a: number) => [number, number];
@@ -3079,8 +3170,8 @@ export interface InitOutput {
3079
3170
  readonly sssr_rings_json: (a: number) => [number, number];
3080
3171
  readonly standardize_smiles: (a: number, b: number) => [number, number];
3081
3172
  readonly standardize_smiles_report_json: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
3082
- readonly start: () => void;
3083
3173
  readonly stereo_parent_json: (a: number) => [number, number];
3174
+ readonly stoichiometry_report_json: (a: number, b: number) => [number, number];
3084
3175
  readonly super_parent_json: (a: number, b: number, c: number, d: number, e: bigint) => [number, number];
3085
3176
  readonly super_parent_report_json: (a: number, b: number, c: number, d: number, e: bigint) => [number, number];
3086
3177
  readonly tanimoto_atom_pair: (a: number, b: number) => number;
@@ -3104,6 +3195,7 @@ export interface InitOutput {
3104
3195
  readonly to_xyz: (a: number) => [number, number];
3105
3196
  readonly topo_path_bitvec: (a: number) => [number, number];
3106
3197
  readonly torsion_bitvec: (a: number) => [number, number];
3198
+ readonly v3000_sgroups_json: (a: number, b: number) => [number, number, number, number];
3107
3199
  readonly validate_nmr_spectrum_json: (a: number, b: number) => [number, number];
3108
3200
  readonly virtual_screen_ecfp4_json: (a: number, b: number, c: number, d: number, e: number) => [number, number];
3109
3201
  readonly whim_descriptors_json: (a: number) => [number, number];
@@ -3121,6 +3213,8 @@ export interface InitOutput {
3121
3213
  readonly xlogp3_json: (a: number) => [number, number];
3122
3214
  readonly xlogp3_per_atom_json: (a: number) => [number, number];
3123
3215
  readonly xyz_frames_batch_json: (a: number, b: number, c: number, d: number) => [number, number, number, number];
3216
+ readonly molhandle_atom_count: (a: number) => number;
3217
+ readonly start: () => void;
3124
3218
  readonly __wbindgen_malloc: (a: number, b: number) => number;
3125
3219
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
3126
3220
  readonly __externref_table_alloc: () => number;
package/chematic_wasm.js CHANGED
@@ -104,7 +104,7 @@ export class ConformerHandle {
104
104
  const ret = wasm.conformerhandle_get_conformer_pdb(this.__wbg_ptr, idx);
105
105
  let v1;
106
106
  if (ret[0] !== 0) {
107
- v1 = getStringFromWasm0(ret[0], ret[1]);
107
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
108
108
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
109
109
  }
110
110
  return v1;
@@ -1401,6 +1401,32 @@ export function canonicalize_smiles_batch_json(smiles_batch, delimiter) {
1401
1401
  }
1402
1402
  }
1403
1403
 
1404
+ /**
1405
+ * Validate a versioned CDXML JSON envelope and serialize its exact source.
1406
+ * @param {string} document_json
1407
+ * @returns {string}
1408
+ */
1409
+ export function cdxml_document_from_json_v1(document_json) {
1410
+ let deferred3_0;
1411
+ let deferred3_1;
1412
+ try {
1413
+ const ptr0 = passStringToWasm0(document_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1414
+ const len0 = WASM_VECTOR_LEN;
1415
+ const ret = wasm.cdxml_document_from_json_v1(ptr0, len0);
1416
+ var ptr2 = ret[0];
1417
+ var len2 = ret[1];
1418
+ if (ret[3]) {
1419
+ ptr2 = 0; len2 = 0;
1420
+ throw takeFromExternrefTable0(ret[2]);
1421
+ }
1422
+ deferred3_0 = ptr2;
1423
+ deferred3_1 = len2;
1424
+ return getStringFromWasm0(ptr2, len2);
1425
+ } finally {
1426
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1427
+ }
1428
+ }
1429
+
1404
1430
  /**
1405
1431
  * Parse a CDXML document while preserving page and presentation objects.
1406
1432
  * The returned JSON contains an opaque `raw_xml` for each object so unknown
@@ -1429,6 +1455,64 @@ export function cdxml_document_json(cdxml) {
1429
1455
  }
1430
1456
  }
1431
1457
 
1458
+ /**
1459
+ * Return a loss-preserving, versioned JSON envelope for a CDXML document.
1460
+ *
1461
+ * `source` is retained for exact re-serialization; `document` is the stable
1462
+ * structural summary used by editors. Unknown objects remain in the summary
1463
+ * and are listed under `document.diagnostics`.
1464
+ * @param {string} cdxml
1465
+ * @returns {string}
1466
+ */
1467
+ export function cdxml_document_json_v1(cdxml) {
1468
+ let deferred3_0;
1469
+ let deferred3_1;
1470
+ try {
1471
+ const ptr0 = passStringToWasm0(cdxml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1472
+ const len0 = WASM_VECTOR_LEN;
1473
+ const ret = wasm.cdxml_document_json_v1(ptr0, len0);
1474
+ var ptr2 = ret[0];
1475
+ var len2 = ret[1];
1476
+ if (ret[3]) {
1477
+ ptr2 = 0; len2 = 0;
1478
+ throw takeFromExternrefTable0(ret[2]);
1479
+ }
1480
+ deferred3_0 = ptr2;
1481
+ deferred3_1 = len2;
1482
+ return getStringFromWasm0(ptr2, len2);
1483
+ } finally {
1484
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1485
+ }
1486
+ }
1487
+
1488
+ /**
1489
+ * Project a CDXML document to its first molecular fragment only when no
1490
+ * presentation data would be lost. Unknown/presentation objects are reported
1491
+ * as an explicit lossy conversion instead of being silently dropped.
1492
+ * @param {string} cdxml
1493
+ * @returns {string}
1494
+ */
1495
+ export function cdxml_document_projection_json_v1(cdxml) {
1496
+ let deferred3_0;
1497
+ let deferred3_1;
1498
+ try {
1499
+ const ptr0 = passStringToWasm0(cdxml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1500
+ const len0 = WASM_VECTOR_LEN;
1501
+ const ret = wasm.cdxml_document_projection_json_v1(ptr0, len0);
1502
+ var ptr2 = ret[0];
1503
+ var len2 = ret[1];
1504
+ if (ret[3]) {
1505
+ ptr2 = 0; len2 = 0;
1506
+ throw takeFromExternrefTable0(ret[2]);
1507
+ }
1508
+ deferred3_0 = ptr2;
1509
+ deferred3_1 = len2;
1510
+ return getStringFromWasm0(ptr2, len2);
1511
+ } finally {
1512
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1513
+ }
1514
+ }
1515
+
1432
1516
  /**
1433
1517
  * Parse all molecular fragments from a CDXML string.
1434
1518
  *
@@ -2131,6 +2215,66 @@ export function edit_cdxml_document_json(cdxml, edit_json) {
2131
2215
  }
2132
2216
  }
2133
2217
 
2218
+ /**
2219
+ * Apply a bounded CDXML edit to a versioned JSON envelope and return the
2220
+ * updated envelope. The source is reparsed after editing, so paths and
2221
+ * diagnostics cannot drift from the returned document summary.
2222
+ * @param {string} document_json
2223
+ * @param {string} edit_json
2224
+ * @returns {string}
2225
+ */
2226
+ export function edit_cdxml_document_json_v1(document_json, edit_json) {
2227
+ let deferred4_0;
2228
+ let deferred4_1;
2229
+ try {
2230
+ const ptr0 = passStringToWasm0(document_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2231
+ const len0 = WASM_VECTOR_LEN;
2232
+ const ptr1 = passStringToWasm0(edit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2233
+ const len1 = WASM_VECTOR_LEN;
2234
+ const ret = wasm.edit_cdxml_document_json_v1(ptr0, len0, ptr1, len1);
2235
+ var ptr3 = ret[0];
2236
+ var len3 = ret[1];
2237
+ if (ret[3]) {
2238
+ ptr3 = 0; len3 = 0;
2239
+ throw takeFromExternrefTable0(ret[2]);
2240
+ }
2241
+ deferred4_0 = ptr3;
2242
+ deferred4_1 = len3;
2243
+ return getStringFromWasm0(ptr3, len3);
2244
+ } finally {
2245
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
2246
+ }
2247
+ }
2248
+
2249
+ /**
2250
+ * Apply a bounded, stable-ID reaction-document edit and return canonical JSON.
2251
+ * @param {string} document_json
2252
+ * @param {string} edit_json
2253
+ * @returns {string}
2254
+ */
2255
+ export function edit_reaction_document_json_v1(document_json, edit_json) {
2256
+ let deferred4_0;
2257
+ let deferred4_1;
2258
+ try {
2259
+ const ptr0 = passStringToWasm0(document_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2260
+ const len0 = WASM_VECTOR_LEN;
2261
+ const ptr1 = passStringToWasm0(edit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2262
+ const len1 = WASM_VECTOR_LEN;
2263
+ const ret = wasm.edit_reaction_document_json_v1(ptr0, len0, ptr1, len1);
2264
+ var ptr3 = ret[0];
2265
+ var len3 = ret[1];
2266
+ if (ret[3]) {
2267
+ ptr3 = 0; len3 = 0;
2268
+ throw takeFromExternrefTable0(ret[2]);
2269
+ }
2270
+ deferred4_0 = ptr3;
2271
+ deferred4_1 = len3;
2272
+ return getStringFromWasm0(ptr3, len3);
2273
+ } finally {
2274
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
2275
+ }
2276
+ }
2277
+
2134
2278
  /**
2135
2279
  * Run `embed_ensemble_v2` on `mol`'s own atom order (never canonicalizes/
2136
2280
  * reparses, same convention as `embed_pipeline_v2_json`). See the module doc
@@ -3580,7 +3724,7 @@ export function minimize_mmff94_lbfgs_json(mol, max_iter) {
3580
3724
  * `coords_json` — JSON array of `[x,y,z]` arrays (Å), one per atom.
3581
3725
  * `max_iter` — maximum iterations (0 = default 500).
3582
3726
  *
3583
- * Returns JSON: `{"coords":[[x,y,z],...], "energy":float, "iterations":int, "converged":bool, "sound":bool, "worst_bond_length":float}`
3727
+ * Returns JSON: `{"coords":[[x,y,z],...], "energy":float, "iterations":int, "converged":bool, "sound":bool, "worst_bond_length":float, "rejected_unsound_step":bool}`
3584
3728
  * or `{"error":"<msg>"}` on failure. `sound` is all-finite coordinates and
3585
3729
  * no bond stretched past a sane covalent-bond length — independent of
3586
3730
  * `converged`, since steepest descent often reports `converged:false` on
@@ -4006,6 +4150,24 @@ export function mol_from_cml(cml) {
4006
4150
  return MolHandle.__wrap(ret[0]);
4007
4151
  }
4008
4152
 
4153
+ /**
4154
+ * Parse a structurally valid, non-empty CML string into a `MolHandle`.
4155
+ *
4156
+ * This opt-in strict boundary rejects missing/empty molecules and malformed
4157
+ * XML while `mol_from_cml` retains its historical lenient behavior.
4158
+ * @param {string} cml
4159
+ * @returns {MolHandle}
4160
+ */
4161
+ export function mol_from_cml_strict(cml) {
4162
+ const ptr0 = passStringToWasm0(cml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
4163
+ const len0 = WASM_VECTOR_LEN;
4164
+ const ret = wasm.mol_from_cml_strict(ptr0, len0);
4165
+ if (ret[2]) {
4166
+ throw takeFromExternrefTable0(ret[1]);
4167
+ }
4168
+ return MolHandle.__wrap(ret[0]);
4169
+ }
4170
+
4009
4171
  /**
4010
4172
  * Parse a Gaussian Cube file and return a `MolHandle` (topology only --
4011
4173
  * element list, no bonds; Cube carries no bond table). Use
@@ -5055,7 +5217,7 @@ export function pqr_infer_element(group_pdb, res_name, atom_name) {
5055
5217
  const ret = wasm.pqr_infer_element(ptr0, len0, ptr1, len1, ptr2, len2);
5056
5218
  let v4;
5057
5219
  if (ret[0] !== 0) {
5058
- v4 = getStringFromWasm0(ret[0], ret[1]);
5220
+ v4 = getStringFromWasm0(ret[0], ret[1]).slice();
5059
5221
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
5060
5222
  }
5061
5223
  return v4;
@@ -5478,6 +5640,63 @@ export function rdkit_torsion_bitvec(mol) {
5478
5640
  return v1;
5479
5641
  }
5480
5642
 
5643
+ /**
5644
+ * Validate and deterministically serialize a rich reaction document JSON.
5645
+ *
5646
+ * This is the versioned JSON boundary for WASM consumers. It preserves IDs,
5647
+ * metadata, and provenance, and rejects malformed documents before returning
5648
+ * JSON. Use [`edit_reaction_document_json_v1`] for bounded ID-addressed edits.
5649
+ * @param {string} document_json
5650
+ * @returns {string}
5651
+ */
5652
+ export function reaction_document_json_v1(document_json) {
5653
+ let deferred3_0;
5654
+ let deferred3_1;
5655
+ try {
5656
+ const ptr0 = passStringToWasm0(document_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
5657
+ const len0 = WASM_VECTOR_LEN;
5658
+ const ret = wasm.reaction_document_json_v1(ptr0, len0);
5659
+ var ptr2 = ret[0];
5660
+ var len2 = ret[1];
5661
+ if (ret[3]) {
5662
+ ptr2 = 0; len2 = 0;
5663
+ throw takeFromExternrefTable0(ret[2]);
5664
+ }
5665
+ deferred3_0 = ptr2;
5666
+ deferred3_1 = len2;
5667
+ return getStringFromWasm0(ptr2, len2);
5668
+ } finally {
5669
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
5670
+ }
5671
+ }
5672
+
5673
+ /**
5674
+ * Convert a rich reaction document to legacy RXN V2000 with structured loss
5675
+ * reporting. A lossy projection is never returned as if it were complete.
5676
+ * @param {string} document_json
5677
+ * @returns {string}
5678
+ */
5679
+ export function reaction_document_to_rxn_v1(document_json) {
5680
+ let deferred3_0;
5681
+ let deferred3_1;
5682
+ try {
5683
+ const ptr0 = passStringToWasm0(document_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
5684
+ const len0 = WASM_VECTOR_LEN;
5685
+ const ret = wasm.reaction_document_to_rxn_v1(ptr0, len0);
5686
+ var ptr2 = ret[0];
5687
+ var len2 = ret[1];
5688
+ if (ret[3]) {
5689
+ ptr2 = 0; len2 = 0;
5690
+ throw takeFromExternrefTable0(ret[2]);
5691
+ }
5692
+ deferred3_0 = ptr2;
5693
+ deferred3_1 = len2;
5694
+ return getStringFromWasm0(ptr2, len2);
5695
+ } finally {
5696
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
5697
+ }
5698
+ }
5699
+
5481
5700
  /**
5482
5701
  * Check whether a reaction SMILES matches a reaction SMARTS query.
5483
5702
  *
@@ -5635,6 +5854,38 @@ export function ring_families_json(mol) {
5635
5854
  }
5636
5855
  }
5637
5856
 
5857
+ /**
5858
+ * Parse and serialize a V3000 block while preserving V3000 metadata.
5859
+ *
5860
+ * Unlike the topology-only [`mol_from_v3000_block`] + [`to_mol_v3000_block`]
5861
+ * pair, this explicit round-trip API retains `SGROUP` logical lines and
5862
+ * `COLLECTION` stereo groups. SGROUP polymer/query expansion is still out of
5863
+ * scope, but the typed syntax view is available through
5864
+ * [`v3000_sgroups_json`].
5865
+ * @param {string} block
5866
+ * @returns {string}
5867
+ */
5868
+ export function roundtrip_mol_v3000_block(block) {
5869
+ let deferred3_0;
5870
+ let deferred3_1;
5871
+ try {
5872
+ const ptr0 = passStringToWasm0(block, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
5873
+ const len0 = WASM_VECTOR_LEN;
5874
+ const ret = wasm.roundtrip_mol_v3000_block(ptr0, len0);
5875
+ var ptr2 = ret[0];
5876
+ var len2 = ret[1];
5877
+ if (ret[3]) {
5878
+ ptr2 = 0; len2 = 0;
5879
+ throw takeFromExternrefTable0(ret[2]);
5880
+ }
5881
+ deferred3_0 = ptr2;
5882
+ deferred3_1 = len2;
5883
+ return getStringFromWasm0(ptr2, len2);
5884
+ } finally {
5885
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
5886
+ }
5887
+ }
5888
+
5638
5889
  /**
5639
5890
  * Apply a SMIRKS reaction template and return product SMILES as a JSON string.
5640
5891
  *
@@ -5961,6 +6212,37 @@ export function semantic_expand_json(base_smiles, model_json) {
5961
6212
  }
5962
6213
  }
5963
6214
 
6215
+ /**
6216
+ * Expand a validated semantic model with explicit finite atom/repeat budgets.
6217
+ * @param {string} base_smiles
6218
+ * @param {string} model_json
6219
+ * @param {number} max_atoms
6220
+ * @param {number} max_repeat_count
6221
+ * @returns {string}
6222
+ */
6223
+ export function semantic_expand_json_with_limits(base_smiles, model_json, max_atoms, max_repeat_count) {
6224
+ let deferred4_0;
6225
+ let deferred4_1;
6226
+ try {
6227
+ const ptr0 = passStringToWasm0(base_smiles, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
6228
+ const len0 = WASM_VECTOR_LEN;
6229
+ const ptr1 = passStringToWasm0(model_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
6230
+ const len1 = WASM_VECTOR_LEN;
6231
+ const ret = wasm.semantic_expand_json_with_limits(ptr0, len0, ptr1, len1, max_atoms, max_repeat_count);
6232
+ var ptr3 = ret[0];
6233
+ var len3 = ret[1];
6234
+ if (ret[3]) {
6235
+ ptr3 = 0; len3 = 0;
6236
+ throw takeFromExternrefTable0(ret[2]);
6237
+ }
6238
+ deferred4_0 = ptr3;
6239
+ deferred4_1 = len3;
6240
+ return getStringFromWasm0(ptr3, len3);
6241
+ } finally {
6242
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
6243
+ }
6244
+ }
6245
+
5964
6246
  /**
5965
6247
  * Validate and normalize a typed Markush/polymer semantic model JSON.
5966
6248
  * @param {string} model_json
@@ -6378,6 +6660,29 @@ export function stereo_parent_json(mol) {
6378
6660
  }
6379
6661
  }
6380
6662
 
6663
+ /**
6664
+ * Analyze a rich reaction document's explicit atom/isotope inventory and
6665
+ * formal charges. The returned JSON includes evidence scope, per-step
6666
+ * diagnostics, and a status that does not imply chemical completeness.
6667
+ * Returns `error:<msg>` when the document or a component is invalid.
6668
+ * @param {string} document_json
6669
+ * @returns {string}
6670
+ */
6671
+ export function stoichiometry_report_json(document_json) {
6672
+ let deferred2_0;
6673
+ let deferred2_1;
6674
+ try {
6675
+ const ptr0 = passStringToWasm0(document_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
6676
+ const len0 = WASM_VECTOR_LEN;
6677
+ const ret = wasm.stoichiometry_report_json(ptr0, len0);
6678
+ deferred2_0 = ret[0];
6679
+ deferred2_1 = ret[1];
6680
+ return getStringFromWasm0(ret[0], ret[1]);
6681
+ } finally {
6682
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
6683
+ }
6684
+ }
6685
+
6381
6686
  /**
6382
6687
  * Compute the composed Super Parent with explicit resource limits.
6383
6688
  * @param {MolHandle} mol
@@ -6833,6 +7138,31 @@ export function torsion_bitvec(mol) {
6833
7138
  return v1;
6834
7139
  }
6835
7140
 
7141
+ /**
7142
+ * @param {string} block
7143
+ * @returns {string}
7144
+ */
7145
+ export function v3000_sgroups_json(block) {
7146
+ let deferred3_0;
7147
+ let deferred3_1;
7148
+ try {
7149
+ const ptr0 = passStringToWasm0(block, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
7150
+ const len0 = WASM_VECTOR_LEN;
7151
+ const ret = wasm.v3000_sgroups_json(ptr0, len0);
7152
+ var ptr2 = ret[0];
7153
+ var len2 = ret[1];
7154
+ if (ret[3]) {
7155
+ ptr2 = 0; len2 = 0;
7156
+ throw takeFromExternrefTable0(ret[2]);
7157
+ }
7158
+ deferred3_0 = ptr2;
7159
+ deferred3_1 = len2;
7160
+ return getStringFromWasm0(ptr2, len2);
7161
+ } finally {
7162
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
7163
+ }
7164
+ }
7165
+
6836
7166
  /**
6837
7167
  * Validate a vendor-neutral NMR spectrum JSON document without parsing a
6838
7168
  * vendor-specific raw file or predicting peaks.
@@ -7289,11 +7619,11 @@ export function xyz_frames_batch_json(text, offset, batch_size) {
7289
7619
  function __wbg_get_imports() {
7290
7620
  const import0 = {
7291
7621
  __proto__: null,
7292
- __wbg___wbindgen_is_undefined_8c687d0b90d5b524: function(arg0) {
7622
+ __wbg___wbindgen_is_undefined_35bb9f4c7fd651d5: function(arg0) {
7293
7623
  const ret = arg0 === undefined;
7294
7624
  return ret;
7295
7625
  },
7296
- __wbg___wbindgen_string_get_92ab86bb19cbc12f: function(arg0, arg1) {
7626
+ __wbg___wbindgen_string_get_d109740c0d18f4d7: function(arg0, arg1) {
7297
7627
  const obj = arg1;
7298
7628
  const ret = typeof(obj) === 'string' ? obj : undefined;
7299
7629
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -7301,17 +7631,17 @@ function __wbg_get_imports() {
7301
7631
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
7302
7632
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
7303
7633
  },
7304
- __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
7634
+ __wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
7305
7635
  throw new Error(getStringFromWasm0(arg0, arg1));
7306
7636
  },
7307
- __wbg_error_756c5934221e6fee: function(arg0) {
7637
+ __wbg_error_f085d7e62279b703: function(arg0) {
7308
7638
  console.error(arg0);
7309
7639
  },
7310
- __wbg_new_from_slice_3b4c7f1456059f80: function(arg0, arg1) {
7640
+ __wbg_new_from_slice_02962bf7778cf945: function(arg0, arg1) {
7311
7641
  const ret = new Float64Array(getArrayF64FromWasm0(arg0, arg1));
7312
7642
  return ret;
7313
7643
  },
7314
- __wbg_new_from_slice_a500ec81601be48f: function(arg0, arg1) {
7644
+ __wbg_new_from_slice_f92bf65e9a895613: function(arg0, arg1) {
7315
7645
  const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
7316
7646
  return ret;
7317
7647
  },
@@ -7323,28 +7653,28 @@ function __wbg_get_imports() {
7323
7653
  const ret = arg0.performance;
7324
7654
  return ret;
7325
7655
  },
7326
- __wbg_static_accessor_GLOBAL_8eb4cd83130a11a0: function() {
7327
- const ret = typeof global === 'undefined' ? null : global;
7656
+ __wbg_static_accessor_GLOBAL_THIS_02344c9b09eb08a9: function() {
7657
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
7328
7658
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
7329
7659
  },
7330
- __wbg_static_accessor_GLOBAL_THIS_1e7044f654e934db: function() {
7331
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
7660
+ __wbg_static_accessor_GLOBAL_ac6d4ac874d5cd54: function() {
7661
+ const ret = typeof global === 'undefined' ? null : global;
7332
7662
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
7333
7663
  },
7334
- __wbg_static_accessor_SELF_d8b50611246a6d92: function() {
7664
+ __wbg_static_accessor_SELF_9b2406c23aeb2023: function() {
7335
7665
  const ret = typeof self === 'undefined' ? null : self;
7336
7666
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
7337
7667
  },
7338
- __wbg_static_accessor_WINDOW_fd0bc376bf0f8b42: function() {
7668
+ __wbg_static_accessor_WINDOW_b34d2126934e16ba: function() {
7339
7669
  const ret = typeof window === 'undefined' ? null : window;
7340
7670
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
7341
7671
  },
7342
- __wbindgen_generic_0000000000000001: function(arg0) {
7672
+ __wbindgen_cast_0000000000000001: function(arg0) {
7343
7673
  // Cast intrinsic for `F64 -> Externref`.
7344
7674
  const ret = arg0;
7345
7675
  return ret;
7346
7676
  },
7347
- __wbindgen_generic_0000000000000002: function(arg0, arg1) {
7677
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
7348
7678
  // Cast intrinsic for `Ref(String) -> Externref`.
7349
7679
  const ret = getStringFromWasm0(arg0, arg1);
7350
7680
  return ret;
@@ -7539,15 +7869,11 @@ function __wbg_finalize_init(instance, module) {
7539
7869
 
7540
7870
  async function __wbg_load(module, imports) {
7541
7871
  if (typeof Response === 'function' && module instanceof Response) {
7542
- if (!module.ok) {
7543
- throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
7544
- }
7545
-
7546
7872
  if (typeof WebAssembly.instantiateStreaming === 'function') {
7547
7873
  try {
7548
7874
  return await WebAssembly.instantiateStreaming(module, imports);
7549
7875
  } catch (e) {
7550
- const validResponse = expectedResponseType(module.type);
7876
+ const validResponse = module.ok && expectedResponseType(module.type);
7551
7877
 
7552
7878
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
7553
7879
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Kentaro Tanabe (kent-tokyo) <kent-tokyo@users.noreply.github.com>"
6
6
  ],
7
7
  "description": "WebAssembly bindings for chematic — use chematic from JavaScript/TypeScript",
8
- "version": "1.0.11",
8
+ "version": "1.0.13",
9
9
  "license": "MIT OR Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",