Package: rxn-chem-utils
RXN chemistry utilities packageThis repository contains various chemistry-related Python utilities used in the RXN universe.
For general utilities not related to chemistry, see our other repositoryrxn-utilities.Links:GitHub repositoryDocumentationPyPI packageSystem RequirementsThis package is supported on all operating systems.
It has been tested on the following systems:macOS: Big Sur (11.1)Linux: Ubuntu 18.04.4A Python version of 3.7 or greater is recommended.Installation guideThe package can be installed from Pypi:pipinstallrxn-chem-utilsFor local development, the package can be installed with:pipinstall-e.[dev]TheRDKitdependency is not installed automatically and can be installed via Conda or Pypi:# Install RDKit from Condacondainstall-cconda-forgerdkit# Install RDKit from PypipipinstallrdkitPackage highlightsConvert between compound representationsThere are functions to convert between SMILES,RDKit.Mol, MDL, InChI, etc.
All of them work in a similar way:>>>fromrxn.chemutils.conversionimportsmiles_to_mol,mol_to_smiles>>>mol=smiles_to_mol("CO(C)")>>>mol_to_smiles(mol)'COC'The functions raise exceptions when failing, and allow to be used without sanitization.>>>mol=smiles_to_mol("CFC")Traceback (most recent call last):[...]rxn.chemutils.exceptions.InvalidSmiles:"CFC" is not a valid SMILES string>>>mol=smiles_to_mol("CFC",sanitize=False)>>>mol_to_smiles(mol)'CFC'Reaction SMILESThe package supports different kinds of reaction SMILES, which, internally, are stored asReactionEquations.To convert to and fromReactionEquation, a few functions are provided:parse_reaction_smilesandto_reaction_smiles, if you know already the format.parse_any_reaction_smiles, if you don't know the format or want to be flexible.Examples:>>>fromrxn.chemutils.reaction_smilesimportReactionFormat,determine_format,parse_reaction_smiles,to_reaction_smiles,parse_any_reaction_smiles>>>rxn_smiles="CC.O.[Na+]~[Cl-]>>CCO">>>determine_format(rxn_smiles)<ReactionFormat.STANDARD_WITH_TILDE: 3>>>>parse_reaction_smiles(rxn_smiles,ReactionFormat.STANDARD_WITH_TILDE)ReactionEquation(reactants=['CC', 'O', '[Na+].[Cl-]'], agents=[], products=['CCO'])>>>parse_any_reaction_smiles(rxn_smiles)ReactionEquation(reactants=['CC', 'O', '[Na+].[Cl-]'], agents=[], products=['CCO'])>>>to_reaction_smiles(parse_any_reaction_smiles(rxn_smiles),ReactionFormat.EXTENDED)'CC.O.[Na+].[Cl-]>>CCO |f:2.3|'Multicomponent SMILESSometimes, it is necessary to represent multiple compounds as one single SMILES string.
For fragments / ions, it becomes necessary to distinguish between what parts belong together as one compound, and what are differentt compounds.
In such "multitcomponent SMILES", we typically use tildes,~, to indicate that different SMILES fragments belong to the same compound.>>>fromrxn.chemutils.multicomponent_smilesimportmulticomponent_smiles_to_list,list_to_multicomponent_smiles>>>list_to_multicomponent_smiles(["CC","[Na+].[Cl-]"],fragment_bond="~")'CC.[Na+]~[Cl-]'>>>multicomponent_smiles_to_list('CC.[Na+]~[Cl-]',fragment_bond="~")['CC', '[Na+].[Cl-]']CanonicalizationCanonicalization of compounds, with the possibility to remove the valence check:>>>fromrxn.chemutils.conversionimportcanonicalize_smiles>>>canonicalize_smiles("CC(O)")'CCO'>>>canonicalize_smiles("ABCD")# Invalid SMILESTraceback (most recent call last):[...]rxn.chemutils.exceptions.InvalidSmiles:"ABCD" is not a valid SMILES string>>>canonicalize_smiles("CF(C)")# Invalid valence, fails by defaultTraceback (most recent call last):[...]rxn.chemutils.exceptions.InvalidSmiles:"CFC" is not a valid SMILES string>>>canonicalize_smiles("CF(C)",check_valence=False)# Invalid valence, does not fail'CFC'Canonicalization of any kind of SMILES (components, multicomponent SMILES, reaction SMILES, etc.), again with the possibility to disable the valence check.
Note that the resulting string is in the same format.>>>fromrxn.chemutils.miscellaneousimportcanonicalize_any>>>canonicalize_any("[Na+].[Cl-]")'[Cl-].[Na+]'>>>canonicalize_any("OC.C(O)~CF(C)",check_valence=False)'CO.CFC~CO'>>>canonicalize_any("CC(C)>C(O)>C(O)")'CCC>CO>CO'>>>canonicalize_any("CO.O.C>>C(O) |f:1.2|")'CO.C.O>>CO |f:1.2|'The executablerxn-canonicalize(installed with the package), which works either on files or on stdinrxn-canonicalize--helpAugmentationSeesmiles_randomization.pyandsmiles_augmenter.pyfor the augmentation of compound SMILES and reaction SMILES strings.OthersWithout going into details, the package also does the following:Tokenization and detokenization of SMILES strings intokenization.py, and the executablesrxn-tokenizeandrxn-detokenize.Easy combination of precursor SMILES and product SMILES into a reaction SMILES with theReactionCombiner, and the executablerxn-combine-reaction.Parsing of RDFs into reaction SMILES: differentmodules, and the executablerxn-rdf-to-smiles.... and many others.