openchemlib-search-wasm 1.2.0 → 2.1.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 +290 -3
- package/lib/functionKeys/dictionary.json +72071 -0
- package/lib/functionKeys/index.d.ts +105 -0
- package/lib/functionKeys/index.d.ts.map +1 -0
- package/lib/functionKeys/index.js +98 -0
- package/lib/functionKeys/index.js.map +1 -0
- package/lib/functions.d.ts +38 -0
- package/lib/functions.d.ts.map +1 -0
- package/lib/functions.js +54 -0
- package/lib/functions.js.map +1 -0
- 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 +140 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +184 -7
- package/lib/index.js.map +1 -1
- package/lib/records.d.ts +45 -0
- package/lib/records.d.ts.map +1 -0
- package/lib/records.js +96 -0
- package/lib/records.js.map +1 -0
- package/lib/scan.d.ts +99 -7
- package/lib/scan.d.ts.map +1 -1
- package/lib/scan.js +158 -11
- 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/substructureSearch.d.ts +8 -5
- package/lib/substructureSearch.d.ts.map +1 -1
- package/lib/substructureSearch.js +28 -5
- package/lib/substructureSearch.js.map +1 -1
- package/lib/types.d.ts +120 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +17 -1
- 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 +6 -3
- package/src/functionKeys/index.ts +181 -0
- package/src/functions.ts +56 -0
- package/src/hex.ts +43 -0
- package/src/index.ts +269 -5
- package/src/records.ts +142 -0
- package/src/scan.ts +259 -16
- package/src/strongHash.ts +57 -0
- package/src/substructureSearch.ts +29 -6
- package/src/types.ts +171 -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
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { buildIndexes, buildNoStereoHashes, buildNoStereoTautomerHashes, } from "./scan.js";
|
|
2
|
-
import { INDEX_WORDS } from "./types.js";
|
|
1
|
+
import { buildIndexes, buildNoStereoHashes, buildNoStereoIdCodes, buildNoStereoTautomerHashes, buildNoStereoTautomerIdCodes, buildQueryWords, buildScreens, readKeys, } from "./scan.js";
|
|
2
|
+
import { DEFAULT_MAX_TAUTOMERS, INDEX_WORDS, NO_ID_CODE } from "./types.js";
|
|
3
3
|
export { substructureSearch } from "./substructureSearch.js";
|
|
4
|
+
export { setLogHandler } from "./wasm/log.js";
|
|
5
|
+
export { hashToHex, hexToHash } from "./hex.js";
|
|
6
|
+
export { strongHash } from "./strongHash.js";
|
|
4
7
|
export { similaritySearch } from "./similaritySearch.js";
|
|
5
|
-
export {
|
|
8
|
+
export { getMoleculeRecords, getMoleculeSizes, getQueryAtomFloor, } from "./records.js";
|
|
9
|
+
export { getFunction, getFunctionKeyFragments, getFunctions, } from "./functions.js";
|
|
10
|
+
export { DEFAULT_MAX_TAUTOMERS, INDEX_WORDS, NO_HASH, NO_ID_CODE, RECORD_WORDS, } from "./types.js";
|
|
6
11
|
export { SimilarityResult, SubstructureResult } from "./types.js";
|
|
7
12
|
/**
|
|
8
13
|
* Builds the 512-bit FragFp fingerprint of one idcode, as sixteen 32-bit words.
|
|
@@ -52,6 +57,105 @@ export function getIndexes(idCodes) {
|
|
|
52
57
|
}
|
|
53
58
|
return indexes;
|
|
54
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Builds the 512-bit screen of one idcode, as sixteen 32-bit words: bit i is set when key i of the
|
|
62
|
+
* screen dictionary is a substructure of the molecule.
|
|
63
|
+
*
|
|
64
|
+
* The screen sits next to the FragFp fingerprint of {@link getIndex}. A molecule is a candidate for
|
|
65
|
+
* a query only if it holds every bit of {@link getQueryIndex} in its fingerprint and every bit of
|
|
66
|
+
* {@link getQueryScreen} in its screen; requiring both lets through about a sixth of the
|
|
67
|
+
* non-matching molecules FragFp alone lets through. The dictionary is 512 OpenChemLib query
|
|
68
|
+
* fragments, matched the way FragFp matches its own keys, and a screen costs about 0.7 times a
|
|
69
|
+
* fingerprint.
|
|
70
|
+
*
|
|
71
|
+
* ```js
|
|
72
|
+
* const isCandidate = (query, molecule) =>
|
|
73
|
+
* query.every((word, i) => (word & molecule[i]) === word);
|
|
74
|
+
* isCandidate(getQueryScreen(query), getScreen(idCode));
|
|
75
|
+
* ```
|
|
76
|
+
* @param idCode - The molecule to screen, as an idcode.
|
|
77
|
+
* @returns Sixteen words. An idcode that will not parse gives sixteen zeros, which no non-empty
|
|
78
|
+
* query screen is a subset of.
|
|
79
|
+
*/
|
|
80
|
+
export function getScreen(idCode) {
|
|
81
|
+
const result = new Int32Array(INDEX_WORDS);
|
|
82
|
+
buildScreens([idCode], result, 0, 1);
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Builds the 512-bit screen of every idcode, sixteen 32-bit words each.
|
|
87
|
+
*
|
|
88
|
+
* See {@link getScreen}. The screens are written into one buffer and returned as a view per
|
|
89
|
+
* molecule, each 8-byte aligned, as {@link getIndexes} does.
|
|
90
|
+
* @param idCodes - The molecules to screen, as idcodes.
|
|
91
|
+
* @returns One sixteen-word view per idcode, in order.
|
|
92
|
+
*/
|
|
93
|
+
export function getScreens(idCodes) {
|
|
94
|
+
const all = new Int32Array(idCodes.length * INDEX_WORDS);
|
|
95
|
+
buildScreens(idCodes, all, 0, idCodes.length);
|
|
96
|
+
const screens = new Array(idCodes.length);
|
|
97
|
+
for (let i = 0; i < idCodes.length; i++) {
|
|
98
|
+
screens[i] = all.subarray(i * INDEX_WORDS, (i + 1) * INDEX_WORDS);
|
|
99
|
+
}
|
|
100
|
+
return screens;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Builds the screen of a query: the bits every molecule the query matches has in its
|
|
104
|
+
* {@link getScreen} screen.
|
|
105
|
+
*
|
|
106
|
+
* The query is screened on the fragment OpenChemLib's substructure search actually matches, so an
|
|
107
|
+
* exclude group cutting an aromatic ring and the atom ring sizes of the query are taken into account
|
|
108
|
+
* as the search takes them; a query with a "match formal bond order" bond gets no bits.
|
|
109
|
+
* @param idCodeQuery - The query, as an idcode; read as a fragment whatever its own fragment flag.
|
|
110
|
+
* @returns Sixteen words.
|
|
111
|
+
* @throws {Error} If the query cannot be parsed.
|
|
112
|
+
*/
|
|
113
|
+
export function getQueryScreen(idCodeQuery) {
|
|
114
|
+
return buildQueryWords('screen', idCodeQuery);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Builds the FragFp fingerprint of a query: the bits every molecule the query matches has in its
|
|
118
|
+
* {@link getIndex} fingerprint.
|
|
119
|
+
*
|
|
120
|
+
* It equals OpenChemLib's own query fingerprint, except for the queries that one wrongly rejects
|
|
121
|
+
* true matches of: an exclude group cutting an aromatic ring, or a "match formal bond order" bond
|
|
122
|
+
* (Actelion/openchemlib#177). The first is fingerprinted on the fragment the search matches; the
|
|
123
|
+
* second gets no bits.
|
|
124
|
+
* @param idCodeQuery - The query, as an idcode; read as a fragment whatever its own fragment flag.
|
|
125
|
+
* @returns Sixteen words.
|
|
126
|
+
* @throws {Error} If the query cannot be parsed.
|
|
127
|
+
*/
|
|
128
|
+
export function getQueryIndex(idCodeQuery) {
|
|
129
|
+
return buildQueryWords('index', idCodeQuery);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns the 512 key fragments of FragFp, in bit order: bit i of {@link getIndex} is set when key i
|
|
133
|
+
* is a substructure of the molecule. They are OpenChemLib's own keys, the list `openchemlib`'s
|
|
134
|
+
* `SSSearcherWithIndex.getKeyIDCode()` returns.
|
|
135
|
+
*
|
|
136
|
+
* Bit i sits in word `i >> 5`, the first key in the highest bit of word 0:
|
|
137
|
+
*
|
|
138
|
+
* ```js
|
|
139
|
+
* const keys = getFragFpKeys();
|
|
140
|
+
* const index = getIndex(idCode);
|
|
141
|
+
* const held = keys.filter((key, i) => index[i >> 5] & (1 << (31 - (i & 31))));
|
|
142
|
+
* ```
|
|
143
|
+
* @returns 512 idcodes, each a query fragment, in bit order. The array is the caller's own.
|
|
144
|
+
*/
|
|
145
|
+
export function getFragFpKeys() {
|
|
146
|
+
return readKeys('index');
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns the 512 key fragments of the screen, in bit order: bit i of {@link getScreen} is set when
|
|
150
|
+
* key i is a substructure of the molecule. The words are laid out as {@link getFragFpKeys} shows.
|
|
151
|
+
*
|
|
152
|
+
* The list is frozen: changing, adding or reordering a key changes every stored screen, so it only
|
|
153
|
+
* changes in a major release.
|
|
154
|
+
* @returns 512 idcodes, each a query fragment, in bit order. The array is the caller's own.
|
|
155
|
+
*/
|
|
156
|
+
export function getScreenKeys() {
|
|
157
|
+
return readKeys('screen');
|
|
158
|
+
}
|
|
55
159
|
/**
|
|
56
160
|
* Hashes one idcode to the 64-bit value OpenChemLib identifies a molecule by up to tautomerism and
|
|
57
161
|
* stereochemistry.
|
|
@@ -74,9 +178,9 @@ export function getIndexes(idCodes) {
|
|
|
74
178
|
* OpenChemLib cannot canonize.
|
|
75
179
|
*/
|
|
76
180
|
export function getNoStereoTautomerHash(idCode, options = {}) {
|
|
77
|
-
const { largestFragmentOnly = false } = options;
|
|
181
|
+
const { largestFragmentOnly = false, tautomerCounts, maxTautomers = DEFAULT_MAX_TAUTOMERS, } = options;
|
|
78
182
|
const result = new BigInt64Array(1);
|
|
79
|
-
buildNoStereoTautomerHashes([idCode], result, largestFragmentOnly, 0, 1);
|
|
183
|
+
buildNoStereoTautomerHashes([idCode], result, largestFragmentOnly, 0, 1, tautomerCounts, maxTautomers);
|
|
80
184
|
return result[0];
|
|
81
185
|
}
|
|
82
186
|
/**
|
|
@@ -97,9 +201,9 @@ export function getNoStereoTautomerHash(idCode, options = {}) {
|
|
|
97
201
|
* hashed.
|
|
98
202
|
*/
|
|
99
203
|
export function getNoStereoTautomerHashes(idCodes, options = {}) {
|
|
100
|
-
const { largestFragmentOnly = false } = options;
|
|
204
|
+
const { largestFragmentOnly = false, tautomerCounts, maxTautomers = DEFAULT_MAX_TAUTOMERS, } = options;
|
|
101
205
|
const result = new BigInt64Array(idCodes.length);
|
|
102
|
-
buildNoStereoTautomerHashes(idCodes, result, largestFragmentOnly, 0, idCodes.length);
|
|
206
|
+
buildNoStereoTautomerHashes(idCodes, result, largestFragmentOnly, 0, idCodes.length, tautomerCounts, maxTautomers);
|
|
103
207
|
return result;
|
|
104
208
|
}
|
|
105
209
|
/**
|
|
@@ -149,4 +253,77 @@ export function getNoStereoHashes(idCodes, options = {}) {
|
|
|
149
253
|
buildNoStereoHashes(idCodes, result, largestFragmentOnly, 0, idCodes.length);
|
|
150
254
|
return result;
|
|
151
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Canonizes one idcode to the form OpenChemLib identifies a molecule by up to stereochemistry.
|
|
258
|
+
*
|
|
259
|
+
* This is the string {@link getNoStereoHash} hashes, for a database that stores the canonical form
|
|
260
|
+
* itself. Prefer the hash where the column is only ever compared: it is a signed 64-bit integer, so
|
|
261
|
+
* it stores and indexes in 8 bytes where these idcodes average around 25 characters.
|
|
262
|
+
*
|
|
263
|
+
* ```js
|
|
264
|
+
* getNoStereoIdCode(idCode); // 'gGX`BDdwMT@@'
|
|
265
|
+
* ```
|
|
266
|
+
* @param idCode - The molecule to canonize, as an idcode.
|
|
267
|
+
* @param options - See {@link HashOptions}.
|
|
268
|
+
* @returns Its canonical no-stereo idcode, or `NO_ID_CODE` (`''`) for an idcode that will not parse
|
|
269
|
+
* or a molecule OpenChemLib cannot canonize.
|
|
270
|
+
*/
|
|
271
|
+
export function getNoStereoIdCode(idCode, options = {}) {
|
|
272
|
+
const { largestFragmentOnly = false } = options;
|
|
273
|
+
const result = [NO_ID_CODE];
|
|
274
|
+
buildNoStereoIdCodes([idCode], result, largestFragmentOnly, 0, 1);
|
|
275
|
+
return result[0];
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Canonizes every idcode to the form OpenChemLib identifies a molecule by up to stereochemistry.
|
|
279
|
+
*
|
|
280
|
+
* See {@link getNoStereoIdCode} for what the form identifies.
|
|
281
|
+
* @param idCodes - The molecules to canonize, as idcodes.
|
|
282
|
+
* @param options - See {@link HashOptions}.
|
|
283
|
+
* @returns One idcode per input, in order, with `NO_ID_CODE` (`''`) for each one that could not be
|
|
284
|
+
* canonized.
|
|
285
|
+
*/
|
|
286
|
+
export function getNoStereoIdCodes(idCodes, options = {}) {
|
|
287
|
+
const { largestFragmentOnly = false } = options;
|
|
288
|
+
const result = new Array(idCodes.length).fill(NO_ID_CODE);
|
|
289
|
+
buildNoStereoIdCodes(idCodes, result, largestFragmentOnly, 0, idCodes.length);
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Canonizes one idcode to the form OpenChemLib identifies a molecule by up to tautomerism and
|
|
294
|
+
* stereochemistry.
|
|
295
|
+
*
|
|
296
|
+
* This is the string {@link getNoStereoTautomerHash} hashes. It is the generic tautomer's idcode, so
|
|
297
|
+
* it is longer than the molecule's own — around twice it for a molecule with tautomeric sites — and
|
|
298
|
+
* it is not a structure: parsing it back gives a molecule with every tautomeric bond normalized, not
|
|
299
|
+
* the compound. Use it as a key, never as something to draw.
|
|
300
|
+
* @param idCode - The molecule to canonize, as an idcode.
|
|
301
|
+
* @param options - See {@link HashOptions}.
|
|
302
|
+
* @returns Its canonical no-stereo generic-tautomer idcode, or `NO_ID_CODE` (`''`) for an idcode that
|
|
303
|
+
* will not parse or a molecule OpenChemLib cannot canonize.
|
|
304
|
+
*/
|
|
305
|
+
export function getNoStereoTautomerIdCode(idCode, options = {}) {
|
|
306
|
+
const { largestFragmentOnly = false, tautomerCounts, maxTautomers = DEFAULT_MAX_TAUTOMERS, } = options;
|
|
307
|
+
const result = [NO_ID_CODE];
|
|
308
|
+
buildNoStereoTautomerIdCodes([idCode], result, largestFragmentOnly, 0, 1, tautomerCounts, maxTautomers);
|
|
309
|
+
return result[0];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Canonizes every idcode to the form OpenChemLib identifies a molecule by up to tautomerism and
|
|
313
|
+
* stereochemistry.
|
|
314
|
+
*
|
|
315
|
+
* See {@link getNoStereoTautomerIdCode} for what the form identifies, and
|
|
316
|
+
* {@link getNoStereoTautomerHashes} for what it costs — the canonization is the expensive part, not
|
|
317
|
+
* the hashing, so these cost what those do.
|
|
318
|
+
* @param idCodes - The molecules to canonize, as idcodes.
|
|
319
|
+
* @param options - See {@link HashOptions}.
|
|
320
|
+
* @returns One idcode per input, in order, with `NO_ID_CODE` (`''`) for each one that could not be
|
|
321
|
+
* canonized.
|
|
322
|
+
*/
|
|
323
|
+
export function getNoStereoTautomerIdCodes(idCodes, options = {}) {
|
|
324
|
+
const { largestFragmentOnly = false, tautomerCounts, maxTautomers = DEFAULT_MAX_TAUTOMERS, } = options;
|
|
325
|
+
const result = new Array(idCodes.length).fill(NO_ID_CODE);
|
|
326
|
+
buildNoStereoTautomerIdCodes(idCodes, result, largestFragmentOnly, 0, idCodes.length, tautomerCounts, maxTautomers);
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
152
329
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,2BAA2B,
|
|
1
|
+
{"version":3,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
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MoleculeRecords, MoleculeRecordsOptions, MoleculeSizes } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Computes everything a molecule table stores about each idcode, parsing each one once: the
|
|
4
|
+
* canonical idcode, the FragFp, the screen and the function bits, the atom count and the relative
|
|
5
|
+
* weight, and the no-stereo and tautomer hashes.
|
|
6
|
+
*
|
|
7
|
+
* Each value is the one the dedicated function returns — `getIndexes`, `getScreens`, `getFunctions`,
|
|
8
|
+
* `getNoStereoHashes`, `getNoStereoTautomerHashes` — with one deliberate exception: a molecule
|
|
9
|
+
* whose tautomer enumeration reached `maxTautomers` gets its no-stereo hash as its tautomer hash,
|
|
10
|
+
* because a key from a truncated enumeration depends on where it stopped and is not canonical.
|
|
11
|
+
* `tautomerCounts` says which molecules those are.
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* const records = getMoleculeRecords(idCodes, { maxTautomers: 5000 });
|
|
15
|
+
* const words = records.words.subarray(48 * i, 48 * (i + 1)); // FragFp, screen, functions
|
|
16
|
+
* ```
|
|
17
|
+
* @param idCodes - The molecules to read, as idcodes.
|
|
18
|
+
* @param options - See {@link MoleculeRecordsOptions}.
|
|
19
|
+
* @returns One entry per idcode in each array, in input order. A molecule that cannot be read gets
|
|
20
|
+
* `NO_ID_CODE`, zeros, 0 atoms, a `NaN` weight, `NO_HASH` and a tautomer count of 0, and does not
|
|
21
|
+
* cost the others in the batch.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getMoleculeRecords(idCodes: string[], options?: MoleculeRecordsOptions): MoleculeRecords;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the atom count and the relative weight of each idcode — exactly the `atomCounts` and
|
|
26
|
+
* `weights` of {@link getMoleculeRecords}, and nothing else, so it costs one parse and one formula
|
|
27
|
+
* per molecule.
|
|
28
|
+
* @param idCodes - The molecules to read, as idcodes.
|
|
29
|
+
* @returns One entry per idcode in each array, in input order: 0 atoms and a `NaN` weight for a
|
|
30
|
+
* molecule that cannot be read.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getMoleculeSizes(idCodes: string[]): MoleculeSizes;
|
|
33
|
+
/**
|
|
34
|
+
* The fewest atoms a molecule needs to contain the query: its atoms once the exclude groups are
|
|
35
|
+
* removed, plain hydrogens aside. Each of them maps onto a distinct atom of any match, so a molecule
|
|
36
|
+
* whose atom count is below the floor cannot match and needs no substructure test.
|
|
37
|
+
*
|
|
38
|
+
* Wildcards and atom lists count — each still takes an atom of the match. A plain hydrogen does not,
|
|
39
|
+
* because it may match an implicit one; a deuterium or a tritium does.
|
|
40
|
+
* @param idCodeQuery - The query, as an idcode; read as a fragment whatever its own fragment flag.
|
|
41
|
+
* @returns The floor, or 0 for a query with no atoms.
|
|
42
|
+
* @throws {Error} If the query cannot be parsed.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getQueryAtomFloor(idCodeQuery: string): number;
|
|
45
|
+
//# sourceMappingURL=records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,aAAa,EACd,MAAM,YAAY,CAAC;AAWpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,GAAE,sBAA2B,GACnC,eAAe,CAgCjB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,aAAa,CAuBjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQ7D"}
|
package/lib/records.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { recoveringFromTraps } from "./scan.js";
|
|
2
|
+
import { DEFAULT_MAX_TAUTOMERS, NO_HASH, NO_ID_CODE, RECORD_WORDS, } from "./types.js";
|
|
3
|
+
import { loadOCL } from "./wasm/load.js";
|
|
4
|
+
const { Search } = await loadOCL();
|
|
5
|
+
/**
|
|
6
|
+
* Computes everything a molecule table stores about each idcode, parsing each one once: the
|
|
7
|
+
* canonical idcode, the FragFp, the screen and the function bits, the atom count and the relative
|
|
8
|
+
* weight, and the no-stereo and tautomer hashes.
|
|
9
|
+
*
|
|
10
|
+
* Each value is the one the dedicated function returns — `getIndexes`, `getScreens`, `getFunctions`,
|
|
11
|
+
* `getNoStereoHashes`, `getNoStereoTautomerHashes` — with one deliberate exception: a molecule
|
|
12
|
+
* whose tautomer enumeration reached `maxTautomers` gets its no-stereo hash as its tautomer hash,
|
|
13
|
+
* because a key from a truncated enumeration depends on where it stopped and is not canonical.
|
|
14
|
+
* `tautomerCounts` says which molecules those are.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* const records = getMoleculeRecords(idCodes, { maxTautomers: 5000 });
|
|
18
|
+
* const words = records.words.subarray(48 * i, 48 * (i + 1)); // FragFp, screen, functions
|
|
19
|
+
* ```
|
|
20
|
+
* @param idCodes - The molecules to read, as idcodes.
|
|
21
|
+
* @param options - See {@link MoleculeRecordsOptions}.
|
|
22
|
+
* @returns One entry per idcode in each array, in input order. A molecule that cannot be read gets
|
|
23
|
+
* `NO_ID_CODE`, zeros, 0 atoms, a `NaN` weight, `NO_HASH` and a tautomer count of 0, and does not
|
|
24
|
+
* cost the others in the batch.
|
|
25
|
+
*/
|
|
26
|
+
export function getMoleculeRecords(idCodes, options = {}) {
|
|
27
|
+
const { maxTautomers = DEFAULT_MAX_TAUTOMERS } = options;
|
|
28
|
+
const count = idCodes.length;
|
|
29
|
+
const records = {
|
|
30
|
+
idCodes: new Array(count).fill(NO_ID_CODE),
|
|
31
|
+
words: new Int32Array(count * RECORD_WORDS),
|
|
32
|
+
atomCounts: new Int32Array(count),
|
|
33
|
+
weights: new Float64Array(count).fill(Number.NaN),
|
|
34
|
+
noStereoHashes: new BigInt64Array(count),
|
|
35
|
+
tautomerHashes: new BigInt64Array(count),
|
|
36
|
+
tautomerCounts: new Int32Array(count),
|
|
37
|
+
};
|
|
38
|
+
recoveringFromTraps((from, to) => Search.getMoleculeRecords(idCodes, records.idCodes, records.words, records.atomCounts, records.weights, records.noStereoHashes, records.tautomerHashes, records.tautomerCounts, maxTautomers, from, to), (index) => markUnreadable(records, index), 0, count);
|
|
39
|
+
return records;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Reads the atom count and the relative weight of each idcode — exactly the `atomCounts` and
|
|
43
|
+
* `weights` of {@link getMoleculeRecords}, and nothing else, so it costs one parse and one formula
|
|
44
|
+
* per molecule.
|
|
45
|
+
* @param idCodes - The molecules to read, as idcodes.
|
|
46
|
+
* @returns One entry per idcode in each array, in input order: 0 atoms and a `NaN` weight for a
|
|
47
|
+
* molecule that cannot be read.
|
|
48
|
+
*/
|
|
49
|
+
export function getMoleculeSizes(idCodes) {
|
|
50
|
+
const count = idCodes.length;
|
|
51
|
+
const sizes = {
|
|
52
|
+
atomCounts: new Int32Array(count),
|
|
53
|
+
weights: new Float64Array(count).fill(Number.NaN),
|
|
54
|
+
};
|
|
55
|
+
recoveringFromTraps((from, to) => Search.getMoleculeSizes(idCodes, sizes.atomCounts, sizes.weights, from, to), (index) => {
|
|
56
|
+
sizes.atomCounts[index] = 0;
|
|
57
|
+
sizes.weights[index] = Number.NaN;
|
|
58
|
+
}, 0, count);
|
|
59
|
+
return sizes;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The fewest atoms a molecule needs to contain the query: its atoms once the exclude groups are
|
|
63
|
+
* removed, plain hydrogens aside. Each of them maps onto a distinct atom of any match, so a molecule
|
|
64
|
+
* whose atom count is below the floor cannot match and needs no substructure test.
|
|
65
|
+
*
|
|
66
|
+
* Wildcards and atom lists count — each still takes an atom of the match. A plain hydrogen does not,
|
|
67
|
+
* because it may match an implicit one; a deuterium or a tritium does.
|
|
68
|
+
* @param idCodeQuery - The query, as an idcode; read as a fragment whatever its own fragment flag.
|
|
69
|
+
* @returns The floor, or 0 for a query with no atoms.
|
|
70
|
+
* @throws {Error} If the query cannot be parsed.
|
|
71
|
+
*/
|
|
72
|
+
export function getQueryAtomFloor(idCodeQuery) {
|
|
73
|
+
try {
|
|
74
|
+
return Search.getQueryAtomFloor(idCodeQuery);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new Error(`"${idCodeQuery}" is not a valid query idcode`, {
|
|
78
|
+
cause: error,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Writes the "could not read this" record of one molecule over whatever a trap left there.
|
|
84
|
+
* @param records - The records being filled.
|
|
85
|
+
* @param index - The molecule's position.
|
|
86
|
+
*/
|
|
87
|
+
function markUnreadable(records, index) {
|
|
88
|
+
records.idCodes[index] = NO_ID_CODE;
|
|
89
|
+
records.words.fill(0, index * RECORD_WORDS, (index + 1) * RECORD_WORDS);
|
|
90
|
+
records.atomCounts[index] = 0;
|
|
91
|
+
records.weights[index] = Number.NaN;
|
|
92
|
+
records.noStereoHashes[index] = NO_HASH;
|
|
93
|
+
records.tautomerHashes[index] = NO_HASH;
|
|
94
|
+
records.tautomerCounts[index] = 0;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAMhD,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,EAAE,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoB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CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;IACxC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;IACxC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACpC,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.
|
|
@@ -37,20 +36,63 @@ export declare function checkQuery(mode: SearchMode, idCodeQuery: string): void;
|
|
|
37
36
|
* @returns How many molecules were parsed and fingerprinted.
|
|
38
37
|
*/
|
|
39
38
|
export declare function buildIndexes(idCodes: string[], result: Int32Array, from: number, to: number): number;
|
|
39
|
+
/**
|
|
40
|
+
* Screens `idCodes[from .. to)` into `result`, sixteen words per molecule.
|
|
41
|
+
*
|
|
42
|
+
* Fails like {@link buildIndexes}: sixteen zeros for an idcode the WASM side cannot read.
|
|
43
|
+
* @param idCodes - The molecules to screen.
|
|
44
|
+
* @param result - The caller's buffer, `16 * idCodes.length` words long.
|
|
45
|
+
* @param from - The first index to screen.
|
|
46
|
+
* @param to - One past the last index to screen.
|
|
47
|
+
* @returns How many molecules were parsed and screened.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildScreens(idCodes: string[], result: Int32Array, from: number, to: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* Builds the function bits of `idCodes[from .. to)` into `result`, sixteen words per molecule.
|
|
52
|
+
*
|
|
53
|
+
* Fails like {@link buildIndexes}: sixteen zeros for an idcode the WASM side cannot read.
|
|
54
|
+
* @param idCodes - The molecules to read.
|
|
55
|
+
* @param result - The caller's buffer, `16 * idCodes.length` words long.
|
|
56
|
+
* @param from - The first index to read.
|
|
57
|
+
* @param to - One past the last index to read.
|
|
58
|
+
* @returns How many molecules were parsed and read.
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildFunctions(idCodes: string[], result: Int32Array, from: number, to: number): number;
|
|
61
|
+
/**
|
|
62
|
+
* Reads the fragments of the 512 stored function keys, in bit order.
|
|
63
|
+
* @returns Per key, its fragment idcodes.
|
|
64
|
+
*/
|
|
65
|
+
export declare function readFunctionKeys(): string[][];
|
|
66
|
+
/**
|
|
67
|
+
* Builds what every molecule a query matches has: its FragFp words, or its screen words.
|
|
68
|
+
* @param kind - `'index'` for the FragFp words, `'screen'` for the screen words.
|
|
69
|
+
* @param idCodeQuery - The query, as an idcode.
|
|
70
|
+
* @returns Sixteen words.
|
|
71
|
+
* @throws {Error} If the query cannot be parsed.
|
|
72
|
+
*/
|
|
73
|
+
export declare function buildQueryWords(kind: 'index' | 'screen', idCodeQuery: string): Int32Array;
|
|
74
|
+
/**
|
|
75
|
+
* Reads the key fragments behind the bits of the FragFp words, or of the screen words.
|
|
76
|
+
* @param kind - `'index'` for FragFp's keys, `'screen'` for the screen's.
|
|
77
|
+
* @returns 512 idcodes, in bit order.
|
|
78
|
+
*/
|
|
79
|
+
export declare function readKeys(kind: 'index' | 'screen'): string[];
|
|
40
80
|
/**
|
|
41
81
|
* Hashes `idCodes[from .. to)` into `result`, one no-stereo tautomer hash per molecule.
|
|
42
82
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* returns for a molecule it cannot canonize, so the two failures are reported the same way.
|
|
83
|
+
* A molecule that cannot be read gets `NO_HASH`, which is also what OpenChemLib returns for one it
|
|
84
|
+
* cannot canonize, so the two failures are reported the same way.
|
|
46
85
|
* @param idCodes - The molecules to hash.
|
|
47
86
|
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
48
87
|
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
49
88
|
* @param from - The first index to hash.
|
|
50
89
|
* @param to - One past the last index to hash.
|
|
90
|
+
* @param tautomerCounts - Filled with how many tautomers each molecule needed; an entry that reached
|
|
91
|
+
* `maxTautomers` is one OpenChemLib stopped early on.
|
|
92
|
+
* @param maxTautomers - The ceiling on that enumeration, which is what bounds the cost.
|
|
51
93
|
* @returns How many molecules were hashed.
|
|
52
94
|
*/
|
|
53
|
-
export declare function buildNoStereoTautomerHashes(idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number): number;
|
|
95
|
+
export declare function buildNoStereoTautomerHashes(idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number, tautomerCounts?: Int32Array, maxTautomers?: number): number;
|
|
54
96
|
/**
|
|
55
97
|
* Hashes `idCodes[from .. to)` into `result`, one no-stereo hash per molecule.
|
|
56
98
|
*
|
|
@@ -64,4 +106,54 @@ export declare function buildNoStereoTautomerHashes(idCodes: string[], result: B
|
|
|
64
106
|
* @returns How many molecules were hashed.
|
|
65
107
|
*/
|
|
66
108
|
export declare function buildNoStereoHashes(idCodes: string[], result: BigInt64Array, largestFragmentOnly: boolean, from: number, to: number): number;
|
|
109
|
+
/**
|
|
110
|
+
* Canonizes `idCodes[from .. to)` into `result`, one no-stereo idcode per molecule.
|
|
111
|
+
*
|
|
112
|
+
* This is the string {@link buildNoStereoHashes} hashes, for a caller that stores the canonical form
|
|
113
|
+
* rather than a 64-bit key. A molecule that cannot be read keeps the `NO_ID_CODE` the caller's array
|
|
114
|
+
* was filled with.
|
|
115
|
+
* @param idCodes - The molecules to canonize.
|
|
116
|
+
* @param result - The caller's array, `idCodes.length` entries long, filled with `NO_ID_CODE`.
|
|
117
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
118
|
+
* @param from - The first index to canonize.
|
|
119
|
+
* @param to - One past the last index to canonize.
|
|
120
|
+
* @returns How many molecules were canonized.
|
|
121
|
+
*/
|
|
122
|
+
export declare function buildNoStereoIdCodes(idCodes: string[], result: string[], largestFragmentOnly: boolean, from: number, to: number): number;
|
|
123
|
+
/**
|
|
124
|
+
* Canonizes `idCodes[from .. to)` into `result`, one no-stereo generic-tautomer idcode per molecule.
|
|
125
|
+
*
|
|
126
|
+
* Fails the same way {@link buildNoStereoIdCodes} does.
|
|
127
|
+
* @param idCodes - The molecules to canonize.
|
|
128
|
+
* @param result - The caller's array, `idCodes.length` entries long, filled with `NO_ID_CODE`.
|
|
129
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
130
|
+
* @param from - The first index to canonize.
|
|
131
|
+
* @param to - One past the last index to canonize.
|
|
132
|
+
* @param tautomerCounts - Filled with how many tautomers each molecule needed; an entry that reached
|
|
133
|
+
* `maxTautomers` is one OpenChemLib stopped early on.
|
|
134
|
+
* @param maxTautomers - The ceiling on that enumeration, which is what bounds the cost.
|
|
135
|
+
* @returns How many molecules were canonized.
|
|
136
|
+
*/
|
|
137
|
+
export declare function buildNoStereoTautomerIdCodes(idCodes: string[], result: string[], largestFragmentOnly: boolean, from: number, to: number, tautomerCounts?: Int32Array, maxTautomers?: number): number;
|
|
138
|
+
/**
|
|
139
|
+
* Runs a ranged WASM call, and redoes the range one molecule at a time if it traps.
|
|
140
|
+
*
|
|
141
|
+
* A malformed idcode makes OpenChemLib's bit-stream parser read past its input, which WebAssembly
|
|
142
|
+
* traps on — the same trap {@link scanRange} recovers from. The Java guard catches an empty or
|
|
143
|
+
* non-ASCII idcode, but a malformed ASCII one reaches the parser and traps there, which would
|
|
144
|
+
* otherwise lose every molecule in the range including the good ones. The trap leaves the module
|
|
145
|
+
* usable, and a per-molecule call costs what a batched one does because the 512 key fragments are
|
|
146
|
+
* parsed once for the module's lifetime, so redoing the range singly costs nothing that was not
|
|
147
|
+
* already going to be spent.
|
|
148
|
+
*
|
|
149
|
+
* There is no cap on the failures: these functions promise a per-molecule "could not read this"
|
|
150
|
+
* answer rather than an exception, so an array that is entirely garbage yields one of those per
|
|
151
|
+
* entry.
|
|
152
|
+
* @param call - Runs the WASM call over a range, returning how many molecules it handled.
|
|
153
|
+
* @param markUnreadable - Writes the "could not read this" answer for one molecule.
|
|
154
|
+
* @param from - The first index to handle.
|
|
155
|
+
* @param to - One past the last index to handle.
|
|
156
|
+
* @returns How many molecules were handled.
|
|
157
|
+
*/
|
|
158
|
+
export declare function recoveringFromTraps(call: (from: number, to: number) => number, markUnreadable: (index: number) => void, from: number, to: number): number;
|
|
67
159
|
//# 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,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