rxn.chemutils.miscellaneous.apply_to_any_smiles
- rxn.chemutils.miscellaneous.apply_to_any_smiles(any_smiles, fn, force_multicomponent=False)[source]
Apply a given function to individual compound SMILES strings given in any kind of SMILES string (molecule SMILES, multicomponent SMILES, reaction SMILES).
In the case of reaction SMILES, the format is kept.
- Parameters
any_smiles (
str
) – any kind of SMILES string.fn (
Callable
[[str
],str
]) – callback to apply to every compound SMILES.force_multicomponent (
bool
, default:False
) – by default, when a SMILES string contains no “>” or “~”, it is assumed to just be a normal single-component SMILES string. Providing force_multicomponent=True leads to an interpretation as a multismiles string, i.e. splitting at all the dots.
- Raises
Exception – different kinds of exception may be raised during parsing, or during execution of the callback.
- Return type
str
- Returns
the new (molecule, multicomponent, or reaction) SMILES string after application of the callback to all the component SMILES.