@cosmol-studio/cosmolkit-core-3d 0.5.1-rc.3 → 0.6.0-dev.1

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.
Files changed (75) hide show
  1. package/README.md +14 -234
  2. package/cosmolkit_wasm.d.ts +13636 -0
  3. package/cosmolkit_wasm.js +58717 -0
  4. package/cosmolkit_wasm_bg.wasm +0 -0
  5. package/cosmolkit_wasm_bg.wasm.d.ts +3767 -0
  6. package/package.json +15 -26
  7. package/snippets/cosmolkit-wasm-719223eb0886d669/src/readonly_map.js +26 -0
  8. package/snippets/package.json +1 -0
  9. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline0.js +0 -1
  10. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline1.js +0 -1
  11. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline10.js +0 -1
  12. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline11.js +0 -1
  13. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline12.js +0 -1
  14. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline13.js +0 -1
  15. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline14.js +0 -1
  16. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline15.js +0 -1
  17. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline16.js +0 -1
  18. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline17.js +0 -1
  19. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline18.js +0 -1
  20. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline19.js +0 -1
  21. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline2.js +0 -1
  22. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline20.js +0 -1
  23. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline21.js +0 -1
  24. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline22.js +0 -1
  25. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline23.js +0 -1
  26. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline24.js +0 -1
  27. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline25.js +0 -1
  28. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline26.js +0 -1
  29. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline27.js +0 -1
  30. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline28.js +0 -1
  31. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline29.js +0 -1
  32. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline3.js +0 -1
  33. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline30.js +0 -1
  34. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline31.js +0 -1
  35. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline32.js +0 -1
  36. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline33.js +0 -1
  37. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline34.js +0 -1
  38. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline35.js +0 -1
  39. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline36.js +0 -1
  40. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline37.js +0 -1
  41. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline38.js +0 -1
  42. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline39.js +0 -1
  43. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline4.js +0 -1
  44. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline40.js +0 -1
  45. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline41.js +0 -1
  46. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline42.js +0 -1
  47. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline43.js +0 -1
  48. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline44.js +0 -1
  49. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline45.js +0 -1
  50. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline46.js +0 -1
  51. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline47.js +0 -1
  52. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline48.js +0 -1
  53. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline49.js +0 -1
  54. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline5.js +0 -1
  55. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline50.js +0 -1
  56. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline51.js +0 -1
  57. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline52.js +0 -1
  58. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline53.js +0 -1
  59. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline54.js +0 -1
  60. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline55.js +0 -1
  61. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline56.js +0 -1
  62. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline57.js +0 -1
  63. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline58.js +0 -1
  64. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline59.js +0 -1
  65. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline6.js +0 -1
  66. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline60.js +0 -1
  67. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline61.js +0 -1
  68. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline62.js +0 -1
  69. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline7.js +0 -1
  70. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline8.js +0 -1
  71. package/snippets/wasm-wasm-d9ca1d4d07779bac/inline9.js +0 -1
  72. package/wasm_wasm.d.ts +0 -4582
  73. package/wasm_wasm.js +0 -20663
  74. package/wasm_wasm_bg.wasm +0 -0
  75. package/wasm_wasm_bg.wasm.d.ts +0 -1665
package/README.md CHANGED
@@ -1,245 +1,25 @@
1
- # COSMolKit WASM
1
+ # COSMolKit for JavaScript and TypeScript
2
2
 
3
- `@cosmol-studio/cosmolkit` is the WebAssembly projection of the Rust `cosmolkit` facade. The
4
- package uses the `wasm-bindgen` `web` target and exposes an opaque
5
- `Molecule` value. Parsing and chemistry errors are thrown as JavaScript
6
- exceptions; successful methods return strings, numbers, typed arrays, or new
7
- `Molecule` values.
8
-
9
- ## Install
3
+ WebAssembly bindings to the public Rust API, with generated TypeScript declarations.
10
4
 
11
5
  ```bash
12
6
  npm install @cosmol-studio/cosmolkit
13
7
  ```
14
8
 
