rxn.chemutils.reaction_combiner.ReactionCombiner
- class rxn.chemutils.reaction_combiner.ReactionCombiner(standardize=False, reaction_format=ReactionFormat.STANDARD_WITH_TILDE, fallback_reaction='>>')[source]
Bases:
object
Class to combine sets of precursors with sets of products, or sets of partial reactions with other sets of partial reactions.
This class is typically useful when one needs to produce the full reaction SMILES starting from multiple files, such as A) one file for the precursors and one for the products, or B) two files containing each one part of a chemical equation.
This class is particularly useful when the said files have different sizes, which can be the case when multiple predictions are made for each line of one of these files.
- Parameters
standardize (
bool
, default:False
) –reaction_format (
ReactionFormat
, default:<ReactionFormat.STANDARD_WITH_TILDE: 3>
) –fallback_reaction (
str
, default:'>>'
) –
- __init__(standardize=False, reaction_format=ReactionFormat.STANDARD_WITH_TILDE, fallback_reaction='>>')[source]
- Parameters
standardize (
bool
, default:False
) – whether to standardize (i.e. canonicalize and reorder) the reaction SMILES.reaction_format (
ReactionFormat
, default:<ReactionFormat.STANDARD_WITH_TILDE: 3>
) – which format should be used for the reaction SMILES.fallback_reaction (
str
, default:'>>'
) – text / reaction to produce when a reaction is invalid.
Methods
__init__
([standardize, reaction_format, ...])- type standardize
bool
, default:False
combine
(fragments_1, fragments_2)See docstring of function
combine_sequences
.combine_iterators
(fragments_1, fragments_2)Combine the two iterators of fragments into an iterator of reactions.
combine_sequences
(fragments_1, fragments_2)Combine the two sequences of fragments into an iterator of reactions.
- combine(fragments_1, fragments_2)[source]
See docstring of function
combine_sequences
.- Parameters
fragments_1 (
Sequence
[str
]) –fragments_2 (
Sequence
[str
]) –
- Return type
Iterator
[str
]
- combine_iterators(fragments_1, fragments_2, fragments_1_multiplier=1, fragments_2_multiplier=1)[source]
Combine the two iterators of fragments into an iterator of reactions.
- Parameters
fragments_1 (
Iterable
[str
]) – Sequence of sets of precursors strings (such as “CC.O.[Na+]~[Cl-]”), or list of partial reactions.fragments_2 (
Iterable
[str
]) – Sequence of sets of product(s) strings, or list of partial reactions.fragments_1_multiplier (
int
, default:1
) – how many times to duplicate the fragments_1.fragments_2_multiplier (
int
, default:1
) – how many times to duplicate the fragments_2.
- Raises
RuntimeError – if one of the iterators isn’t fully consumed.
ValueError – when one is not exactly a multiple of the other.
- Return type
Iterator
[str
]- Returns
Iterator over the resulting reaction SMILES.
- combine_sequences(fragments_1, fragments_2)[source]
Combine the two sequences of fragments into an iterator of reactions.
- Parameters
fragments_1 (
Sequence
[str
]) – Sequence of sets of precursors strings (such as “CC.O.[Na+]~[Cl-]”), or list of partial reactions.fragments_2 (
Sequence
[str
]) – Sequence of sets of product(s) strings, or list of partial reactions.
- Return type
Iterator
[str
]- Returns
Iterator over the resulting reaction SMILES.