openchemlib-search-wasm 1.0.0 → 1.2.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 +69 -2
- package/lib/index.d.ts +80 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +99 -2
- package/lib/index.js.map +1 -1
- package/lib/scan.d.ts +27 -0
- package/lib/scan.d.ts.map +1 -1
- package/lib/scan.js +31 -0
- package/lib/scan.js.map +1 -1
- package/lib/types.d.ts +22 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +6 -0
- package/lib/types.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +128 -2
- package/src/scan.ts +57 -0
- package/src/types.ts +37 -0
- package/wasm/data.js +1 -1
package/src/scan.ts
CHANGED
|
@@ -139,3 +139,60 @@ export function buildIndexes(
|
|
|
139
139
|
): number {
|
|
140
140
|
return Search.getIndexes(idCodes, result, from, to);
|
|
141
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Hashes `idCodes[from .. to)` into `result`, one no-stereo tautomer hash per molecule.
|
|
145
|
+
*
|
|
146
|
+
* Like the fingerprints and unlike the searches, a malformed idcode needs no recovery here: the
|
|
147
|
+
* WASM side writes `0` for one it cannot read and carries on, and `0` is also what OpenChemLib
|
|
148
|
+
* returns for a molecule it cannot canonize, so the two failures are reported the same way.
|
|
149
|
+
* @param idCodes - The molecules to hash.
|
|
150
|
+
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
151
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
152
|
+
* @param from - The first index to hash.
|
|
153
|
+
* @param to - One past the last index to hash.
|
|
154
|
+
* @returns How many molecules were hashed.
|
|
155
|
+
*/
|
|
156
|
+
export function buildNoStereoTautomerHashes(
|
|
157
|
+
idCodes: string[],
|
|
158
|
+
result: BigInt64Array,
|
|
159
|
+
largestFragmentOnly: boolean,
|
|
160
|
+
from: number,
|
|
161
|
+
to: number,
|
|
162
|
+
): number {
|
|
163
|
+
return Search.getNoStereoTautomerHashes(
|
|
164
|
+
idCodes,
|
|
165
|
+
result,
|
|
166
|
+
largestFragmentOnly,
|
|
167
|
+
from,
|
|
168
|
+
to,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Hashes `idCodes[from .. to)` into `result`, one no-stereo hash per molecule.
|
|
174
|
+
*
|
|
175
|
+
* Fails the same way {@link buildNoStereoTautomerHashes} does: `0` for an idcode the WASM side
|
|
176
|
+
* cannot read and for a molecule OpenChemLib cannot canonize.
|
|
177
|
+
* @param idCodes - The molecules to hash.
|
|
178
|
+
* @param result - The caller's buffer, `idCodes.length` entries long.
|
|
179
|
+
* @param largestFragmentOnly - Whether to strip and neutralize down to the largest fragment first.
|
|
180
|
+
* @param from - The first index to hash.
|
|
181
|
+
* @param to - One past the last index to hash.
|
|
182
|
+
* @returns How many molecules were hashed.
|
|
183
|
+
*/
|
|
184
|
+
export function buildNoStereoHashes(
|
|
185
|
+
idCodes: string[],
|
|
186
|
+
result: BigInt64Array,
|
|
187
|
+
largestFragmentOnly: boolean,
|
|
188
|
+
from: number,
|
|
189
|
+
to: number,
|
|
190
|
+
): number {
|
|
191
|
+
return Search.getNoStereoHashes(
|
|
192
|
+
idCodes,
|
|
193
|
+
result,
|
|
194
|
+
largestFragmentOnly,
|
|
195
|
+
from,
|
|
196
|
+
to,
|
|
197
|
+
);
|
|
198
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -190,8 +190,45 @@ export interface OCLSearch {
|
|
|
190
190
|
from: number,
|
|
191
191
|
to: number,
|
|
192
192
|
) => number;
|
|
193
|
+
/** Returns how many molecules in the range were hashed. */
|
|
194
|
+
getNoStereoTautomerHashes: (
|
|
195
|
+
idCodes: string[],
|
|
196
|
+
result: BigInt64Array,
|
|
197
|
+
largestFragmentOnly: boolean,
|
|
198
|
+
from: number,
|
|
199
|
+
to: number,
|
|
200
|
+
) => number;
|
|
201
|
+
/** Returns how many molecules in the range were hashed. */
|
|
202
|
+
getNoStereoHashes: (
|
|
203
|
+
idCodes: string[],
|
|
204
|
+
result: BigInt64Array,
|
|
205
|
+
largestFragmentOnly: boolean,
|
|
206
|
+
from: number,
|
|
207
|
+
to: number,
|
|
208
|
+
) => number;
|
|
193
209
|
};
|
|
194
210
|
}
|
|
195
211
|
|
|
196
212
|
/** How many 32-bit words one molecule's FragFp fingerprint occupies. */
|
|
197
213
|
export const INDEX_WORDS = 16;
|
|
214
|
+
|
|
215
|
+
/** What every hash function takes. */
|
|
216
|
+
export interface HashOptions {
|
|
217
|
+
/**
|
|
218
|
+
* Whether to reduce the molecule to its largest fragment and neutralize it before hashing, so a
|
|
219
|
+
* salt hashes as its parent structure and a hydrochloride as its free base. Off by default, which
|
|
220
|
+
* is what `openchemlib`'s own `CanonizerUtil.getIDCode` does.
|
|
221
|
+
* @default false
|
|
222
|
+
*/
|
|
223
|
+
largestFragmentOnly?: boolean;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** {@link HashOptions} under the name the tautomer hashes introduced it with. */
|
|
227
|
+
export type TautomerHashOptions = HashOptions;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The hash of a molecule that has none: its idcode could not be parsed, or OpenChemLib could not
|
|
231
|
+
* canonize it. A real hash collides with it once in 2^64, so an equality test against it is a
|
|
232
|
+
* usable "no hash" check.
|
|
233
|
+
*/
|
|
234
|
+
export const NO_HASH = 0n;
|