rxn.chemutils.miscellaneous.apply_to_smiles_groups

rxn.chemutils.miscellaneous.apply_to_smiles_groups(any_smiles, fn)[source]

Apply a given function to groups of SMILES strings given in any multicomponent SMILES or reaction SMILES.

This function can typically be used for sorting or shuffling precursors, products, etc.

In the case of reaction SMILES, the format is kept.

Parameters
  • any_smiles (str) – any kind of SMILES string.

  • fn (Callable[[List[str]], List[str]]) – callback to apply to every compound SMILES.

Raises

Exception – different kinds of exception may be raised during parsing, or during execution of the callback.

Return type

str

Returns

the new (multicomponent, or reaction) SMILES string after application of the callback to all the groups of SMILES.