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,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;
@@ -0,0 +1,68 @@
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
+ import * as raw from "./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
+ export 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
+ export const IR_VERSION = 1;
21
+ export 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
+ export 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
+ export function smilesToName(smiles) { return flattenName(call(raw.smilesToName, smiles)); }
54
+ export 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
+ export function moleculeToName(molecule) {
66
+ assertFiniteNumbers(molecule);
67
+ return flattenName(call(raw.moleculeToName, molecule));
68
+ }
@@ -0,0 +1,8 @@
1
+ import * as wasm from "../nazuchem_bg.wasm";
2
+ import { __wbg_set_wasm } from "../nazuchem_bg.js";
3
+
4
+ __wbg_set_wasm(wasm);
5
+ wasm.__wbindgen_start();
6
+ export {
7
+ moleculeToName, nameToMolecule, nameToSmiles, smilesToName
8
+ } from "../nazuchem_bg.js";
@@ -0,0 +1 @@
1
+ {"type":"module"}