@cosmol-studio/cosmolkit-core-3d 0.5.1-rc.4 → 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.
- package/README.md +14 -234
- package/cosmolkit_wasm.d.ts +13636 -0
- package/cosmolkit_wasm.js +58717 -0
- package/cosmolkit_wasm_bg.wasm +0 -0
- package/cosmolkit_wasm_bg.wasm.d.ts +3767 -0
- package/package.json +15 -26
- package/snippets/cosmolkit-wasm-719223eb0886d669/src/readonly_map.js +26 -0
- package/snippets/package.json +1 -0
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline0.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline1.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline10.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline11.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline12.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline13.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline14.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline15.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline16.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline17.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline18.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline19.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline2.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline20.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline21.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline22.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline23.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline24.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline25.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline26.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline27.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline28.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline29.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline3.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline30.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline31.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline32.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline33.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline34.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline35.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline36.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline37.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline38.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline39.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline4.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline40.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline41.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline42.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline43.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline44.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline45.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline46.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline47.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline48.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline49.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline5.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline50.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline51.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline52.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline53.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline54.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline55.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline56.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline57.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline58.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline59.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline6.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline60.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline61.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline62.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline63.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline64.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline7.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline8.js +0 -1
- package/snippets/wasm-wasm-8d351253ad5d1fc8/inline9.js +0 -1
- package/wasm_wasm.d.ts +0 -4658
- package/wasm_wasm.js +0 -20968
- package/wasm_wasm_bg.wasm +0 -0
- package/wasm_wasm_bg.wasm.d.ts +0 -1687
package/README.md
CHANGED
|
@@ -1,245 +1,25 @@
|
|
|
1
|
-
# COSMolKit
|
|
1
|
+
# COSMolKit for JavaScript and TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
75
|
-
console.log(
|
|
76
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
239
|
-
|
|
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)
|