15
- The default package is **full**. Each smaller distribution has its own package
16
- name, so upgrading it cannot select a different feature combination:
17
-
18
- | Package name (under `@cosmol-studio/`) | Included public features |
19
- |---|---|
20
- | `cosmolkit-core` | `core`, including molecular IO and batch processing |
21
- | `cosmolkit-core-search` | `core + search` |
22
- | `cosmolkit-core-fingerprints` | `core + fingerprints` |
23
- | `cosmolkit-core-analysis` | `core + search + fingerprints + descriptors` |
24
- | `cosmolkit-core-reaction` | `core + reaction` (including search) |
25
- | `cosmolkit-core-depict` | `core + depict` |
26
- | `cosmolkit-core-3d` | `core + conformer` (including forcefields and alignment) |
27
- | `cosmolkit-core-bio` | `core + bio` |
28
- | `cosmolkit-core-inchi` | `core + inchi` |
29
- | `cosmolkit` | `full` |
30
-
31
- For example: `npm install @cosmol-studio/cosmolkit-core-bio`, then import from
32
- `"@cosmol-studio/cosmolkit-core-bio"`. Omitted domains are absent from both exports and TypeScript
33
- declarations; they are not runtime placeholders.
34
-
35
- WASM uses the Rust facade's feature tree, generated from its Cargo manifest.
36
- The platform exception is binary archives: `toBinary`/`fromBinary` and the
37
- binary-only encoding dependencies are not compiled, even in `full`.
38
- Query IO needs `search`; automatic 2D coordinate generation needs `depict`.
39
- Without these capabilities, shared IO entrypoints report an explicit error.
40
-
41
- All packages use the Rust release version, without a feature suffix. Stable
42
- releases update `latest`; RC releases update `rc`, not `latest`. To install an
43
- RC, use e.g. `npm install @cosmol-studio/cosmolkit-core-bio@rc`. Tags identify
44
- release channels, never feature combinations. Pin a version or use a lockfile
45
- for reproducible installs.
46
-
47
- Existing installations using feature dist-tags such as `cosmolkit@core-bio`
48
- must switch once to the corresponding package name. New releases do not update
49
- those old feature tags.
50
-
51
- InChI is available in `core-inchi` and the default full package:
52
-
53
- ```js
54
- const molecule = Molecule.fromSmiles("CCO");
55
- console.log(molecule.toInchi());
56
- console.log(molecule.toInchiKey());
57
- const restored = Molecule.fromInchi(molecule.toInchi());
58
- restored.free();
59
- molecule.free();
60
- ```
61
-
62
- The package is browser/bundler-oriented. It can be used from Vite, webpack,
63
- Rollup, and other tools that support the web `WebAssembly` target.
64
-
65
- ## Native JavaScript
66
-
67
- Initialize the module once before using `Molecule`:
68
-
69
- ```js
70
- import init, { Molecule } from "@cosmol-studio/cosmolkit";
9
+ ```typescript
10
+ import init, { molFromSmiles } from "@cosmol-studio/cosmolkit";
71
11
 
72
12
  await init();
