UNPKG

@iktos-oss/rdkit-provider

Version:

exports an initialized RDKit instance, with helper functions

131 lines (127 loc) 5.59 kB
"use strict"; /* MIT License Copyright (c) 2023 Iktos Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); const caching_1 = require("./utils/caching"); const actions_1 = require("./actions"); const initRDKit_1 = require("./utils/initRDKit"); const chem_1 = require("./utils/chem"); addEventListener('message', async ({ data }) => { let responsePayload; switch (data.actionType) { case actions_1.RDKIT_WORKER_ACTIONS.INIT_RDKIT_MODULE: await (0, initRDKit_1.initRdkit)(data.payload); break; case actions_1.RDKIT_WORKER_ACTIONS.GET_MOLECULE_DETAILS: responsePayload = (0, chem_1.getMoleculeDetails)({ smiles: data.payload.smiles, returnFullDetails: true, }); break; case actions_1.RDKIT_WORKER_ACTIONS.DEPRECATED_GET_MOLECULE_DETAILS: console.warn('[DEPRECATED] Using deprecated molecule details retrieval. Please update to the full details API by passing returnFullDetails=true, careful numAtom is now NumHeavyAtom and not NumAtom.'); responsePayload = (0, chem_1.getMoleculeDetails)({ smiles: data.payload.smiles, returnFullDetails: false, }); break; case actions_1.RDKIT_WORKER_ACTIONS.GET_CANONICAL_FORM_FOR_STRUCTURE: responsePayload = { canonicalForm: (0, chem_1.getCanonicalFormForStructure)(data.payload), }; break; case actions_1.RDKIT_WORKER_ACTIONS.IS_CHIRAL: responsePayload = (0, chem_1.isChiral)(data.payload.smiles); break; case actions_1.RDKIT_WORKER_ACTIONS.GET_MORGAN_FP: responsePayload = (0, chem_1.getMorganFp)(data.payload); break; case actions_1.RDKIT_WORKER_ACTIONS.GET_SVG: responsePayload = { svg: (0, chem_1.getSvg)(data.payload), }; break; case actions_1.RDKIT_WORKER_ACTIONS.GET_SVG_FROM_SMARTS: responsePayload = { svg: (0, chem_1.getSvgFromSmarts)(data.payload), }; break; case actions_1.RDKIT_WORKER_ACTIONS.IS_VALID_SMILES: responsePayload = { isValid: (0, chem_1.isValidSmiles)(data.payload.smiles), }; break; case actions_1.RDKIT_WORKER_ACTIONS.IS_VALID_SMARTS: responsePayload = { isValid: (0, chem_1.isValidSmarts)(data.payload.smarts), }; break; case actions_1.RDKIT_WORKER_ACTIONS.HAS_MATCHING_SUBSTRUCTURE: responsePayload = { matching: (0, chem_1.hasMatchingSubstructure)(data.payload), }; break; case actions_1.RDKIT_WORKER_ACTIONS.GET_SUBSTRUCTURE_MATCH: responsePayload = (0, chem_1.getMatchingSubstructure)(data.payload); break; case actions_1.RDKIT_WORKER_ACTIONS.IS_VALID_MOLBLOCK: responsePayload = { isValid: (0, chem_1.isValidMolBlock)(data.payload.mdl), }; break; case actions_1.RDKIT_WORKER_ACTIONS.CONVERT_MOL_NOTATION: responsePayload = { structure: (0, chem_1.convertMolNotation)(data.payload), }; break; case actions_1.RDKIT_WORKER_ACTIONS.ADD_HS: responsePayload = { mdl: (0, chem_1.addHs)(data.payload.structure), }; break; case actions_1.RDKIT_WORKER_ACTIONS.REMOVE_HS: responsePayload = { mdl: (0, chem_1.removeHs)(data.payload.structure), }; break; case actions_1.RDKIT_WORKER_ACTIONS.GET_NEW_COORDS: responsePayload = { mdl: (0, chem_1.getNewCoords)(data.payload.structure, data.payload.useCoordGen), }; break; case actions_1.RDKIT_WORKER_ACTIONS.GET_STEREO_TAGS: responsePayload = { ...(0, chem_1.getStereoTags)(data.payload.structure), }; break; case actions_1.RDKIT_WORKER_ACTIONS.TERMINATE: (0, caching_1.cleanAllCache)(); self.close(); break; default: return; } postMessage({ actionType: (0, actions_1.getActionLocalResponseIdentifier)(data.actionType), payload: responsePayload, key: data.key, }); }); //# sourceMappingURL=worker.js.map