openchemlib-search-wasm 1.1.0 → 2.0.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.
- package/README.md +204 -22
- package/lib/hex.d.ts +31 -0
- package/lib/hex.d.ts.map +1 -0
- package/lib/hex.js +41 -0
- package/lib/hex.js.map +1 -0
- package/lib/index.d.ts +101 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +131 -8
- package/lib/index.js.map +1 -1
- package/lib/scan.d.ts +50 -7
- package/lib/scan.d.ts.map +1 -1
- package/lib/scan.js +104 -10
- package/lib/scan.js.map +1 -1
- package/lib/strongHash.d.ts +9 -0
- package/lib/strongHash.d.ts.map +1 -0
- package/lib/strongHash.js +56 -0
- package/lib/strongHash.js.map +1 -0
- package/lib/types.d.ts +43 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +11 -0
- package/lib/types.js.map +1 -1
- package/lib/wasm/load.d.ts.map +1 -1
- package/lib/wasm/load.js +9 -1
- package/lib/wasm/load.js.map +1 -1
- package/lib/wasm/log.d.ts +36 -0
- package/lib/wasm/log.d.ts.map +1 -0
- package/lib/wasm/log.js +52 -0
- package/lib/wasm/log.js.map +1 -0
- package/package.json +1 -1
- package/src/hex.ts +43 -0
- package/src/index.ts +213 -11
- package/src/scan.ts +193 -12
- package/src/strongHash.ts +57 -0
- package/src/types.ts +69 -2
- package/src/wasm/load.ts +10 -1
- package/src/wasm/log.ts +66 -0
- package/wasm/data.js +1 -1
- package/wasm/runtime.d.ts +6 -0
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,GAC7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AAU,yBAAyB,CACvC,MAAc,EACd,UAAuB,EAAE;IAEzB,MAAM,EACJ,mBAAmB,GAAG,KAAK,EAC3B,cAAc,EACd,YAAY,GAAG,qBAAqB,GACrC,GAAG,OAAO,CAAC;IACZ,MAAM,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5B,4BAA4B,CAC1B,CAAC,MAAM,CAAC,EACR,MAAM,EACN,mBAAmB,EACnB,CAAC,EACD,CAAC,EACD,cAAc,EACd,YAAY,CACb,CAAC;IACF,OAAO,MAAM,CAAC,CAAC,CAAW,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAiB,EACjB,UAAuB,EAAE;IAEzB,MAAM,EACJ,mBAAmB,GAAG,KAAK,EAC3B,cAAc,EACd,YAAY,GAAG,qBAAqB,GACrC,GAAG,OAAO,CAAC;IACZ,MAAM,MAAM,GAAG,IAAI,KAAK,CAAS,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClE,4BAA4B,CAC1B,OAAO,EACP,MAAM,EACN,mBAAmB,EACnB,CAAC,EACD,OAAO,CAAC,MAAM,EACd,cAAc,EACd,YAAY,CACb,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/lib/scan.d.ts
CHANGED
|
@@ -27,9 +27,8 @@ export declare function checkQuery(mode: SearchMode, idCodeQuery: string): void;
|
|
|
27
27
|
/**
|
|
28
28
|
* Fingerprints `idCodes[from .. to)` into `result`, sixteen words per molecule.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* for a molecule that could not be read.
|
|
30
|
+
* A molecule that cannot be read gets sixteen zeros, which no non-empty query is a subset of, so it
|
|
31
|
+
* is never a false candidate.
|
|
33
32
|
* @param idCodes - The molecules to fingerprint.
|
|
34
33
|
* @param result - The caller's buffer, `16 * idCodes.length` words long.
|
|
35
34
|
* @param from - The first index to fingerprint.
|
|
@@ -40,15 +39,59 @@ export declare function buildIndexes(idCodes: string[], result: Int32Array, from
|
|
|
40
39
|
/**
|
|
41
40
|
* Hashes `idCodes[from .. to)` into `result`, one no-stereo tautomer hash per molecule.
|
|
42
41
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* returns for a molecule it cannot canonize, so the two failures are reported the same way.
|
|
42
|
+
* A molecule that cannot be read gets `NO_HASH`, which is also what OpenChemLib returns for one it
|
|
43
|
+
* cannot canonize, so the two failures are reported the same way.
|
|
46
44
|
* @param idCodes - The molecules to hash.
|
|
47
45
|
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
48
46
|
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
49
47
|
* @param from - The first index to hash.
|
|
50
48
|
* @param to - One past the last index to hash.
|
|
49
|
+
* @param tautomerCounts - Filled with how many tautomers each molecule needed; an entry that reached
|
|
50
|
+
* `maxTautomers` is one OpenChemLib stopped early on.
|
|
51
|
+
* @param maxTautomers - The ceiling on that enumeration, which is what bounds the cost.
|
|
51
52
|
* @returns How many molecules were hashed.
|
|
52
53
|
*/
|
|
53
|
-
export declare function buildNoStereoTautomerHashes(idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number): number;
|
|
54
|
+
export declare function buildNoStereoTautomerHashes(idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number, tautomerCounts?: Int32Array, maxTautomers?: number): number;
|
|
55
|
+
/**
|
|
56
|
+
* Hashes `idCodes[from .. to)` into `result`, one no-stereo hash per molecule.
|
|
57
|
+
*
|
|
58
|
+
* Fails the same way {@link buildNoStereoTautomerHashes} does: `0` for an idcode the WASM side
|
|
59
|
+
* cannot read and for a molecule OpenChemLib cannot canonize.
|
|
60
|
+
* @param idCodes - The molecules to hash.
|
|
61
|
+
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
62
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
63
|
+
* @param from - The first index to hash.
|
|
64
|
+
* @param to - One past the last index to hash.
|
|
65
|
+
* @returns How many molecules were hashed.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildNoStereoHashes(idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Canonizes `idCodes[from .. to)` into `result`, one no-stereo idcode per molecule.
|
|
70
|
+
*
|
|
71
|
+
* This is the string {@link buildNoStereoHashes} hashes, for a caller that stores the canonical form
|
|
72
|
+
* rather than a 64-bit key. A molecule that cannot be read keeps the `NO_ID_CODE` the caller's array
|
|
73
|
+
* was filled with.
|
|
74
|
+
* @param idCodes - The molecules to canonize.
|
|
75
|
+
* @param result - The caller's array, `idCodes.length` entries long, filled with `NO_ID_CODE`.
|
|
76
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
77
|
+
* @param from - The first index to canonize.
|
|
78
|
+
* @param to - One past the last index to canonize.
|
|
79
|
+
* @returns How many molecules were canonized.
|
|
80
|
+
*/
|
|
81
|
+
export declare function buildNoStereoIdCodes(idCodes: string[], result: string[], largestFragmentOnly: boolean, from: number, to: number): number;
|
|
82
|
+
/**
|
|
83
|
+
* Canonizes `idCodes[from .. to)` into `result`, one no-stereo generic-tautomer idcode per molecule.
|
|
84
|
+
*
|
|
85
|
+
* Fails the same way {@link buildNoStereoIdCodes} does.
|
|
86
|
+
* @param idCodes - The molecules to canonize.
|
|
87
|
+
* @param result - The caller's array, `idCodes.length` entries long, filled with `NO_ID_CODE`.
|
|
88
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
89
|
+
* @param from - The first index to canonize.
|
|
90
|
+
* @param to - One past the last index to canonize.
|
|
91
|
+
* @param tautomerCounts - Filled with how many tautomers each molecule needed; an entry that reached
|
|
92
|
+
* `maxTautomers` is one OpenChemLib stopped early on.
|
|
93
|
+
* @param maxTautomers - The ceiling on that enumeration, which is what bounds the cost.
|
|
94
|
+
* @returns How many molecules were canonized.
|
|
95
|
+
*/
|
|
96
|
+
export declare function buildNoStereoTautomerIdCodes(idCodes: string[], result: string[], largestFragmentOnly: boolean, from: number, to: number, tautomerCounts?: Int32Array, maxTautomers?: number): number;
|
|
54
97
|
//# sourceMappingURL=scan.d.ts.map
|
package/lib/scan.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAqB3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,UAAU,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,IAAI,CA0BN;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAStE;AAwCD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,MAAM,CAOR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,aAAa,EACrB,mBAAmB,EAAE,OAAO,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,cAAc,GAAE,UAA2C,EAC3D,YAAY,GAAE,MAA8B,GAC3C,MAAM,CAkBR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,aAAa,EACrB,mBAAmB,EAAE,OAAO,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,MAAM,CAgBR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EAAE,EAChB,mBAAmB,EAAE,OAAO,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,MAAM,CAgBR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EAAE,EAChB,mBAAmB,EAAE,OAAO,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,cAAc,GAAE,UAA2C,EAC3D,YAAY,GAAE,MAA8B,GAC3C,MAAM,CAkBR"}
|
package/lib/scan.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SimilarityResult, SubstructureResult } from "./types.js";
|
|
1
|
+
import { DEFAULT_MAX_TAUTOMERS, INDEX_WORDS, NO_HASH, NO_ID_CODE, SimilarityResult, SubstructureResult, } from "./types.js";
|
|
2
2
|
import { loadOCL } from "./wasm/load.js";
|
|
3
3
|
// Top-level await: the WASM module is instantiated when this module is imported, so the searches are
|
|
4
4
|
// plain calls. A worker pays it once, at startup, for about 25 ms from the built package.
|
|
@@ -88,9 +88,8 @@ function firstPending(mode, result, from, to) {
|
|
|
88
88
|
/**
|
|
89
89
|
* Fingerprints `idCodes[from .. to)` into `result`, sixteen words per molecule.
|
|
90
90
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* for a molecule that could not be read.
|
|
91
|
+
* A molecule that cannot be read gets sixteen zeros, which no non-empty query is a subset of, so it
|
|
92
|
+
* is never a false candidate.
|
|
94
93
|
* @param idCodes - The molecules to fingerprint.
|
|
95
94
|
* @param result - The caller's buffer, `16 * idCodes.length` words long.
|
|
96
95
|
* @param from - The first index to fingerprint.
|
|
@@ -98,22 +97,117 @@ function firstPending(mode, result, from, to) {
|
|
|
98
97
|
* @returns How many molecules were parsed and fingerprinted.
|
|
99
98
|
*/
|
|
100
99
|
export function buildIndexes(idCodes, result, from, to) {
|
|
101
|
-
return Search.getIndexes(idCodes, result, from, to);
|
|
100
|
+
return recoveringFromTraps((first, last) => Search.getIndexes(idCodes, result, first, last), (index) => result.fill(0, index * INDEX_WORDS, (index + 1) * INDEX_WORDS), from, to);
|
|
102
101
|
}
|
|
103
102
|
/**
|
|
104
103
|
* Hashes `idCodes[from .. to)` into `result`, one no-stereo tautomer hash per molecule.
|
|
105
104
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* returns for a molecule it cannot canonize, so the two failures are reported the same way.
|
|
105
|
+
* A molecule that cannot be read gets `NO_HASH`, which is also what OpenChemLib returns for one it
|
|
106
|
+
* cannot canonize, so the two failures are reported the same way.
|
|
109
107
|
* @param idCodes - The molecules to hash.
|
|
110
108
|
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
111
109
|
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
112
110
|
* @param from - The first index to hash.
|
|
113
111
|
* @param to - One past the last index to hash.
|
|
112
|
+
* @param tautomerCounts - Filled with how many tautomers each molecule needed; an entry that reached
|
|
113
|
+
* `maxTautomers` is one OpenChemLib stopped early on.
|
|
114
|
+
* @param maxTautomers - The ceiling on that enumeration, which is what bounds the cost.
|
|
114
115
|
* @returns How many molecules were hashed.
|
|
115
116
|
*/
|
|
116
|
-
export function buildNoStereoTautomerHashes(idCodes, result, largestFragmentOnly, from, to) {
|
|
117
|
-
return Search.getNoStereoTautomerHashes(idCodes, result, largestFragmentOnly,
|
|
117
|
+
export function buildNoStereoTautomerHashes(idCodes, result, largestFragmentOnly, from, to, tautomerCounts = new Int32Array(idCodes.length), maxTautomers = DEFAULT_MAX_TAUTOMERS) {
|
|
118
|
+
return recoveringFromTraps((first, last) => Search.getNoStereoTautomerHashes(idCodes, result, tautomerCounts, largestFragmentOnly, maxTautomers, first, last), (index) => {
|
|
119
|
+
result[index] = NO_HASH;
|
|
120
|
+
}, from, to);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Hashes `idCodes[from .. to)` into `result`, one no-stereo hash per molecule.
|
|
124
|
+
*
|
|
125
|
+
* Fails the same way {@link buildNoStereoTautomerHashes} does: `0` for an idcode the WASM side
|
|
126
|
+
* cannot read and for a molecule OpenChemLib cannot canonize.
|
|
127
|
+
* @param idCodes - The molecules to hash.
|
|
128
|
+
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
129
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
130
|
+
* @param from - The first index to hash.
|
|
131
|
+
* @param to - One past the last index to hash.
|
|
132
|
+
* @returns How many molecules were hashed.
|
|
133
|
+
*/
|
|
134
|
+
export function buildNoStereoHashes(idCodes, result, largestFragmentOnly, from, to) {
|
|
135
|
+
return recoveringFromTraps((first, last) => Search.getNoStereoHashes(idCodes, result, largestFragmentOnly, first, last), (index) => {
|
|
136
|
+
result[index] = NO_HASH;
|
|
137
|
+
}, from, to);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Canonizes `idCodes[from .. to)` into `result`, one no-stereo idcode per molecule.
|
|
141
|
+
*
|
|
142
|
+
* This is the string {@link buildNoStereoHashes} hashes, for a caller that stores the canonical form
|
|
143
|
+
* rather than a 64-bit key. A molecule that cannot be read keeps the `NO_ID_CODE` the caller's array
|
|
144
|
+
* was filled with.
|
|
145
|
+
* @param idCodes - The molecules to canonize.
|
|
146
|
+
* @param result - The caller's array, `idCodes.length` entries long, filled with `NO_ID_CODE`.
|
|
147
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
148
|
+
* @param from - The first index to canonize.
|
|
149
|
+
* @param to - One past the last index to canonize.
|
|
150
|
+
* @returns How many molecules were canonized.
|
|
151
|
+
*/
|
|
152
|
+
export function buildNoStereoIdCodes(idCodes, result, largestFragmentOnly, from, to) {
|
|
153
|
+
return recoveringFromTraps((first, last) => Search.getNoStereoIdCodes(idCodes, result, largestFragmentOnly, first, last), (index) => {
|
|
154
|
+
result[index] = NO_ID_CODE;
|
|
155
|
+
}, from, to);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Canonizes `idCodes[from .. to)` into `result`, one no-stereo generic-tautomer idcode per molecule.
|
|
159
|
+
*
|
|
160
|
+
* Fails the same way {@link buildNoStereoIdCodes} does.
|
|
161
|
+
* @param idCodes - The molecules to canonize.
|
|
162
|
+
* @param result - The caller's array, `idCodes.length` entries long, filled with `NO_ID_CODE`.
|
|
163
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
164
|
+
* @param from - The first index to canonize.
|
|
165
|
+
* @param to - One past the last index to canonize.
|
|
166
|
+
* @param tautomerCounts - Filled with how many tautomers each molecule needed; an entry that reached
|
|
167
|
+
* `maxTautomers` is one OpenChemLib stopped early on.
|
|
168
|
+
* @param maxTautomers - The ceiling on that enumeration, which is what bounds the cost.
|
|
169
|
+
* @returns How many molecules were canonized.
|
|
170
|
+
*/
|
|
171
|
+
export function buildNoStereoTautomerIdCodes(idCodes, result, largestFragmentOnly, from, to, tautomerCounts = new Int32Array(idCodes.length), maxTautomers = DEFAULT_MAX_TAUTOMERS) {
|
|
172
|
+
return recoveringFromTraps((first, last) => Search.getNoStereoTautomerIdCodes(idCodes, result, tautomerCounts, largestFragmentOnly, maxTautomers, first, last), (index) => {
|
|
173
|
+
result[index] = NO_ID_CODE;
|
|
174
|
+
}, from, to);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Runs a ranged WASM call, and redoes the range one molecule at a time if it traps.
|
|
178
|
+
*
|
|
179
|
+
* A malformed idcode makes OpenChemLib's bit-stream parser read past its input, which WebAssembly
|
|
180
|
+
* traps on — the same trap {@link scanRange} recovers from. The Java guard catches an empty or
|
|
181
|
+
* non-ASCII idcode, but a malformed ASCII one reaches the parser and traps there, which would
|
|
182
|
+
* otherwise lose every molecule in the range including the good ones. The trap leaves the module
|
|
183
|
+
* usable, and a per-molecule call costs what a batched one does because the 512 key fragments are
|
|
184
|
+
* parsed once for the module's lifetime, so redoing the range singly costs nothing that was not
|
|
185
|
+
* already going to be spent.
|
|
186
|
+
*
|
|
187
|
+
* There is no cap on the failures: these functions promise a per-molecule "could not read this"
|
|
188
|
+
* answer rather than an exception, so an array that is entirely garbage yields one of those per
|
|
189
|
+
* entry.
|
|
190
|
+
* @param call - Runs the WASM call over a range, returning how many molecules it handled.
|
|
191
|
+
* @param markUnreadable - Writes the "could not read this" answer for one molecule.
|
|
192
|
+
* @param from - The first index to handle.
|
|
193
|
+
* @param to - One past the last index to handle.
|
|
194
|
+
* @returns How many molecules were handled.
|
|
195
|
+
*/
|
|
196
|
+
function recoveringFromTraps(call, markUnreadable, from, to) {
|
|
197
|
+
try {
|
|
198
|
+
return call(from, to);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
let handled = 0;
|
|
202
|
+
for (let index = from; index < to; index++) {
|
|
203
|
+
try {
|
|
204
|
+
handled += call(index, index + 1);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
markUnreadable(index);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return handled;
|
|
211
|
+
}
|
|
118
212
|
}
|
|
119
213
|
//# sourceMappingURL=scan.js.map
|
package/lib/scan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../src/scan.ts"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AC,KAAK,CAAC,GAAG,UAAU,CAAC;IAC7B,CAAC,EACD,IAAI,EACJ,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,mBAAmB,CAC1B,IAA0C,EAC1C,cAAuC,EACvC,IAAY,EACZ,EAAU;IAEV,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACH,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACpC,CAAC;YAAC,MAAM,CAAC;gBACP,cAAc,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `openchemlib-js` exposes `CanonizerUtil.getIDCode` but not the hash built from it, so the hash
|
|
3
|
+
* tests hash that idcode here. This is OpenChemLib's `StrongHasher.hash` transcribed, and having it
|
|
4
|
+
* written a second way is what makes those comparisons a real cross-check.
|
|
5
|
+
* @param text - The idcode to hash.
|
|
6
|
+
* @returns Its 64-bit hash, signed, as a `BigInt64Array` entry holds it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function strongHash(text: string): bigint;
|
|
9
|
+
//# sourceMappingURL=strongHash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongHash.d.ts","sourceRoot":"","sources":["../src/strongHash.ts"],"names":[],"mappings":"AAmBA;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAY/C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenChemLib's 64-bit StrongHasher, which is how every `CanonizerUtil` hash is defined: the
|
|
3
|
+
* molecule is reduced to a canonical idcode, and that string is hashed. `openchemlib` exposes the
|
|
4
|
+
* canonical forms but not the hasher, so this is its `CanonizerUtil.StrongHasher` transcribed.
|
|
5
|
+
*
|
|
6
|
+
* It is here so a caller that already holds a canonical idcode — one of this package's, or a column
|
|
7
|
+
* of them in a database — can get its hash without canonizing again. That matters because
|
|
8
|
+
* canonizing a generic tautomer is the most expensive thing this package does, and asking for both
|
|
9
|
+
* the idcode and the hash would otherwise pay for it twice.
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* strongHash(getNoStereoTautomerIdCode(idCode)) === getNoStereoTautomerHash(idCode);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
const MASK_64 = (1n << 64n) - 1n;
|
|
16
|
+
const HSTART = 0xbb40e64da205b064n;
|
|
17
|
+
const HMULT = 7664345821815920749n;
|
|
18
|
+
const BYTE_TABLE = buildByteTable();
|
|
19
|
+
/**
|
|
20
|
+
* `openchemlib-js` exposes `CanonizerUtil.getIDCode` but not the hash built from it, so the hash
|
|
21
|
+
* tests hash that idcode here. This is OpenChemLib's `StrongHasher.hash` transcribed, and having it
|
|
22
|
+
* written a second way is what makes those comparisons a real cross-check.
|
|
23
|
+
* @param text - The idcode to hash.
|
|
24
|
+
* @returns Its 64-bit hash, signed, as a `BigInt64Array` entry holds it.
|
|
25
|
+
*/
|
|
26
|
+
export function strongHash(text) {
|
|
27
|
+
let h = HSTART;
|
|
28
|
+
for (let i = text.length - 1; i >= 0; i--) {
|
|
29
|
+
const character = BigInt(text.codePointAt(i));
|
|
30
|
+
h =
|
|
31
|
+
((h * HMULT) & MASK_64) ^
|
|
32
|
+
BYTE_TABLE[Number(character & 0xffn)];
|
|
33
|
+
h =
|
|
34
|
+
((h * HMULT) & MASK_64) ^
|
|
35
|
+
BYTE_TABLE[Number((character >> 8n) & 0xffn)];
|
|
36
|
+
}
|
|
37
|
+
return BigInt.asIntN(64, h);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* OpenChemLib's `CanonizerUtil.StrongHasher` byte table, built the same way the Java does.
|
|
41
|
+
* @returns The 256 seeds, as unsigned 64-bit values.
|
|
42
|
+
*/
|
|
43
|
+
function buildByteTable() {
|
|
44
|
+
const table = new Array(256);
|
|
45
|
+
let h = 0x544b2fbacaaf1684n;
|
|
46
|
+
for (let i = 0; i < 256; i++) {
|
|
47
|
+
for (let j = 0; j < 31; j++) {
|
|
48
|
+
h = ((h >> 7n) ^ h) & MASK_64;
|
|
49
|
+
h = ((h << 11n) ^ h) & MASK_64;
|
|
50
|
+
h = ((h >> 10n) ^ h) & MASK_64;
|
|
51
|
+
}
|
|
52
|
+
table[i] = h;
|
|
53
|
+
}
|
|
54
|
+
return table;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=strongHash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongHash.js","sourceRoot":"","sources":["../src/strongHash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AACjC,MAAM,MAAM,GAAG,mBAAmB,CAAC;AACnC,MAAM,KAAK,GAAG,oBAAoB,CAAC;AACnC,MAAM,UAAU,GAAG,cAAc,EAAE,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC,GAAG,MAAM,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAW,CAAC,CAAC;QACxD,CAAC;YACC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC;gBACtB,UAAU,CAAC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,CAAY,CAAC;QACpD,CAAC;YACC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC;gBACtB,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAY,CAAC;IAC9D,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACrB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAS,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,mBAAmB,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;YAC9B,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;YAC/B,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;QACjC,CAAC;QACD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -163,13 +163,19 @@ export interface OCLSearch {
|
|
|
163
163
|
/** Returns how many molecules in the range were parsed and fingerprinted. */
|
|
164
164
|
getIndexes: (idCodes: string[], result: Int32Array, from: number, to: number) => number;
|
|
165
165
|
/** Returns how many molecules in the range were hashed. */
|
|
166
|
-
getNoStereoTautomerHashes: (idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number) => number;
|
|
166
|
+
getNoStereoTautomerHashes: (idCodes: string[], result: BigInt64Array, tautomerCounts: Int32Array, largestFragmentOnly: boolean, maxTautomers: number, from: number, to: number) => number;
|
|
167
|
+
/** Returns how many molecules in the range were hashed. */
|
|
168
|
+
getNoStereoHashes: (idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number) => number;
|
|
169
|
+
/** Returns how many molecules in the range were canonized. */
|
|
170
|
+
getNoStereoIdCodes: (idCodes: string[], result: string[], largestFragmentOnly: boolean, from: number, to: number) => number;
|
|
171
|
+
/** Returns how many molecules in the range were canonized. */
|
|
172
|
+
getNoStereoTautomerIdCodes: (idCodes: string[], result: string[], tautomerCounts: Int32Array, largestFragmentOnly: boolean, maxTautomers: number, from: number, to: number) => number;
|
|
167
173
|
};
|
|
168
174
|
}
|
|
169
175
|
/** How many 32-bit words one molecule's FragFp fingerprint occupies. */
|
|
170
176
|
export declare const INDEX_WORDS = 16;
|
|
171
|
-
/** What
|
|
172
|
-
export interface
|
|
177
|
+
/** What every hash function takes. */
|
|
178
|
+
export interface HashOptions {
|
|
173
179
|
/**
|
|
174
180
|
* Whether to reduce the molecule to its largest fragment and neutralize it before hashing, so a
|
|
175
181
|
* salt hashes as its parent structure and a hydrochloride as its free base. Off by default, which
|
|
@@ -177,11 +183,45 @@ export interface TautomerHashOptions {
|
|
|
177
183
|
* @default false
|
|
178
184
|
*/
|
|
179
185
|
largestFragmentOnly?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* The ceiling on how many tautomers OpenChemLib enumerates before it settles for what it has.
|
|
188
|
+
* Only the tautomer functions read it.
|
|
189
|
+
*
|
|
190
|
+
* The cost of a tautomer key is set by this, not by the molecule's size: the median molecule needs
|
|
191
|
+
* a hundred microseconds and one in a hundred runs into the ceiling and spends the better part of
|
|
192
|
+
* a second getting there. Lowering it bounds that tail, at the price of a key that may not be
|
|
193
|
+
* canonical for the molecules that hit it — compare `tautomerCounts` against this value to find
|
|
194
|
+
* them.
|
|
195
|
+
* @default 100000 — OpenChemLib's own
|
|
196
|
+
*/
|
|
197
|
+
maxTautomers?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Filled with how many tautomers were enumerated for each molecule, if given. An entry that
|
|
200
|
+
* reached {@link HashOptions.maxTautomers} is one OpenChemLib stopped early on, which is the only
|
|
201
|
+
* signal that a key may not be canonical.
|
|
202
|
+
*
|
|
203
|
+
* It is the caller's buffer, `idCodes.length` entries long, so a table of flags costs one
|
|
204
|
+
* allocation. Only the tautomer functions write it.
|
|
205
|
+
*/
|
|
206
|
+
tautomerCounts?: Int32Array;
|
|
180
207
|
}
|
|
208
|
+
/** {@link HashOptions} under the name the tautomer hashes introduced it with. */
|
|
209
|
+
export type TautomerHashOptions = HashOptions;
|
|
181
210
|
/**
|
|
182
211
|
* The hash of a molecule that has none: its idcode could not be parsed, or OpenChemLib could not
|
|
183
212
|
* canonize it. A real hash collides with it once in 2^64, so an equality test against it is a
|
|
184
213
|
* usable "no hash" check.
|
|
185
214
|
*/
|
|
186
215
|
export declare const NO_HASH = 0n;
|
|
216
|
+
/**
|
|
217
|
+
* The canonical idcode of a molecule that has none: its idcode could not be parsed, or OpenChemLib
|
|
218
|
+
* could not canonize it. The empty string is never a valid idcode, so an equality test against it is
|
|
219
|
+
* the idcode counterpart of {@link NO_HASH}.
|
|
220
|
+
*/
|
|
221
|
+
export declare const NO_ID_CODE = "";
|
|
222
|
+
/**
|
|
223
|
+
* How many tautomers OpenChemLib enumerates before it settles for what it has, unless
|
|
224
|
+
* {@link HashOptions.maxTautomers} says otherwise. It is OpenChemLib's own ceiling.
|
|
225
|
+
*/
|
|
226
|
+
export declare const DEFAULT_MAX_TAUTOMERS = 100000;
|
|
187
227
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|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BAAmB,EAAE,OAAO,EAC5B,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,KACP,MAAM,CAAC;KACb,CAAC;CACH;AAED,wEAAwE;AACxE,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,sCAAsC;AACtC,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;;;;;;OAUG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,UAAU,CAAC;CAC7B;AAED,iFAAiF;AACjF,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,OAAO,KAAK,CAAC;AAE1B;;;;GAIG;AACH,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,qBAAqB,SAAU,CAAC"}
|
package/lib/types.js
CHANGED
|
@@ -33,4 +33,15 @@ export const INDEX_WORDS = 16;
|
|
|
33
33
|
* usable "no hash" check.
|
|
34
34
|
*/
|
|
35
35
|
export const NO_HASH = 0n;
|
|
36
|
+
/**
|
|
37
|
+
* The canonical idcode of a molecule that has none: its idcode could not be parsed, or OpenChemLib
|
|
38
|
+
* could not canonize it. The empty string is never a valid idcode, so an equality test against it is
|
|
39
|
+
* the idcode counterpart of {@link NO_HASH}.
|
|
40
|
+
*/
|
|
41
|
+
export const NO_ID_CODE = '';
|
|
42
|
+
/**
|
|
43
|
+
* How many tautomers OpenChemLib enumerates before it settles for what it has, unless
|
|
44
|
+
* {@link HashOptions.maxTautomers} says otherwise. It is OpenChemLib's own ceiling.
|
|
45
|
+
*/
|
|
46
|
+
export const DEFAULT_MAX_TAUTOMERS = 100_000;
|
|
36
47
|
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,sBAAsB;IACtB,WAAW,EAAE,CAAC;IACd,oDAAoD;IACpD,KAAK,EAAE,CAAC;IACR,wDAAwD;IACxD,OAAO,EAAE,CAAC;IACV,0DAA0D;IAC1D,UAAU,EAAE,CAAC;CACd,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC,GAAG;IACvB,4DAA4D;IAC5D,UAAU,EAAE,CAAC,CAAC;CACf,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,sBAAsB;IACtB,WAAW,EAAE,CAAC;IACd,oDAAoD;IACpD,KAAK,EAAE,CAAC;IACR,wDAAwD;IACxD,OAAO,EAAE,CAAC;IACV,0DAA0D;IAC1D,UAAU,EAAE,CAAC;CACd,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC,GAAG;IACvB,4DAA4D;IAC5D,UAAU,EAAE,CAAC,CAAC;CACf,CAAC,CAAC;AA4MH,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAuC9B;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC"}
|
package/lib/wasm/load.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/wasm/load.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/wasm/load.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAe7C;;;;;;GAMG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,CAG5C"}
|
package/lib/wasm/load.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { wasmGzipBase64 } from '../../wasm/data.js';
|
|
2
2
|
import { load } from '../../wasm/runtime.js';
|
|
3
|
+
import { createConsoleImport } from "./log.js";
|
|
3
4
|
let modulePromise;
|
|
4
5
|
/**
|
|
5
6
|
* The ceiling on the module's linear memory. The runtime otherwise declares the largest maximum it
|
|
@@ -22,7 +23,14 @@ export function loadOCL() {
|
|
|
22
23
|
}
|
|
23
24
|
async function instantiate() {
|
|
24
25
|
const wasmBytes = await gunzip(base64ToBytes(wasmGzipBase64));
|
|
25
|
-
const teavm = await load(wasmBytes, {
|
|
26
|
+
const teavm = await load(wasmBytes, {
|
|
27
|
+
memory: { maxSize: MAX_LINEAR_MEMORY },
|
|
28
|
+
// The runtime's own `teavmConsole` puts Java's System.out on `console.log`, so OpenChemLib's
|
|
29
|
+
// "Tautomer count exceeds maximum" lands on the host's stdout — see src/wasm/log.ts.
|
|
30
|
+
installImports(imports) {
|
|
31
|
+
imports.teavmConsole = createConsoleImport();
|
|
32
|
+
},
|
|
33
|
+
});
|
|
26
34
|
return teavm.exports;
|
|
27
35
|
}
|
|
28
36
|
function base64ToBytes(base64) {
|
package/lib/wasm/load.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/wasm/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,IAAI,aAA6C,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO;IACrB,aAAa,KAAK,WAAW,EAAE,CAAC;IAChC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,WAAW;IACxB,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/wasm/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,IAAI,aAA6C,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO;IACrB,aAAa,KAAK,WAAW,EAAE,CAAC;IAChC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,WAAW;IACxB,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE;QAClC,MAAM,EAAE,EAAE,OAAO,EAAE,iBAAiB,EAAE;QACtC,6FAA6F;QAC7F,qFAAqF;QACrF,cAAc,CAAC,OAAO;YACpB,OAAO,CAAC,YAAY,GAAG,mBAAmB,EAAE,CAAC;QAC/C,CAAC;KACF,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,OAA+B,CAAC;AAC/C,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,KAAK,UAAU,MAAM,CACnB,KAA8B;IAE9B,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;SAC7B,MAAM,EAAE;SACR,WAAW,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Which of Java's two standard streams a line came from. */
|
|
2
|
+
export type LogStream = 'stdout' | 'stderr';
|
|
3
|
+
/** Called with one line OpenChemLib wrote to a standard stream. */
|
|
4
|
+
export type LogHandler = (message: string, stream: LogStream) => void;
|
|
5
|
+
/** TeaVM imports one character sink per stream; it writes a character at a time. */
|
|
6
|
+
interface TeaVMConsole {
|
|
7
|
+
putcharStdout: (code: number) => void;
|
|
8
|
+
putcharStderr: (code: number) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Routes what OpenChemLib writes to Java's standard streams wherever you want it.
|
|
12
|
+
*
|
|
13
|
+
* Nothing is written anywhere by default, and that is the point: OpenChemLib prints
|
|
14
|
+
* `Tautomer count exceeds maximum: <idcode>` for every molecule whose tautomers it stops
|
|
15
|
+
* enumerating, which an import emits thousands of times, and the generated TeaVM runtime maps that
|
|
16
|
+
* onto `console.log` — the same stream a host writing structured logs is using, whose output it
|
|
17
|
+
* then corrupts. The message says nothing a caller can act on; the hash is still returned and still
|
|
18
|
+
* identifies the molecule. So the default is to drop it, and a host that wants it says where.
|
|
19
|
+
*
|
|
20
|
+
* It applies whether or not the module has been instantiated yet, so it can be set at startup or
|
|
21
|
+
* around one call.
|
|
22
|
+
*
|
|
23
|
+
* ```js
|
|
24
|
+
* setLogHandler((message, stream) => logger.debug({ stream }, message));
|
|
25
|
+
* ```
|
|
26
|
+
* @param next - Called once per line, or `null` to go back to discarding them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function setLogHandler(next: LogHandler | null): void;
|
|
29
|
+
/**
|
|
30
|
+
* Builds the `teavmConsole` import that replaces the generated runtime's own, which calls
|
|
31
|
+
* `console.log` and `console.error`.
|
|
32
|
+
* @returns The import object to install over it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createConsoleImport(): TeaVMConsole;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/wasm/log.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5C,mEAAmE;AACnE,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;AAEtE,oFAAoF;AACpF,UAAU,YAAY;IACpB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAKlD"}
|
package/lib/wasm/log.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const NEWLINE = 10;
|
|
2
|
+
let handler = null;
|
|
3
|
+
/**
|
|
4
|
+
* Routes what OpenChemLib writes to Java's standard streams wherever you want it.
|
|
5
|
+
*
|
|
6
|
+
* Nothing is written anywhere by default, and that is the point: OpenChemLib prints
|
|
7
|
+
* `Tautomer count exceeds maximum: <idcode>` for every molecule whose tautomers it stops
|
|
8
|
+
* enumerating, which an import emits thousands of times, and the generated TeaVM runtime maps that
|
|
9
|
+
* onto `console.log` — the same stream a host writing structured logs is using, whose output it
|
|
10
|
+
* then corrupts. The message says nothing a caller can act on; the hash is still returned and still
|
|
11
|
+
* identifies the molecule. So the default is to drop it, and a host that wants it says where.
|
|
12
|
+
*
|
|
13
|
+
* It applies whether or not the module has been instantiated yet, so it can be set at startup or
|
|
14
|
+
* around one call.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* setLogHandler((message, stream) => logger.debug({ stream }, message));
|
|
18
|
+
* ```
|
|
19
|
+
* @param next - Called once per line, or `null` to go back to discarding them.
|
|
20
|
+
*/
|
|
21
|
+
export function setLogHandler(next) {
|
|
22
|
+
handler = next;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds the `teavmConsole` import that replaces the generated runtime's own, which calls
|
|
26
|
+
* `console.log` and `console.error`.
|
|
27
|
+
* @returns The import object to install over it.
|
|
28
|
+
*/
|
|
29
|
+
export function createConsoleImport() {
|
|
30
|
+
return {
|
|
31
|
+
putcharStdout: lineSink('stdout'),
|
|
32
|
+
putcharStderr: lineSink('stderr'),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Collects characters into a line and hands each finished one to the current handler.
|
|
37
|
+
* @param stream - The stream these characters belong to.
|
|
38
|
+
* @returns The per-character callback the runtime imports.
|
|
39
|
+
*/
|
|
40
|
+
function lineSink(stream) {
|
|
41
|
+
let line = '';
|
|
42
|
+
return (code) => {
|
|
43
|
+
if (code === NEWLINE) {
|
|
44
|
+
handler?.(line, stream);
|
|
45
|
+
line = '';
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
line += String.fromCodePoint(code);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/wasm/log.ts"],"names":[],"mappings":"AAYA,MAAM,OAAO,GAAG,EAAE,CAAC;AAEnB,IAAI,OAAO,GAAsB,IAAI,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,aAAa,EAAE,QAAQ,CAAC,QAAQ,CAAC;QACjC,aAAa,EAAE,QAAQ,CAAC,QAAQ,CAAC;KAClC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,MAAiB;IACjC,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,IAAY,EAAE,EAAE;QACtB,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACxB,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|