73
-
74
- const molecule = Molecule.fromSmiles("CCO");
75
- console.log(molecule.toSmiles());
76
- console.log(molecule.numAtoms());
77
- molecule.free();
78
- ```
79
-
80
- The published npm package is scoped as `@cosmol-studio/cosmolkit`. The Rust
81
- binding crate remains `cosmolkit-wasm` internally.
82
-
83
- ## Native JavaScript From A CDN
84
-
85
- For a browser page that does not use a bundler, import the generated web
86
- module from jsDelivr. Pin the package version in production and keep the
87
- background `.wasm` file on the same CDN host:
88
-
89
- ```html
90
- <div id="molecule"></div>
91
- <script type="module">
92
- import init, { Molecule } from
93
- "https://cdn.jsdelivr.net/npm/@cosmol-studio/cosmolkit@0.5.0/wasm_wasm.js";
94
-
95
- await init(
96
- "https://cdn.jsdelivr.net/npm/@cosmol-studio/cosmolkit@0.5.0/wasm_wasm_bg.wasm",
97
- );
98
- const molecule = Molecule.fromSmiles("c1ccccc1O");
99
- document.querySelector("#molecule").textContent = molecule.toSmiles();
100
- molecule.free();
101
- </script>
13
+ const mol = molFromSmiles("CCO");
14
+ console.log(mol.toSmiles());
15
+ console.log(mol.numAtoms);
16
+ mol.free();
102
17
  ```
103
18
 
104
- The generated wasm-bindgen module is currently named `wasm_wasm.js` because
105
- Alef derives the generated Cargo package from the `wasm/` source directory.
106
- The package export remains `Molecule`; the generated filename is an artifact
107
- of the binding build and should be updated here if that output layout changes.
108
-
109
- More focused examples are in [`examples/vanilla`](./examples/vanilla/):
110
-
111
- - [`basic.js`](./examples/vanilla/basic.js): parse, write, and render SVG.
112
- - [`cdn.html`](./examples/vanilla/cdn.html): run the web module directly from
113
- jsDelivr without a bundler.
114
- - [`descriptors.js`](./examples/vanilla/descriptors.js): descriptors and typed
115
- coordinate arrays.
116
- - [`fingerprints.js`](./examples/vanilla/fingerprints.js): typed fingerprint
117
- bit vectors.
118
- - [`substructure.js`](./examples/vanilla/substructure.js): SMARTS matching and
119
- disconnected fragments.
120
- - [`stereo.js`](./examples/vanilla/stereo.js): stereochemistry and conformers.
121
-
122
- ## React
123
-
124
- The React example keeps initialization and molecule ownership in component
125
- state. It does not call the Rust API during render:
126
-
127
- ```jsx
128
- import { useEffect, useState } from "react";
129
- import init, { Molecule } from "@cosmol-studio/cosmolkit";
130
-
131
- export function MoleculePanel({ smiles }) {
132
- const [ready, setReady] = useState(false);
133
- const [molecule, setMolecule] = useState(null);
134
- const [error, setError] = useState(null);
135
-
136
- useEffect(() => {
137
- let active = true;
138
- init()
139
- .then(() => {
140
- if (active) setReady(true);
141
- })
142
- .catch((value) => {
143
- if (active) setError(String(value));
144
- });
145
- return () => {
146
- active = false;
147
- };
148
- }, []);
149
-
150
- useEffect(() => {
151
- if (!ready) return;
152
- try {
153
- const next = Molecule.fromSmiles(smiles);
154
- setMolecule(next);
155
- setError(null);
156
- } catch (value) {
157
- setError(String(value));
158
- }
159
- }, [ready, smiles]);
160
-
161
- useEffect(() => () => molecule?.free(), [molecule]);
162
-
163
- if (error) return <pre>{error}</pre>;
164
- if (!molecule) return <p>Loading COSMolKit...</p>;
165
- return <output>{molecule.toSmiles()} ({molecule.numAtoms()} atoms)</output>;
166
- }
167
- ```
168
-
169
- The complete copyable component is
170
- [`examples/react/MoleculePanel.jsx`](./examples/react/MoleculePanel.jsx).
171
-
172
- ## Vue
173
-
174
- Vue applications should initialize in `onMounted` and replace the previous
175
- opaque value when the input changes:
176
-
177
- ```vue
178
- <script setup>
179
- import { onBeforeUnmount, onMounted, ref, watch } from "vue";
180
- import init, { Molecule } from "@cosmol-studio/cosmolkit";
181
-
182
- const props = defineProps({ smiles: { type: String, default: "CCO" } });
183
- const molecule = ref(null);
184
- const error = ref("");
185
-
186
- async function update() {
187
- try {
188
- const next = Molecule.fromSmiles(props.smiles);
189
- molecule.value?.free();
190
- molecule.value = next;
191
- error.value = "";
192
- } catch (value) {
193
- error.value = String(value);
194
- }
195
- }
196
-
197
- onMounted(async () => {
198
- try {
199
- await init();
200
- await update();
201
- } catch (value) {
202
- error.value = String(value);
203
- }
204
- });
205
- watch(() => props.smiles, update);
206
- onBeforeUnmount(() => molecule.value?.free());
207
- </script>
208
-
209
- <template>
210
- <pre v-if="error">{{ error }}</pre>
211
- <output v-else-if="molecule">{{ molecule.toSmiles() }}</output>
212
- <p v-else>Loading COSMolKit...</p>
213
- </template>
214
- ```
215
-
216
- The complete component is [`examples/vue/MoleculePanel.vue`](./examples/vue/MoleculePanel.vue).
217
-
218
- ## Ownership And Errors
219
-
220
- `Molecule` values own Rust allocations. Keep a value while it is in use and
221
- call `.free()` when a long-lived UI state or worker no longer needs it. Methods
222
- such as `withHydrogens()`, `with2dCoordinates()`, and
223
- `with3dConformer()` return new values and leave the source value unchanged.
224
-
225
- In-place molecule operations retain the trailing `_` in JavaScript, such as
226
- `addHydrogens_()` and `add2dCoordinates_()`. Their configured forms also retain
227
- it: `add2dCoordinatesWithParams_(params)`. Use `with2dCoordinates()` or
228
- `with2dCoordinatesWithParams(params)` when a new molecule is required.
229
-
230
- Fingerprint methods return `Uint32Array` set-bit lists. Coordinate methods
231
- return flattened `Float64Array` values. Native binary archives are intentionally
232
- not part of the WASM API.
233
-
234
- ## Examples
235
-
236
- The examples are intentionally small and use only the published package:
19
+ Use the full package above or select a smaller
20
+ [feature package](https://kit.cosmol.org/javascript/).
21
+ Native objects retain Rust ownership and copy-on-write behavior.
22
+ Params accept typed options or parameter instances; invalid inputs throw typed errors.
237
23
 
238
- - [`examples/vanilla/basic.js`](./examples/vanilla/basic.js)
239
- - [`examples/vanilla/cdn.html`](./examples/vanilla/cdn.html)
240
- - [`examples/vanilla/descriptors.js`](./examples/vanilla/descriptors.js)
241
- - [`examples/vanilla/fingerprints.js`](./examples/vanilla/fingerprints.js)
242
- - [`examples/vanilla/substructure.js`](./examples/vanilla/substructure.js)
243
- - [`examples/vanilla/stereo.js`](./examples/vanilla/stereo.js)
244
- - [`examples/react/MoleculePanel.jsx`](./examples/react/MoleculePanel.jsx)
245
- - [`examples/vue/MoleculePanel.vue`](./examples/vue/MoleculePanel.vue)
24
+ [API and examples](https://kit.cosmol.org/javascript/api) ·
25
+ [Build and development](https://github.com/cosmol-studio/COSMolKit/blob/main/wasm/dev.md) · [Binding contract](https://github.com/cosmol-studio/COSMolKit/blob/main/wasm/BINDING_CONTRACT.md)