@molcrafts/molrs 0.0.8 → 0.0.12
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/molrs.d.ts +240 -38
- package/molrs.js +1 -1
- package/molrs_bg.js +394 -43
- package/molrs_bg.wasm +0 -0
- package/package.json +1 -1
package/molrs.d.ts
CHANGED
|
@@ -1114,6 +1114,31 @@ export class Frame {
|
|
|
1114
1114
|
* ```
|
|
1115
1115
|
*/
|
|
1116
1116
|
getGrid(name: string): Grid | undefined;
|
|
1117
|
+
/**
|
|
1118
|
+
* Read a per-frame metadata value as a numeric scalar.
|
|
1119
|
+
*
|
|
1120
|
+
* Returns `Some(v)` if the meta key exists AND its string value parses
|
|
1121
|
+
* as an `f64`. Returns `None` if the key is missing or the value is
|
|
1122
|
+
* non-numeric (e.g., `config="trans"`).
|
|
1123
|
+
*
|
|
1124
|
+
* `frame.meta` is a `HashMap<String, String>`; the ExtXYZ parser stores
|
|
1125
|
+
* all comment-line values as strings. This accessor reads numeric ones
|
|
1126
|
+
* via `str::parse::<f64>`.
|
|
1127
|
+
*
|
|
1128
|
+
* # Arguments
|
|
1129
|
+
*
|
|
1130
|
+
* * `name` — Meta key to look up (e.g., `"energy"`, `"temp"`).
|
|
1131
|
+
*
|
|
1132
|
+
* # Example (JavaScript)
|
|
1133
|
+
*
|
|
1134
|
+
* ```js
|
|
1135
|
+
* const energy = frame.getMetaScalar("energy");
|
|
1136
|
+
* if (energy !== undefined) {
|
|
1137
|
+
* console.log("Energy:", energy);
|
|
1138
|
+
* }
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
getMetaScalar(name: string): number | undefined;
|
|
1117
1142
|
/**
|
|
1118
1143
|
* Return the names of all grids attached to this frame.
|
|
1119
1144
|
*
|
|
@@ -1190,6 +1215,20 @@ export class Frame {
|
|
|
1190
1215
|
* ```
|
|
1191
1216
|
*/
|
|
1192
1217
|
insertGrid(name: string, grid: Grid): void;
|
|
1218
|
+
/**
|
|
1219
|
+
* Return the names of all metadata keys on this frame.
|
|
1220
|
+
*
|
|
1221
|
+
* Includes all keys regardless of whether their values are numeric
|
|
1222
|
+
* or categorical. To filter to numeric keys, iterate and call
|
|
1223
|
+
* [`getMetaScalar`](Self::get_meta_scalar) on each.
|
|
1224
|
+
*
|
|
1225
|
+
* # Example (JavaScript)
|
|
1226
|
+
*
|
|
1227
|
+
* ```js
|
|
1228
|
+
* const names = frame.metaNames(); // e.g. ["energy", "config", "temp"]
|
|
1229
|
+
* ```
|
|
1230
|
+
*/
|
|
1231
|
+
metaNames(): string[];
|
|
1193
1232
|
/**
|
|
1194
1233
|
* Create a new, empty `Frame` with no blocks and no simulation box.
|
|
1195
1234
|
*
|
|
@@ -1286,6 +1325,33 @@ export class Frame {
|
|
|
1286
1325
|
* ```
|
|
1287
1326
|
*/
|
|
1288
1327
|
renameColumn(block_key: string, old_col: string, new_col: string): boolean;
|
|
1328
|
+
/**
|
|
1329
|
+
* Set a per-frame metadata value.
|
|
1330
|
+
*
|
|
1331
|
+
* Stores `value` as the string backing for `name` on `frame.meta`.
|
|
1332
|
+
* Numeric values are read back via
|
|
1333
|
+
* [`getMetaScalar`](Self::get_meta_scalar) by parsing the string
|
|
1334
|
+
* form. `frame.meta` is the single source of truth for per-frame
|
|
1335
|
+
* scalars — no separate aggregation layer is needed on the JS side.
|
|
1336
|
+
*
|
|
1337
|
+
* # Arguments
|
|
1338
|
+
*
|
|
1339
|
+
* * `name` — Meta key (e.g., `"energy"`, `"temp"`).
|
|
1340
|
+
* * `value` — String value. For numeric labels, the caller is
|
|
1341
|
+
* responsible for converting (e.g., `num.toString()`).
|
|
1342
|
+
*
|
|
1343
|
+
* # Errors
|
|
1344
|
+
*
|
|
1345
|
+
* Throws a `JsValue` string if the frame has been dropped.
|
|
1346
|
+
*
|
|
1347
|
+
* # Example (JavaScript)
|
|
1348
|
+
*
|
|
1349
|
+
* ```js
|
|
1350
|
+
* frame.setMeta("energy", "-3.14");
|
|
1351
|
+
* frame.setMeta("note", "run-42");
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
setMeta(name: string, value: string): void;
|
|
1289
1355
|
/**
|
|
1290
1356
|
* Get the simulation box attached to this frame (if any).
|
|
1291
1357
|
*
|
|
@@ -1541,6 +1607,10 @@ export class GyrationTensor {
|
|
|
1541
1607
|
[Symbol.dispose](): void;
|
|
1542
1608
|
/**
|
|
1543
1609
|
* Compute gyration tensors. Returns a flat float typed array (9 values per cluster).
|
|
1610
|
+
*
|
|
1611
|
+
* Internally computes the cluster geometric centers (via
|
|
1612
|
+
* [`RsClusterCenters`]) since the new compute trait exposes them as a
|
|
1613
|
+
* required upstream — the old single-frame wasm API hides this detail.
|
|
1544
1614
|
*/
|
|
1545
1615
|
compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
|
|
1546
1616
|
constructor();
|
|
@@ -1554,6 +1624,10 @@ export class InertiaTensor {
|
|
|
1554
1624
|
[Symbol.dispose](): void;
|
|
1555
1625
|
/**
|
|
1556
1626
|
* Compute inertia tensors. Returns a flat float typed array (9 values per cluster).
|
|
1627
|
+
*
|
|
1628
|
+
* Internally computes the cluster centers of mass (via
|
|
1629
|
+
* [`RsCenterOfMass`]) since the new compute trait consumes them as a
|
|
1630
|
+
* required upstream — the old single-frame wasm API hides this detail.
|
|
1557
1631
|
*/
|
|
1558
1632
|
compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
|
|
1559
1633
|
constructor(masses?: Float64Array | null);
|
|
@@ -1807,25 +1881,23 @@ export class MSD {
|
|
|
1807
1881
|
/**
|
|
1808
1882
|
* Feed a frame into the MSD analysis.
|
|
1809
1883
|
*
|
|
1810
|
-
*
|
|
1811
|
-
*
|
|
1884
|
+
* Internally clones the frame's core data so subsequent mutations on
|
|
1885
|
+
* the JS side (e.g. trajectory playback overwriting buffers) do not
|
|
1886
|
+
* race against pending [`results`](Self::results) calls. The first
|
|
1887
|
+
* frame sets the reference configuration.
|
|
1812
1888
|
*
|
|
1813
1889
|
* # Arguments
|
|
1814
1890
|
*
|
|
1815
1891
|
* * `frame` - Frame with `"atoms"` block containing
|
|
1816
1892
|
* `x`, `y`, `z` (F) columns
|
|
1817
1893
|
*
|
|
1818
|
-
* # Errors
|
|
1819
|
-
*
|
|
1820
|
-
* Throws if the frame is missing required columns or has a
|
|
1821
|
-
* different number of atoms than the reference.
|
|
1822
|
-
*
|
|
1823
1894
|
* # Example (JavaScript)
|
|
1824
1895
|
*
|
|
1825
1896
|
* ```js
|
|
1826
1897
|
* const msd = new MSD();
|
|
1827
1898
|
* msd.feed(frame0); // sets reference
|
|
1828
|
-
* msd.feed(frame1); //
|
|
1899
|
+
* msd.feed(frame1); // added to trajectory
|
|
1900
|
+
* const series = msd.results();
|
|
1829
1901
|
* ```
|
|
1830
1902
|
*/
|
|
1831
1903
|
feed(frame: Frame): void;
|
|
@@ -1843,14 +1915,14 @@ export class MSD {
|
|
|
1843
1915
|
*/
|
|
1844
1916
|
constructor();
|
|
1845
1917
|
/**
|
|
1846
|
-
* Reset the analysis, clearing
|
|
1918
|
+
* Reset the analysis, clearing the trajectory buffer.
|
|
1847
1919
|
*/
|
|
1848
1920
|
reset(): void;
|
|
1849
1921
|
/**
|
|
1850
|
-
*
|
|
1922
|
+
* Run the stateless [`molrs_compute::MSD`] over every fed frame and
|
|
1923
|
+
* return the per-frame time series.
|
|
1851
1924
|
*
|
|
1852
|
-
*
|
|
1853
|
-
* reference frame, which has MSD = 0).
|
|
1925
|
+
* The first frame is always the reference, so `results()[0].mean ≈ 0`.
|
|
1854
1926
|
*
|
|
1855
1927
|
* # Example (JavaScript)
|
|
1856
1928
|
*
|
|
@@ -2066,15 +2138,16 @@ export class PDBReader {
|
|
|
2066
2138
|
/**
|
|
2067
2139
|
* Radial distribution function g(r) analysis.
|
|
2068
2140
|
*
|
|
2069
|
-
*
|
|
2070
|
-
*
|
|
2071
|
-
*
|
|
2141
|
+
* Bins neighbor-pair distances in `[rMin, rMax]` and normalizes by the
|
|
2142
|
+
* ideal-gas pair density. Defaults follow freud (`rMin = 0`). Periodic
|
|
2143
|
+
* systems take their normalization volume from `frame.simbox`; non-periodic
|
|
2144
|
+
* systems must supply it explicitly via [`computeWithVolume`].
|
|
2072
2145
|
*
|
|
2073
2146
|
* # Algorithm
|
|
2074
2147
|
*
|
|
2075
2148
|
* g(r) = n(r) / (rho * V_shell(r) * N_ref)
|
|
2076
2149
|
*
|
|
2077
|
-
* where `n(r)` is the pair count in bin `r`, `rho` is the number
|
|
2150
|
+
* where `n(r)` is the pair count in bin `r`, `rho = N/V` is the number
|
|
2078
2151
|
* density, and `V_shell(r)` is the shell volume for that bin.
|
|
2079
2152
|
*
|
|
2080
2153
|
* # Example (JavaScript)
|
|
@@ -2083,60 +2156,73 @@ export class PDBReader {
|
|
|
2083
2156
|
* const lc = new LinkedCell(5.0);
|
|
2084
2157
|
* const nlist = lc.build(frame);
|
|
2085
2158
|
*
|
|
2086
|
-
* const rdf = new RDF(100, 5.0);
|
|
2159
|
+
* const rdf = new RDF(100, 5.0); // rMin defaults to 0
|
|
2087
2160
|
* const result = rdf.compute(frame, nlist);
|
|
2088
2161
|
*
|
|
2089
|
-
*
|
|
2090
|
-
* const
|
|
2162
|
+
* // Non-periodic frame: supply the normalization volume.
|
|
2163
|
+
* const resultFree = rdf.computeWithVolume(nlist, volumeA3);
|
|
2164
|
+
*
|
|
2165
|
+
* const r = result.binCenters();
|
|
2166
|
+
* const gr = result.rdf();
|
|
2091
2167
|
* ```
|
|
2092
2168
|
*/
|
|
2093
2169
|
export class RDF {
|
|
2094
2170
|
free(): void;
|
|
2095
2171
|
[Symbol.dispose](): void;
|
|
2096
2172
|
/**
|
|
2097
|
-
* Compute
|
|
2098
|
-
*
|
|
2099
|
-
* The frame is needed to read the simulation box volume for
|
|
2100
|
-
* normalization.
|
|
2173
|
+
* Compute g(r) using the simulation-box volume from `frame.simbox`.
|
|
2101
2174
|
*
|
|
2102
2175
|
* # Arguments
|
|
2103
2176
|
*
|
|
2104
|
-
* * `frame` - Frame with a `simbox` set (for volume
|
|
2177
|
+
* * `frame` - Frame with a `simbox` set (used only for volume)
|
|
2105
2178
|
* * `neighbors` - Pre-built [`NeighborList`] from [`LinkedCell`]
|
|
2106
2179
|
*
|
|
2107
|
-
* #
|
|
2180
|
+
* # Errors
|
|
2108
2181
|
*
|
|
2109
|
-
*
|
|
2110
|
-
*
|
|
2182
|
+
* Throws if the frame has no `simbox` — use
|
|
2183
|
+
* [`computeWithVolume`](Self::compute_with_volume) for non-periodic frames.
|
|
2184
|
+
*/
|
|
2185
|
+
compute(frame: Frame, neighbors: NeighborList): RDFResult;
|
|
2186
|
+
/**
|
|
2187
|
+
* Compute g(r) using an explicit normalization volume (A^3).
|
|
2111
2188
|
*
|
|
2112
|
-
*
|
|
2189
|
+
* Use this for non-periodic systems or to override the box volume.
|
|
2190
|
+
* Internally wraps the supplied volume as a cubic SimBox since the
|
|
2191
|
+
* underlying [`molrs_compute::RDF`] pulls its normalization volume from
|
|
2192
|
+
* `frame.simbox`.
|
|
2113
2193
|
*
|
|
2114
|
-
*
|
|
2194
|
+
* # Arguments
|
|
2195
|
+
*
|
|
2196
|
+
* * `neighbors` - Pre-built [`NeighborList`]
|
|
2197
|
+
* * `volume` - Normalization volume in A^3 (must be finite and > 0)
|
|
2115
2198
|
*
|
|
2116
2199
|
* # Example (JavaScript)
|
|
2117
2200
|
*
|
|
2118
2201
|
* ```js
|
|
2119
|
-
* const result = rdf.
|
|
2120
|
-
* const gr = result.rdf(); // Float32Array or Float64Array
|
|
2202
|
+
* const result = rdf.computeWithVolume(nlist, 1000.0);
|
|
2121
2203
|
* ```
|
|
2122
2204
|
*/
|
|
2123
|
-
|
|
2205
|
+
computeWithVolume(neighbors: NeighborList, volume: number): RDFResult;
|
|
2124
2206
|
/**
|
|
2125
|
-
* Create a new RDF analysis
|
|
2207
|
+
* Create a new RDF analysis.
|
|
2126
2208
|
*
|
|
2127
2209
|
* # Arguments
|
|
2128
2210
|
*
|
|
2129
2211
|
* * `n_bins` - Number of histogram bins
|
|
2130
|
-
* * `r_max` -
|
|
2131
|
-
*
|
|
2212
|
+
* * `r_max` - Upper radial cutoff in angstrom (A). Should be ≤ the
|
|
2213
|
+
* neighbor-search cutoff.
|
|
2214
|
+
* * `r_min` - Lower radial cutoff in angstrom (A). Optional, defaults
|
|
2215
|
+
* to 0 (freud convention). Pairs with `d < rMin` or `d == 0` are
|
|
2216
|
+
* excluded from the histogram.
|
|
2132
2217
|
*
|
|
2133
2218
|
* # Example (JavaScript)
|
|
2134
2219
|
*
|
|
2135
2220
|
* ```js
|
|
2136
|
-
* const rdf = new RDF(100, 5.0);
|
|
2221
|
+
* const rdf = new RDF(100, 5.0); // rMin = 0
|
|
2222
|
+
* const rdf2 = new RDF(100, 5.0, 0.5); // exclude d < 0.5 A
|
|
2137
2223
|
* ```
|
|
2138
2224
|
*/
|
|
2139
|
-
constructor(n_bins: number, r_max: number);
|
|
2225
|
+
constructor(n_bins: number, r_max: number, r_min?: number | null);
|
|
2140
2226
|
}
|
|
2141
2227
|
|
|
2142
2228
|
/**
|
|
@@ -2186,7 +2272,11 @@ export class RDFResult {
|
|
|
2186
2272
|
*/
|
|
2187
2273
|
readonly numPoints: number;
|
|
2188
2274
|
/**
|
|
2189
|
-
*
|
|
2275
|
+
* Inner cutoff in A (lower edge of bin 0).
|
|
2276
|
+
*/
|
|
2277
|
+
readonly rMin: number;
|
|
2278
|
+
/**
|
|
2279
|
+
* Normalization volume in A^3 (from the SimBox or the explicit caller value).
|
|
2190
2280
|
*/
|
|
2191
2281
|
readonly volume: number;
|
|
2192
2282
|
}
|
|
@@ -2199,6 +2289,10 @@ export class RadiusOfGyration {
|
|
|
2199
2289
|
[Symbol.dispose](): void;
|
|
2200
2290
|
/**
|
|
2201
2291
|
* Compute radii of gyration. Returns a float typed array of length `numClusters`.
|
|
2292
|
+
*
|
|
2293
|
+
* Internally computes the cluster centers of mass so the single-frame
|
|
2294
|
+
* wasm signature `(frame, cluster)` stays stable despite the new
|
|
2295
|
+
* compute trait needing explicit COM upstream.
|
|
2202
2296
|
*/
|
|
2203
2297
|
compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
|
|
2204
2298
|
constructor(masses?: Float64Array | null);
|
|
@@ -2660,6 +2754,114 @@ export class WasmArray {
|
|
|
2660
2754
|
write_from(arr: Float64Array): void;
|
|
2661
2755
|
}
|
|
2662
2756
|
|
|
2757
|
+
/**
|
|
2758
|
+
* Wrapper for [`molrs_compute::kmeans::KMeans`].
|
|
2759
|
+
*
|
|
2760
|
+
* # Example (JavaScript)
|
|
2761
|
+
*
|
|
2762
|
+
* ```js
|
|
2763
|
+
* const km = new WasmKMeans(3, 100, 42);
|
|
2764
|
+
* const labels = km.fit(coords, nRows, 2); // Int32Array
|
|
2765
|
+
* ```
|
|
2766
|
+
*/
|
|
2767
|
+
export class WasmKMeans {
|
|
2768
|
+
free(): void;
|
|
2769
|
+
[Symbol.dispose](): void;
|
|
2770
|
+
/**
|
|
2771
|
+
* Cluster a row-major `n_rows × n_dims` coordinate matrix.
|
|
2772
|
+
*
|
|
2773
|
+
* # Returns
|
|
2774
|
+
*
|
|
2775
|
+
* Cluster labels in `0..k` as an owned `Int32Array`, one per row.
|
|
2776
|
+
*
|
|
2777
|
+
* # Errors
|
|
2778
|
+
*
|
|
2779
|
+
* Throws if `k > n_rows`, `n_dims == 0`, the length does not match
|
|
2780
|
+
* `n_rows * n_dims`, or any element is non-finite.
|
|
2781
|
+
*/
|
|
2782
|
+
fit(coords: Float64Array, n_rows: number, n_dims: number): Int32Array;
|
|
2783
|
+
/**
|
|
2784
|
+
* Create a new k-means configuration.
|
|
2785
|
+
*
|
|
2786
|
+
* # Arguments
|
|
2787
|
+
*
|
|
2788
|
+
* * `k` — number of clusters (>= 1).
|
|
2789
|
+
* * `max_iter` — maximum Lloyd iterations (>= 1).
|
|
2790
|
+
* * `seed` — RNG seed for k-means++ initialization. Cast to `u64`
|
|
2791
|
+
* internally (JS numbers are `f64`; integers up to 2^53 pass
|
|
2792
|
+
* through losslessly).
|
|
2793
|
+
*
|
|
2794
|
+
* # Errors
|
|
2795
|
+
*
|
|
2796
|
+
* Throws if `k == 0` or `max_iter == 0`.
|
|
2797
|
+
*/
|
|
2798
|
+
constructor(k: number, max_iter: number, seed: number);
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
/**
|
|
2802
|
+
* Stateless wrapper for [`molrs_compute::pca::Pca2`].
|
|
2803
|
+
*
|
|
2804
|
+
* All configuration lives on [`fitTransform`](Self::fit_transform).
|
|
2805
|
+
*
|
|
2806
|
+
* # Example (JavaScript)
|
|
2807
|
+
*
|
|
2808
|
+
* ```js
|
|
2809
|
+
* const pca = new WasmPca2();
|
|
2810
|
+
* const result = pca.fitTransform(matrix, nRows, nCols);
|
|
2811
|
+
* const coords = result.coords(); // Float64Array, length 2 * nRows
|
|
2812
|
+
* const variance = result.variance(); // Float64Array, length 2
|
|
2813
|
+
* ```
|
|
2814
|
+
*/
|
|
2815
|
+
export class WasmPca2 {
|
|
2816
|
+
free(): void;
|
|
2817
|
+
[Symbol.dispose](): void;
|
|
2818
|
+
/**
|
|
2819
|
+
* Fit 2-component PCA on a row-major observation matrix and return the
|
|
2820
|
+
* projected coordinates + per-component variance.
|
|
2821
|
+
*
|
|
2822
|
+
* # Arguments
|
|
2823
|
+
*
|
|
2824
|
+
* * `matrix` — row-major `n_rows × n_cols` observation matrix.
|
|
2825
|
+
* * `n_rows` — number of observations.
|
|
2826
|
+
* * `n_cols` — number of features.
|
|
2827
|
+
*
|
|
2828
|
+
* # Errors
|
|
2829
|
+
*
|
|
2830
|
+
* Throws if `n_rows < 3`, `n_cols < 2`, the length does not match
|
|
2831
|
+
* `n_rows * n_cols`, any element is non-finite, or any column has
|
|
2832
|
+
* zero variance.
|
|
2833
|
+
*/
|
|
2834
|
+
fitTransform(matrix: Float64Array, n_rows: number, n_cols: number): WasmPcaResult;
|
|
2835
|
+
/**
|
|
2836
|
+
* Create a new PCA calculator. The struct carries no state — all
|
|
2837
|
+
* parameters are supplied on [`fitTransform`](Self::fit_transform).
|
|
2838
|
+
*/
|
|
2839
|
+
constructor();
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
/**
|
|
2843
|
+
* Result of a [`WasmPca2::fit_transform`] call.
|
|
2844
|
+
*
|
|
2845
|
+
* Each accessor returns an **owned** `Float64Array` (copy of the underlying
|
|
2846
|
+
* `Vec`) so JS is free to let this wrapper be GC'd without dangling views.
|
|
2847
|
+
*/
|
|
2848
|
+
export class WasmPcaResult {
|
|
2849
|
+
private constructor();
|
|
2850
|
+
free(): void;
|
|
2851
|
+
[Symbol.dispose](): void;
|
|
2852
|
+
/**
|
|
2853
|
+
* Projected 2D coordinates as a row-major `Float64Array` of length
|
|
2854
|
+
* `2 * n_rows`. `coords[2 * i + 0]` is the PC1 score for row `i`,
|
|
2855
|
+
* `coords[2 * i + 1]` is PC2.
|
|
2856
|
+
*/
|
|
2857
|
+
coords(): Float64Array;
|
|
2858
|
+
/**
|
|
2859
|
+
* Explained variance per component as `Float64Array` of length 2.
|
|
2860
|
+
* `variance[0] >= variance[1]` by construction.
|
|
2861
|
+
*/
|
|
2862
|
+
variance(): Float64Array;
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2663
2865
|
/**
|
|
2664
2866
|
* XYZ / Extended XYZ file reader.
|
|
2665
2867
|
*
|
package/molrs.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./molrs_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
Block, Box, CenterOfMass, CenterOfMassResult, Cluster, ClusterCenters, ClusterResult, Frame, Grid, GyrationTensor, InertiaTensor, LAMMPSDumpReader, LAMMPSReader, LinkedCell, MSD, MSDResult, MolRecReader, NeighborList, PDBReader, RDF, RDFResult, RadiusOfGyration, SDFReader, SmilesIR, Topology, TopologyRingInfo, WasmArray, XYZReader, generate3D, parseSMILES, start, wasmMemory, writeFrame
|
|
8
|
+
Block, Box, CenterOfMass, CenterOfMassResult, Cluster, ClusterCenters, ClusterResult, Frame, Grid, GyrationTensor, InertiaTensor, LAMMPSDumpReader, LAMMPSReader, LinkedCell, MSD, MSDResult, MolRecReader, NeighborList, PDBReader, RDF, RDFResult, RadiusOfGyration, SDFReader, SmilesIR, Topology, TopologyRingInfo, WasmArray, WasmKMeans, WasmPca2, WasmPcaResult, XYZReader, generate3D, parseSMILES, start, wasmMemory, writeFrame
|
|
9
9
|
} from "./molrs_bg.js";
|
package/molrs_bg.js
CHANGED
|
@@ -1651,6 +1651,38 @@ export class Frame {
|
|
|
1651
1651
|
}
|
|
1652
1652
|
return ret[0] === 0 ? undefined : Grid.__wrap(ret[0]);
|
|
1653
1653
|
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Read a per-frame metadata value as a numeric scalar.
|
|
1656
|
+
*
|
|
1657
|
+
* Returns `Some(v)` if the meta key exists AND its string value parses
|
|
1658
|
+
* as an `f64`. Returns `None` if the key is missing or the value is
|
|
1659
|
+
* non-numeric (e.g., `config="trans"`).
|
|
1660
|
+
*
|
|
1661
|
+
* `frame.meta` is a `HashMap<String, String>`; the ExtXYZ parser stores
|
|
1662
|
+
* all comment-line values as strings. This accessor reads numeric ones
|
|
1663
|
+
* via `str::parse::<f64>`.
|
|
1664
|
+
*
|
|
1665
|
+
* # Arguments
|
|
1666
|
+
*
|
|
1667
|
+
* * `name` — Meta key to look up (e.g., `"energy"`, `"temp"`).
|
|
1668
|
+
*
|
|
1669
|
+
* # Example (JavaScript)
|
|
1670
|
+
*
|
|
1671
|
+
* ```js
|
|
1672
|
+
* const energy = frame.getMetaScalar("energy");
|
|
1673
|
+
* if (energy !== undefined) {
|
|
1674
|
+
* console.log("Energy:", energy);
|
|
1675
|
+
* }
|
|
1676
|
+
* ```
|
|
1677
|
+
* @param {string} name
|
|
1678
|
+
* @returns {number | undefined}
|
|
1679
|
+
*/
|
|
1680
|
+
getMetaScalar(name) {
|
|
1681
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
|
|
1682
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1683
|
+
const ret = wasm.frame_getMetaScalar(this.__wbg_ptr, ptr0, len0);
|
|
1684
|
+
return ret[0] === 0 ? undefined : ret[1];
|
|
1685
|
+
}
|
|
1654
1686
|
/**
|
|
1655
1687
|
* Return the names of all grids attached to this frame.
|
|
1656
1688
|
*
|
|
@@ -1766,6 +1798,26 @@ export class Frame {
|
|
|
1766
1798
|
throw takeFromExternrefTable0(ret[0]);
|
|
1767
1799
|
}
|
|
1768
1800
|
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Return the names of all metadata keys on this frame.
|
|
1803
|
+
*
|
|
1804
|
+
* Includes all keys regardless of whether their values are numeric
|
|
1805
|
+
* or categorical. To filter to numeric keys, iterate and call
|
|
1806
|
+
* [`getMetaScalar`](Self::get_meta_scalar) on each.
|
|
1807
|
+
*
|
|
1808
|
+
* # Example (JavaScript)
|
|
1809
|
+
*
|
|
1810
|
+
* ```js
|
|
1811
|
+
* const names = frame.metaNames(); // e.g. ["energy", "config", "temp"]
|
|
1812
|
+
* ```
|
|
1813
|
+
* @returns {string[]}
|
|
1814
|
+
*/
|
|
1815
|
+
metaNames() {
|
|
1816
|
+
const ret = wasm.frame_metaNames(this.__wbg_ptr);
|
|
1817
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
1818
|
+
wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
|
|
1819
|
+
return v1;
|
|
1820
|
+
}
|
|
1769
1821
|
/**
|
|
1770
1822
|
* Create a new, empty `Frame` with no blocks and no simulation box.
|
|
1771
1823
|
*
|
|
@@ -1912,6 +1964,44 @@ export class Frame {
|
|
|
1912
1964
|
}
|
|
1913
1965
|
return ret[0] !== 0;
|
|
1914
1966
|
}
|
|
1967
|
+
/**
|
|
1968
|
+
* Set a per-frame metadata value.
|
|
1969
|
+
*
|
|
1970
|
+
* Stores `value` as the string backing for `name` on `frame.meta`.
|
|
1971
|
+
* Numeric values are read back via
|
|
1972
|
+
* [`getMetaScalar`](Self::get_meta_scalar) by parsing the string
|
|
1973
|
+
* form. `frame.meta` is the single source of truth for per-frame
|
|
1974
|
+
* scalars — no separate aggregation layer is needed on the JS side.
|
|
1975
|
+
*
|
|
1976
|
+
* # Arguments
|
|
1977
|
+
*
|
|
1978
|
+
* * `name` — Meta key (e.g., `"energy"`, `"temp"`).
|
|
1979
|
+
* * `value` — String value. For numeric labels, the caller is
|
|
1980
|
+
* responsible for converting (e.g., `num.toString()`).
|
|
1981
|
+
*
|
|
1982
|
+
* # Errors
|
|
1983
|
+
*
|
|
1984
|
+
* Throws a `JsValue` string if the frame has been dropped.
|
|
1985
|
+
*
|
|
1986
|
+
* # Example (JavaScript)
|
|
1987
|
+
*
|
|
1988
|
+
* ```js
|
|
1989
|
+
* frame.setMeta("energy", "-3.14");
|
|
1990
|
+
* frame.setMeta("note", "run-42");
|
|
1991
|
+
* ```
|
|
1992
|
+
* @param {string} name
|
|
1993
|
+
* @param {string} value
|
|
1994
|
+
*/
|
|
1995
|
+
setMeta(name, value) {
|
|
1996
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
|
|
1997
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1998
|
+
const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
|
|
1999
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2000
|
+
const ret = wasm.frame_setMeta(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
2001
|
+
if (ret[1]) {
|
|
2002
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
1915
2005
|
/**
|
|
1916
2006
|
* Attach or detach a simulation box.
|
|
1917
2007
|
*
|
|
@@ -2288,6 +2378,10 @@ export class GyrationTensor {
|
|
|
2288
2378
|
}
|
|
2289
2379
|
/**
|
|
2290
2380
|
* Compute gyration tensors. Returns a flat float typed array (9 values per cluster).
|
|
2381
|
+
*
|
|
2382
|
+
* Internally computes the cluster geometric centers (via
|
|
2383
|
+
* [`RsClusterCenters`]) since the new compute trait exposes them as a
|
|
2384
|
+
* required upstream — the old single-frame wasm API hides this detail.
|
|
2291
2385
|
* @param {Frame} frame
|
|
2292
2386
|
* @param {ClusterResult} cluster_result
|
|
2293
2387
|
* @returns {Float64Array}
|
|
@@ -2328,6 +2422,10 @@ export class InertiaTensor {
|
|
|
2328
2422
|
}
|
|
2329
2423
|
/**
|
|
2330
2424
|
* Compute inertia tensors. Returns a flat float typed array (9 values per cluster).
|
|
2425
|
+
*
|
|
2426
|
+
* Internally computes the cluster centers of mass (via
|
|
2427
|
+
* [`RsCenterOfMass`]) since the new compute trait consumes them as a
|
|
2428
|
+
* required upstream — the old single-frame wasm API hides this detail.
|
|
2331
2429
|
* @param {Frame} frame
|
|
2332
2430
|
* @param {ClusterResult} cluster_result
|
|
2333
2431
|
* @returns {Float64Array}
|
|
@@ -2734,25 +2832,23 @@ export class MSD {
|
|
|
2734
2832
|
/**
|
|
2735
2833
|
* Feed a frame into the MSD analysis.
|
|
2736
2834
|
*
|
|
2737
|
-
*
|
|
2738
|
-
*
|
|
2835
|
+
* Internally clones the frame's core data so subsequent mutations on
|
|
2836
|
+
* the JS side (e.g. trajectory playback overwriting buffers) do not
|
|
2837
|
+
* race against pending [`results`](Self::results) calls. The first
|
|
2838
|
+
* frame sets the reference configuration.
|
|
2739
2839
|
*
|
|
2740
2840
|
* # Arguments
|
|
2741
2841
|
*
|
|
2742
2842
|
* * `frame` - Frame with `"atoms"` block containing
|
|
2743
2843
|
* `x`, `y`, `z` (F) columns
|
|
2744
2844
|
*
|
|
2745
|
-
* # Errors
|
|
2746
|
-
*
|
|
2747
|
-
* Throws if the frame is missing required columns or has a
|
|
2748
|
-
* different number of atoms than the reference.
|
|
2749
|
-
*
|
|
2750
2845
|
* # Example (JavaScript)
|
|
2751
2846
|
*
|
|
2752
2847
|
* ```js
|
|
2753
2848
|
* const msd = new MSD();
|
|
2754
2849
|
* msd.feed(frame0); // sets reference
|
|
2755
|
-
* msd.feed(frame1); //
|
|
2850
|
+
* msd.feed(frame1); // added to trajectory
|
|
2851
|
+
* const series = msd.results();
|
|
2756
2852
|
* ```
|
|
2757
2853
|
* @param {Frame} frame
|
|
2758
2854
|
*/
|
|
@@ -2782,16 +2878,16 @@ export class MSD {
|
|
|
2782
2878
|
return this;
|
|
2783
2879
|
}
|
|
2784
2880
|
/**
|
|
2785
|
-
* Reset the analysis, clearing
|
|
2881
|
+
* Reset the analysis, clearing the trajectory buffer.
|
|
2786
2882
|
*/
|
|
2787
2883
|
reset() {
|
|
2788
2884
|
wasm.msd_reset(this.__wbg_ptr);
|
|
2789
2885
|
}
|
|
2790
2886
|
/**
|
|
2791
|
-
*
|
|
2887
|
+
* Run the stateless [`molrs_compute::MSD`] over every fed frame and
|
|
2888
|
+
* return the per-frame time series.
|
|
2792
2889
|
*
|
|
2793
|
-
*
|
|
2794
|
-
* reference frame, which has MSD = 0).
|
|
2890
|
+
* The first frame is always the reference, so `results()[0].mean ≈ 0`.
|
|
2795
2891
|
*
|
|
2796
2892
|
* # Example (JavaScript)
|
|
2797
2893
|
*
|
|
@@ -2803,6 +2899,9 @@ export class MSD {
|
|
|
2803
2899
|
*/
|
|
2804
2900
|
results() {
|
|
2805
2901
|
const ret = wasm.msd_results(this.__wbg_ptr);
|
|
2902
|
+
if (ret[3]) {
|
|
2903
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
2904
|
+
}
|
|
2806
2905
|
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
2807
2906
|
wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
|
|
2808
2907
|
return v1;
|
|
@@ -3168,15 +3267,16 @@ if (Symbol.dispose) PDBReader.prototype[Symbol.dispose] = PDBReader.prototype.fr
|
|
|
3168
3267
|
/**
|
|
3169
3268
|
* Radial distribution function g(r) analysis.
|
|
3170
3269
|
*
|
|
3171
|
-
*
|
|
3172
|
-
*
|
|
3173
|
-
*
|
|
3270
|
+
* Bins neighbor-pair distances in `[rMin, rMax]` and normalizes by the
|
|
3271
|
+
* ideal-gas pair density. Defaults follow freud (`rMin = 0`). Periodic
|
|
3272
|
+
* systems take their normalization volume from `frame.simbox`; non-periodic
|
|
3273
|
+
* systems must supply it explicitly via [`computeWithVolume`].
|
|
3174
3274
|
*
|
|
3175
3275
|
* # Algorithm
|
|
3176
3276
|
*
|
|
3177
3277
|
* g(r) = n(r) / (rho * V_shell(r) * N_ref)
|
|
3178
3278
|
*
|
|
3179
|
-
* where `n(r)` is the pair count in bin `r`, `rho` is the number
|
|
3279
|
+
* where `n(r)` is the pair count in bin `r`, `rho = N/V` is the number
|
|
3180
3280
|
* density, and `V_shell(r)` is the shell volume for that bin.
|
|
3181
3281
|
*
|
|
3182
3282
|
* # Example (JavaScript)
|
|
@@ -3185,11 +3285,14 @@ if (Symbol.dispose) PDBReader.prototype[Symbol.dispose] = PDBReader.prototype.fr
|
|
|
3185
3285
|
* const lc = new LinkedCell(5.0);
|
|
3186
3286
|
* const nlist = lc.build(frame);
|
|
3187
3287
|
*
|
|
3188
|
-
* const rdf = new RDF(100, 5.0);
|
|
3288
|
+
* const rdf = new RDF(100, 5.0); // rMin defaults to 0
|
|
3189
3289
|
* const result = rdf.compute(frame, nlist);
|
|
3190
3290
|
*
|
|
3191
|
-
*
|
|
3192
|
-
* const
|
|
3291
|
+
* // Non-periodic frame: supply the normalization volume.
|
|
3292
|
+
* const resultFree = rdf.computeWithVolume(nlist, volumeA3);
|
|
3293
|
+
*
|
|
3294
|
+
* const r = result.binCenters();
|
|
3295
|
+
* const gr = result.rdf();
|
|
3193
3296
|
* ```
|
|
3194
3297
|
*/
|
|
3195
3298
|
export class RDF {
|
|
@@ -3204,64 +3307,88 @@ export class RDF {
|
|
|
3204
3307
|
wasm.__wbg_rdf_free(ptr, 0);
|
|
3205
3308
|
}
|
|
3206
3309
|
/**
|
|
3207
|
-
* Compute
|
|
3208
|
-
*
|
|
3209
|
-
* The frame is needed to read the simulation box volume for
|
|
3210
|
-
* normalization.
|
|
3310
|
+
* Compute g(r) using the simulation-box volume from `frame.simbox`.
|
|
3211
3311
|
*
|
|
3212
3312
|
* # Arguments
|
|
3213
3313
|
*
|
|
3214
|
-
* * `frame` - Frame with a `simbox` set (for volume
|
|
3314
|
+
* * `frame` - Frame with a `simbox` set (used only for volume)
|
|
3215
3315
|
* * `neighbors` - Pre-built [`NeighborList`] from [`LinkedCell`]
|
|
3216
3316
|
*
|
|
3217
|
-
* #
|
|
3317
|
+
* # Errors
|
|
3218
3318
|
*
|
|
3219
|
-
*
|
|
3220
|
-
*
|
|
3319
|
+
* Throws if the frame has no `simbox` — use
|
|
3320
|
+
* [`computeWithVolume`](Self::compute_with_volume) for non-periodic frames.
|
|
3321
|
+
* @param {Frame} frame
|
|
3322
|
+
* @param {NeighborList} neighbors
|
|
3323
|
+
* @returns {RDFResult}
|
|
3324
|
+
*/
|
|
3325
|
+
compute(frame, neighbors) {
|
|
3326
|
+
_assertClass(frame, Frame);
|
|
3327
|
+
_assertClass(neighbors, NeighborList);
|
|
3328
|
+
const ret = wasm.rdf_compute(this.__wbg_ptr, frame.__wbg_ptr, neighbors.__wbg_ptr);
|
|
3329
|
+
if (ret[2]) {
|
|
3330
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
3331
|
+
}
|
|
3332
|
+
return RDFResult.__wrap(ret[0]);
|
|
3333
|
+
}
|
|
3334
|
+
/**
|
|
3335
|
+
* Compute g(r) using an explicit normalization volume (A^3).
|
|
3221
3336
|
*
|
|
3222
|
-
*
|
|
3337
|
+
* Use this for non-periodic systems or to override the box volume.
|
|
3338
|
+
* Internally wraps the supplied volume as a cubic SimBox since the
|
|
3339
|
+
* underlying [`molrs_compute::RDF`] pulls its normalization volume from
|
|
3340
|
+
* `frame.simbox`.
|
|
3341
|
+
*
|
|
3342
|
+
* # Arguments
|
|
3223
3343
|
*
|
|
3224
|
-
*
|
|
3344
|
+
* * `neighbors` - Pre-built [`NeighborList`]
|
|
3345
|
+
* * `volume` - Normalization volume in A^3 (must be finite and > 0)
|
|
3225
3346
|
*
|
|
3226
3347
|
* # Example (JavaScript)
|
|
3227
3348
|
*
|
|
3228
3349
|
* ```js
|
|
3229
|
-
* const result = rdf.
|
|
3230
|
-
* const gr = result.rdf(); // Float32Array or Float64Array
|
|
3350
|
+
* const result = rdf.computeWithVolume(nlist, 1000.0);
|
|
3231
3351
|
* ```
|
|
3232
|
-
* @param {Frame} frame
|
|
3233
3352
|
* @param {NeighborList} neighbors
|
|
3353
|
+
* @param {number} volume
|
|
3234
3354
|
* @returns {RDFResult}
|
|
3235
3355
|
*/
|
|
3236
|
-
|
|
3237
|
-
_assertClass(frame, Frame);
|
|
3356
|
+
computeWithVolume(neighbors, volume) {
|
|
3238
3357
|
_assertClass(neighbors, NeighborList);
|
|
3239
|
-
const ret = wasm.
|
|
3358
|
+
const ret = wasm.rdf_computeWithVolume(this.__wbg_ptr, neighbors.__wbg_ptr, volume);
|
|
3240
3359
|
if (ret[2]) {
|
|
3241
3360
|
throw takeFromExternrefTable0(ret[1]);
|
|
3242
3361
|
}
|
|
3243
3362
|
return RDFResult.__wrap(ret[0]);
|
|
3244
3363
|
}
|
|
3245
3364
|
/**
|
|
3246
|
-
* Create a new RDF analysis
|
|
3365
|
+
* Create a new RDF analysis.
|
|
3247
3366
|
*
|
|
3248
3367
|
* # Arguments
|
|
3249
3368
|
*
|
|
3250
3369
|
* * `n_bins` - Number of histogram bins
|
|
3251
|
-
* * `r_max` -
|
|
3252
|
-
*
|
|
3370
|
+
* * `r_max` - Upper radial cutoff in angstrom (A). Should be ≤ the
|
|
3371
|
+
* neighbor-search cutoff.
|
|
3372
|
+
* * `r_min` - Lower radial cutoff in angstrom (A). Optional, defaults
|
|
3373
|
+
* to 0 (freud convention). Pairs with `d < rMin` or `d == 0` are
|
|
3374
|
+
* excluded from the histogram.
|
|
3253
3375
|
*
|
|
3254
3376
|
* # Example (JavaScript)
|
|
3255
3377
|
*
|
|
3256
3378
|
* ```js
|
|
3257
|
-
* const rdf = new RDF(100, 5.0);
|
|
3379
|
+
* const rdf = new RDF(100, 5.0); // rMin = 0
|
|
3380
|
+
* const rdf2 = new RDF(100, 5.0, 0.5); // exclude d < 0.5 A
|
|
3258
3381
|
* ```
|
|
3259
3382
|
* @param {number} n_bins
|
|
3260
3383
|
* @param {number} r_max
|
|
3384
|
+
* @param {number | null} [r_min]
|
|
3261
3385
|
*/
|
|
3262
|
-
constructor(n_bins, r_max) {
|
|
3263
|
-
const ret = wasm.rdf_new(n_bins, r_max);
|
|
3264
|
-
|
|
3386
|
+
constructor(n_bins, r_max, r_min) {
|
|
3387
|
+
const ret = wasm.rdf_new(n_bins, r_max, !isLikeNone(r_min), isLikeNone(r_min) ? 0 : r_min);
|
|
3388
|
+
if (ret[2]) {
|
|
3389
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
3390
|
+
}
|
|
3391
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
3265
3392
|
RDFFinalization.register(this, this.__wbg_ptr, this);
|
|
3266
3393
|
return this;
|
|
3267
3394
|
}
|
|
@@ -3339,6 +3466,14 @@ export class RDFResult {
|
|
|
3339
3466
|
const ret = wasm.rdfresult_pairCounts(this.__wbg_ptr);
|
|
3340
3467
|
return ret;
|
|
3341
3468
|
}
|
|
3469
|
+
/**
|
|
3470
|
+
* Inner cutoff in A (lower edge of bin 0).
|
|
3471
|
+
* @returns {number}
|
|
3472
|
+
*/
|
|
3473
|
+
get rMin() {
|
|
3474
|
+
const ret = wasm.rdfresult_rMin(this.__wbg_ptr);
|
|
3475
|
+
return ret;
|
|
3476
|
+
}
|
|
3342
3477
|
/**
|
|
3343
3478
|
* Zero-copy `Float64Array` view of normalized g(r). Same invalidation
|
|
3344
3479
|
* caveat.
|
|
@@ -3349,7 +3484,7 @@ export class RDFResult {
|
|
|
3349
3484
|
return ret;
|
|
3350
3485
|
}
|
|
3351
3486
|
/**
|
|
3352
|
-
*
|
|
3487
|
+
* Normalization volume in A^3 (from the SimBox or the explicit caller value).
|
|
3353
3488
|
* @returns {number}
|
|
3354
3489
|
*/
|
|
3355
3490
|
get volume() {
|
|
@@ -3375,6 +3510,10 @@ export class RadiusOfGyration {
|
|
|
3375
3510
|
}
|
|
3376
3511
|
/**
|
|
3377
3512
|
* Compute radii of gyration. Returns a float typed array of length `numClusters`.
|
|
3513
|
+
*
|
|
3514
|
+
* Internally computes the cluster centers of mass so the single-frame
|
|
3515
|
+
* wasm signature `(frame, cluster)` stays stable despite the new
|
|
3516
|
+
* compute trait needing explicit COM upstream.
|
|
3378
3517
|
* @param {Frame} frame
|
|
3379
3518
|
* @param {ClusterResult} cluster_result
|
|
3380
3519
|
* @returns {Float64Array}
|
|
@@ -4171,6 +4310,195 @@ export class WasmArray {
|
|
|
4171
4310
|
}
|
|
4172
4311
|
if (Symbol.dispose) WasmArray.prototype[Symbol.dispose] = WasmArray.prototype.free;
|
|
4173
4312
|
|
|
4313
|
+
/**
|
|
4314
|
+
* Wrapper for [`molrs_compute::kmeans::KMeans`].
|
|
4315
|
+
*
|
|
4316
|
+
* # Example (JavaScript)
|
|
4317
|
+
*
|
|
4318
|
+
* ```js
|
|
4319
|
+
* const km = new WasmKMeans(3, 100, 42);
|
|
4320
|
+
* const labels = km.fit(coords, nRows, 2); // Int32Array
|
|
4321
|
+
* ```
|
|
4322
|
+
*/
|
|
4323
|
+
export class WasmKMeans {
|
|
4324
|
+
__destroy_into_raw() {
|
|
4325
|
+
const ptr = this.__wbg_ptr;
|
|
4326
|
+
this.__wbg_ptr = 0;
|
|
4327
|
+
WasmKMeansFinalization.unregister(this);
|
|
4328
|
+
return ptr;
|
|
4329
|
+
}
|
|
4330
|
+
free() {
|
|
4331
|
+
const ptr = this.__destroy_into_raw();
|
|
4332
|
+
wasm.__wbg_wasmkmeans_free(ptr, 0);
|
|
4333
|
+
}
|
|
4334
|
+
/**
|
|
4335
|
+
* Cluster a row-major `n_rows × n_dims` coordinate matrix.
|
|
4336
|
+
*
|
|
4337
|
+
* # Returns
|
|
4338
|
+
*
|
|
4339
|
+
* Cluster labels in `0..k` as an owned `Int32Array`, one per row.
|
|
4340
|
+
*
|
|
4341
|
+
* # Errors
|
|
4342
|
+
*
|
|
4343
|
+
* Throws if `k > n_rows`, `n_dims == 0`, the length does not match
|
|
4344
|
+
* `n_rows * n_dims`, or any element is non-finite.
|
|
4345
|
+
* @param {Float64Array} coords
|
|
4346
|
+
* @param {number} n_rows
|
|
4347
|
+
* @param {number} n_dims
|
|
4348
|
+
* @returns {Int32Array}
|
|
4349
|
+
*/
|
|
4350
|
+
fit(coords, n_rows, n_dims) {
|
|
4351
|
+
const ptr0 = passArrayF64ToWasm0(coords, wasm.__wbindgen_malloc_command_export);
|
|
4352
|
+
const len0 = WASM_VECTOR_LEN;
|
|
4353
|
+
const ret = wasm.wasmkmeans_fit(this.__wbg_ptr, ptr0, len0, n_rows, n_dims);
|
|
4354
|
+
if (ret[2]) {
|
|
4355
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
4356
|
+
}
|
|
4357
|
+
return takeFromExternrefTable0(ret[0]);
|
|
4358
|
+
}
|
|
4359
|
+
/**
|
|
4360
|
+
* Create a new k-means configuration.
|
|
4361
|
+
*
|
|
4362
|
+
* # Arguments
|
|
4363
|
+
*
|
|
4364
|
+
* * `k` — number of clusters (>= 1).
|
|
4365
|
+
* * `max_iter` — maximum Lloyd iterations (>= 1).
|
|
4366
|
+
* * `seed` — RNG seed for k-means++ initialization. Cast to `u64`
|
|
4367
|
+
* internally (JS numbers are `f64`; integers up to 2^53 pass
|
|
4368
|
+
* through losslessly).
|
|
4369
|
+
*
|
|
4370
|
+
* # Errors
|
|
4371
|
+
*
|
|
4372
|
+
* Throws if `k == 0` or `max_iter == 0`.
|
|
4373
|
+
* @param {number} k
|
|
4374
|
+
* @param {number} max_iter
|
|
4375
|
+
* @param {number} seed
|
|
4376
|
+
*/
|
|
4377
|
+
constructor(k, max_iter, seed) {
|
|
4378
|
+
const ret = wasm.wasmkmeans_new(k, max_iter, seed);
|
|
4379
|
+
if (ret[2]) {
|
|
4380
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
4381
|
+
}
|
|
4382
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
4383
|
+
WasmKMeansFinalization.register(this, this.__wbg_ptr, this);
|
|
4384
|
+
return this;
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
if (Symbol.dispose) WasmKMeans.prototype[Symbol.dispose] = WasmKMeans.prototype.free;
|
|
4388
|
+
|
|
4389
|
+
/**
|
|
4390
|
+
* Stateless wrapper for [`molrs_compute::pca::Pca2`].
|
|
4391
|
+
*
|
|
4392
|
+
* All configuration lives on [`fitTransform`](Self::fit_transform).
|
|
4393
|
+
*
|
|
4394
|
+
* # Example (JavaScript)
|
|
4395
|
+
*
|
|
4396
|
+
* ```js
|
|
4397
|
+
* const pca = new WasmPca2();
|
|
4398
|
+
* const result = pca.fitTransform(matrix, nRows, nCols);
|
|
4399
|
+
* const coords = result.coords(); // Float64Array, length 2 * nRows
|
|
4400
|
+
* const variance = result.variance(); // Float64Array, length 2
|
|
4401
|
+
* ```
|
|
4402
|
+
*/
|
|
4403
|
+
export class WasmPca2 {
|
|
4404
|
+
__destroy_into_raw() {
|
|
4405
|
+
const ptr = this.__wbg_ptr;
|
|
4406
|
+
this.__wbg_ptr = 0;
|
|
4407
|
+
WasmPca2Finalization.unregister(this);
|
|
4408
|
+
return ptr;
|
|
4409
|
+
}
|
|
4410
|
+
free() {
|
|
4411
|
+
const ptr = this.__destroy_into_raw();
|
|
4412
|
+
wasm.__wbg_wasmpca2_free(ptr, 0);
|
|
4413
|
+
}
|
|
4414
|
+
/**
|
|
4415
|
+
* Fit 2-component PCA on a row-major observation matrix and return the
|
|
4416
|
+
* projected coordinates + per-component variance.
|
|
4417
|
+
*
|
|
4418
|
+
* # Arguments
|
|
4419
|
+
*
|
|
4420
|
+
* * `matrix` — row-major `n_rows × n_cols` observation matrix.
|
|
4421
|
+
* * `n_rows` — number of observations.
|
|
4422
|
+
* * `n_cols` — number of features.
|
|
4423
|
+
*
|
|
4424
|
+
* # Errors
|
|
4425
|
+
*
|
|
4426
|
+
* Throws if `n_rows < 3`, `n_cols < 2`, the length does not match
|
|
4427
|
+
* `n_rows * n_cols`, any element is non-finite, or any column has
|
|
4428
|
+
* zero variance.
|
|
4429
|
+
* @param {Float64Array} matrix
|
|
4430
|
+
* @param {number} n_rows
|
|
4431
|
+
* @param {number} n_cols
|
|
4432
|
+
* @returns {WasmPcaResult}
|
|
4433
|
+
*/
|
|
4434
|
+
fitTransform(matrix, n_rows, n_cols) {
|
|
4435
|
+
const ptr0 = passArrayF64ToWasm0(matrix, wasm.__wbindgen_malloc_command_export);
|
|
4436
|
+
const len0 = WASM_VECTOR_LEN;
|
|
4437
|
+
const ret = wasm.wasmpca2_fitTransform(this.__wbg_ptr, ptr0, len0, n_rows, n_cols);
|
|
4438
|
+
if (ret[2]) {
|
|
4439
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
4440
|
+
}
|
|
4441
|
+
return WasmPcaResult.__wrap(ret[0]);
|
|
4442
|
+
}
|
|
4443
|
+
/**
|
|
4444
|
+
* Create a new PCA calculator. The struct carries no state — all
|
|
4445
|
+
* parameters are supplied on [`fitTransform`](Self::fit_transform).
|
|
4446
|
+
*/
|
|
4447
|
+
constructor() {
|
|
4448
|
+
const ret = wasm.wasmpca2_new();
|
|
4449
|
+
this.__wbg_ptr = ret >>> 0;
|
|
4450
|
+
WasmPca2Finalization.register(this, this.__wbg_ptr, this);
|
|
4451
|
+
return this;
|
|
4452
|
+
}
|
|
4453
|
+
}
|
|
4454
|
+
if (Symbol.dispose) WasmPca2.prototype[Symbol.dispose] = WasmPca2.prototype.free;
|
|
4455
|
+
|
|
4456
|
+
/**
|
|
4457
|
+
* Result of a [`WasmPca2::fit_transform`] call.
|
|
4458
|
+
*
|
|
4459
|
+
* Each accessor returns an **owned** `Float64Array` (copy of the underlying
|
|
4460
|
+
* `Vec`) so JS is free to let this wrapper be GC'd without dangling views.
|
|
4461
|
+
*/
|
|
4462
|
+
export class WasmPcaResult {
|
|
4463
|
+
static __wrap(ptr) {
|
|
4464
|
+
ptr = ptr >>> 0;
|
|
4465
|
+
const obj = Object.create(WasmPcaResult.prototype);
|
|
4466
|
+
obj.__wbg_ptr = ptr;
|
|
4467
|
+
WasmPcaResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
4468
|
+
return obj;
|
|
4469
|
+
}
|
|
4470
|
+
__destroy_into_raw() {
|
|
4471
|
+
const ptr = this.__wbg_ptr;
|
|
4472
|
+
this.__wbg_ptr = 0;
|
|
4473
|
+
WasmPcaResultFinalization.unregister(this);
|
|
4474
|
+
return ptr;
|
|
4475
|
+
}
|
|
4476
|
+
free() {
|
|
4477
|
+
const ptr = this.__destroy_into_raw();
|
|
4478
|
+
wasm.__wbg_wasmpcaresult_free(ptr, 0);
|
|
4479
|
+
}
|
|
4480
|
+
/**
|
|
4481
|
+
* Projected 2D coordinates as a row-major `Float64Array` of length
|
|
4482
|
+
* `2 * n_rows`. `coords[2 * i + 0]` is the PC1 score for row `i`,
|
|
4483
|
+
* `coords[2 * i + 1]` is PC2.
|
|
4484
|
+
* @returns {Float64Array}
|
|
4485
|
+
*/
|
|
4486
|
+
coords() {
|
|
4487
|
+
const ret = wasm.wasmpcaresult_coords(this.__wbg_ptr);
|
|
4488
|
+
return ret;
|
|
4489
|
+
}
|
|
4490
|
+
/**
|
|
4491
|
+
* Explained variance per component as `Float64Array` of length 2.
|
|
4492
|
+
* `variance[0] >= variance[1]` by construction.
|
|
4493
|
+
* @returns {Float64Array}
|
|
4494
|
+
*/
|
|
4495
|
+
variance() {
|
|
4496
|
+
const ret = wasm.wasmpcaresult_variance(this.__wbg_ptr);
|
|
4497
|
+
return ret;
|
|
4498
|
+
}
|
|
4499
|
+
}
|
|
4500
|
+
if (Symbol.dispose) WasmPcaResult.prototype[Symbol.dispose] = WasmPcaResult.prototype.free;
|
|
4501
|
+
|
|
4174
4502
|
/**
|
|
4175
4503
|
* XYZ / Extended XYZ file reader.
|
|
4176
4504
|
*
|
|
@@ -4592,6 +4920,14 @@ export function __wbg_new_from_slice_ede497d29b90a4ad(arg0, arg1) {
|
|
|
4592
4920
|
const ret = new Int32Array(getArrayI32FromWasm0(arg0, arg1));
|
|
4593
4921
|
return ret;
|
|
4594
4922
|
}
|
|
4923
|
+
export function __wbg_new_with_length_33f0a4c41f7ce2fc(arg0) {
|
|
4924
|
+
const ret = new Int32Array(arg0 >>> 0);
|
|
4925
|
+
return ret;
|
|
4926
|
+
}
|
|
4927
|
+
export function __wbg_new_with_length_5cfd777b51078805(arg0) {
|
|
4928
|
+
const ret = new Float64Array(arg0 >>> 0);
|
|
4929
|
+
return ret;
|
|
4930
|
+
}
|
|
4595
4931
|
export function __wbg_next_0340c4ae324393c3() { return handleError(function (arg0) {
|
|
4596
4932
|
const ret = arg0.next();
|
|
4597
4933
|
return ret;
|
|
@@ -4612,6 +4948,12 @@ export function __wbg_push_471a5b068a5295f6(arg0, arg1) {
|
|
|
4612
4948
|
const ret = arg0.push(arg1);
|
|
4613
4949
|
return ret;
|
|
4614
4950
|
}
|
|
4951
|
+
export function __wbg_set_5637e648df81c8e5(arg0, arg1, arg2) {
|
|
4952
|
+
arg0.set(getArrayF64FromWasm0(arg1, arg2));
|
|
4953
|
+
}
|
|
4954
|
+
export function __wbg_set_6c7215e0274bbbf2(arg0, arg1, arg2) {
|
|
4955
|
+
arg0.set(getArrayI32FromWasm0(arg1, arg2));
|
|
4956
|
+
}
|
|
4615
4957
|
export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
|
|
4616
4958
|
const ret = arg1.stack;
|
|
4617
4959
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
|
|
@@ -4727,6 +5069,15 @@ const TopologyRingInfoFinalization = (typeof FinalizationRegistry === 'undefined
|
|
|
4727
5069
|
const WasmArrayFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
4728
5070
|
? { register: () => {}, unregister: () => {} }
|
|
4729
5071
|
: new FinalizationRegistry(ptr => wasm.__wbg_wasmarray_free(ptr >>> 0, 1));
|
|
5072
|
+
const WasmKMeansFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
5073
|
+
? { register: () => {}, unregister: () => {} }
|
|
5074
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmkmeans_free(ptr >>> 0, 1));
|
|
5075
|
+
const WasmPca2Finalization = (typeof FinalizationRegistry === 'undefined')
|
|
5076
|
+
? { register: () => {}, unregister: () => {} }
|
|
5077
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmpca2_free(ptr >>> 0, 1));
|
|
5078
|
+
const WasmPcaResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
5079
|
+
? { register: () => {}, unregister: () => {} }
|
|
5080
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmpcaresult_free(ptr >>> 0, 1));
|
|
4730
5081
|
const SmilesIRFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
4731
5082
|
? { register: () => {}, unregister: () => {} }
|
|
4732
5083
|
: new FinalizationRegistry(ptr => wasm.__wbg_smilesir_free(ptr >>> 0, 1));
|
package/molrs_bg.wasm
CHANGED
|
Binary file
|