schrodinger.application.pathfinder.reaction module¶
Classes to represent and apply chemical reactions.
Examples:
# run one reaction
rxn_smarts = "[C:8][N:7][C:2]([C:1])=[O:4]>>[C:1][C:2](O)=[O:4].[N:7][C:8]"
rxn = Reaction("Amide coupling", rxn_smarts)
amide = Chem.MolFromSmiles('CC(=O)NC')
for acid, amine in rxn.apply((amide,)):
print(Chem.MolToSmiles(acid))
print(Chem.MolToSmiles(amine))
reverse_rxn = rxn.inverse()
# read reactions from file:
reactions = read_reactions_file('reactions.json')
- class schrodinger.application.pathfinder.reaction.Reaction(name, retro_smarts=None, lhs_classes=None, rhs_classes=None, syn_smarts=None, tags=None, tier=None, allow_multiple_products=False, rxnfile=None, inverse_rxnfile=None, description=None, reagents_dict=None, long_name=None, ld_data=None, require_mapping=True, **kw)¶
Bases:
object
A Reaction object represents a generic reaction, such as “amide coupling”. An actual instance of a reaction between specific reagents is a ReactionInstance (see below).
A Reaction may optionally be associated with “reagent classes” for the molecules on the left-hand-side and right-hand-side of the reaction. We avoid the terms “reactants” and “products” because they depend on the context; Reaction objects may be used for actual reactions, but also for retrosynthetic transforms (where “target” and “precursors” would be more appropriate), or for even for alchemical transformations.
A reagent class is just a name representing the type of compound involved in the reaction; the naming scheme is up to the caller. For example, for amide coupling, the reagent classes on one side might be “amine” and “acid”, and on the other “amide”.
- __init__(name, retro_smarts=None, lhs_classes=None, rhs_classes=None, syn_smarts=None, tags=None, tier=None, allow_multiple_products=False, rxnfile=None, inverse_rxnfile=None, description=None, reagents_dict=None, long_name=None, ld_data=None, require_mapping=True, **kw)¶
- Parameters:
name (str) – Reaction name.
retro_smarts (str or NoneType) – Reaction SMARTS (RDKit dialect).
lhs_classes (list of str or NoneType) – Reagent classes for the left-hand-side of the reaction.
rhs_classes (list of str or NoneType) – Reagent classes for the right-hand-side of the reaction.
syn_smarts – Reaction SMARTS for the reverse reaction. If not specified, it is constructed automatically from ‘retro_smarts’ by swapping around the “>>”.
tags (iterable of str or NoneType) – Optional list of tags associated with the reaction.
tier (int) – an integer describing how “good” the reaction is (lower is better)
allow_multiple_products – ignored for backward compatibility
rxnfile (str) – Path to MDL Rxnfile. May be used instead of ‘retro_smarts’.
inverse_rxnfile (str) – Path to MDL Rxnfile for the reverse reaction. May be used instead of ‘syn_smarts’.
description (str) – Reaction description.
ld_data (object) – arbitrary object reserved for the use of LiveDesign.
require_mapping (bool) – if True, raise a ValueError for reactions without any atom mappings
- asDict()¶
Return a dict representation of the reaction suitable for JSON serialization.
- Returns:
dict
- Return type:
dict
- apply(reactants)¶
Apply the reaction to the given reactants, returning a list of lists of products. The products are already sanitized.
- Return type:
list of list of Mol
- inverse()¶
Return a new Reaction object for the inverse of the current reaction.
- suggestReagentClasses(r_classes, libpath=None, max_search=10)¶
Search through r_classes for reagent classes matching each of the reactants in the reaction.
- Parameters:
r_classes (dict of ReagentClass) – dictionary of reagent classes by name
libpath (list of str) – list of directories to prepend to the standard reagent library search path
max_search (int) – maximum number of structures to search from each reagent file before deciding the file doesn’t match.
- Returns:
list of lists of reagent classes. Each item in the outer list corresponds to one of the molecules on the right-hand side of the reaction. Items in the inner list (which may be empty) are the suggested classes for that molecule.
- Return type:
list of list of ReagentClass
- getDisplaySmarts()¶
Return the display SMARTS for the reaction. This is a simplified SMARTS meant for depiction purposes only. If the reaction doesn’t have a display SMARTS, the syn_smarts is returned.
- Returns:
display SMARTS
- Return type:
str
- debugReactants(reactants)¶
Print each reactant SMILES and reactant template SMARTS and whether they match. This helps debugging a reaction SMARTS by making it easier to see which component to focus on.
- Parameters:
reactants ([Chem.Mol]) – list of reactants
- class schrodinger.application.pathfinder.reaction.ReactionDict(reactions, reagent_classes, inverse_tags)¶
Bases:
dict
Reaction dictionary with additional properties for reagent classes and inverse tags.
- Variables:
reagent_classes – reagent classes
inverse_tags – inverse tags
- __init__(reactions, reagent_classes, inverse_tags)¶
- Parameters:
reactions ({str: Reaction}) – dict of reactions by name
reagent_classes ({str: ReagentClass}) – dict of reagent classes by name
inverse_tags – dict of inverse tags for each tag
inverse_tags – {str: set(str)}
- class schrodinger.application.pathfinder.reaction.ReagentClass(name, reactive=False, description=None, smarts=None)¶
Bases:
object
Struct-like class to hold metadata for a reagent class. Fields include name, description, and ‘reactive’. A reactive reagent is one which shouldn’t be analyzed retrosynthetically. For example, acyl chlorides.
- __init__(name, reactive=False, description=None, smarts=None)¶
- asDict()¶
Return a dict representation of the reaction suitable for JSON serialization.
- Returns:
dict
- Return type:
dict
- findReagentFile(libpath=None)¶
Look for <reagent_class>.* (where the extension corresponds to a recognized structure file format) in each of the directories in the library search path. Return the first match, but if multiple matches are found in the same directory, raise an exception.
- Parameters:
libpath (list of str) – list of directories to prepend to the default reagent library search path
- Returns:
path to reagent file, or None if not found
- Return type:
str
- Raises:
ValueError if multiple matches are found in the CWD.
- size(libpath=None)¶
Return the number of structures in the reagent file for this class.
- Parameters:
libpath (list of str) – list of directories to prepend to the standard reagent library search path
- Returns:
number of structures, or zero when no file is found.
- Return type:
int
- copyReagentFile(dest_file, libpath=None)¶
Exports reagents into a given .csv file.
- Parameters:
dest_file (str) – output .csv file
libpath (list of str) – list of directories to prepend to the standard reagent library search path
- Returns:
False if reagent file was not found and True otherwise
- Return type:
bool
- schrodinger.application.pathfinder.reaction.read_reactions_file(filename=None, reagents_dict=None, merge_with_defaults=False)¶
Read a reactions file in JSON format and return a dictionary of reactions by name. If filename is None, read the standard reactions file from the mmshare data directory and add the ‘default’ tag to each reaction.
- Parameters:
filename (str) – file to read
reagents_dict (dict {str: ReagentClass}) – dictionary of reagent classes (normally from read_reagent_classes_file).
merge_with_defaults (bool) – if True, read both the default file and the specified file and merge them.
- Returns:
dictionary of reactions by name
- Return type:
dict {str: Reaction}
- schrodinger.application.pathfinder.reaction.read_rxn_file(filename)¶
Read reaction from .rxn file and return dictionary of reactions.
- Parameters:
filename (str) – file to read
- Returns:
dictionary of reactions by name
- Return type:
dict {str: Reaction}
- schrodinger.application.pathfinder.reaction.read_reagent_classes_file(filename=None, merge_with_defaults=False)¶
Read a reagent classes file in JSON format and return a dictionary of reagent classes by name. If filename is None, read the standard reagent classes file from the mmshare data directory.
- Parameters:
filename (str) – file to read
merge_with_defaults (bool) – if True, read both the default file and the specified file and merge them.
- Returns:
dictionary of reagent classes by name
- Return type:
dict {str: ReagentClass}
- schrodinger.application.pathfinder.reaction.get_custom_reagent_classes(filename)¶
Reads a reagent classes file in JSON format and returns a dictionary of reagent classes by name. If custom reagent classes file is not found it will be created.
- Parameters:
filename – file to read
- Returns:
dictionary of reagent classes
- Return type:
dict {str: ReagentClass}
- schrodinger.application.pathfinder.reaction.get_MEL_class(reagent_class, reaction)¶
Concatenate reagent class and reaction strings using canonical unifier into MEL class string. Since reagent class and reaction classes have stringify methods, theses classes can be used as arguments.
- Parameters:
reagent_class (str) – reagent class name
reaction (str) – reaction name
- Returns:
concatenated string
- Return type:
str
- schrodinger.application.pathfinder.reaction.read_minimal_caps_file(minimal_caps_file=None)¶
Read minimal caps file. If not provided, use the default one for Pathfinder space. :rtype: dict[str, Tuple[Chem.Mol, str]] :return: dictionary of minimal caps by reagent class and reaction
- schrodinger.application.pathfinder.reaction.get_inverse_reactions_by_reagent(reactions)¶
Restructure reactions dictionary to the form of {reagent_name: {reaction_name: Reaction.inverse()}} and return the resulting dictionary. Useful for application of ‘forward’ reactions to building blocks. :param reactions: dictionary of reactions :type reactions: ReactionDict[str, Reaction] :return: dictionary of inverse reactions by reagent :rtype: dict[str, dict[str, Reaction]]
- schrodinger.application.pathfinder.reaction.get_default_reactions_filename()¶
Return the path to the default reactions file.
- Returns:
path
- Return type:
str
- schrodinger.application.pathfinder.reaction.get_default_reagent_classes_filename()¶
Return the path to the default reagent classes file.
- Returns:
path
- Return type:
str
- schrodinger.application.pathfinder.reaction.get_default_minimal_caps_filename()¶
Return the path to the default MEL minimal caps file.
- Returns:
path
- Return type:
str
- schrodinger.application.pathfinder.reaction.parse_inverse_tags(tag_tups)¶
Turn the list-based representation of inverse tags into a dictionary for ease of look up. For example, given
[ [['a', 'b'], ['c', 'd']], [['e'], ['f']] ]
return
{ 'a': {'c', 'd'}, 'b': {'c', 'd'}, 'c': {'a', 'b'}, 'd': {'a', 'b'}, 'e': {'f'}, 'f': {'e'} }
- Parameters:
tag_tups (list(list(list(str)))) – a list of incompatible tag sets. In the example above, reactions tagged “a” or “b” are considered inverse of reactions tagged “c” or “d”.
- Returns:
dictionary where each key is a tag an each value is a set of tags considered “inverse” of the key. This is actually a defaultdict, where the default value is an empty set.
- Return type:
defaultdict(set(str))
- schrodinger.application.pathfinder.reaction.parse_pathfinder_data(raw_dict)¶
Convert a “raw dict” (usually from a pathfinder.json) into a ReactionDict.
- Return type:
- schrodinger.application.pathfinder.reaction.read_pathfinder_data(filename=None)¶
Read a PathFinder data file and return a ReactionDict.
- Parameters:
filename (str) – file to read
- Returns:
dictionary of reactions by name
- Return type:
- schrodinger.application.pathfinder.reaction.parse_reaction_data(raw_dict, reagents_dict=None)¶
Convert a “raw dict” (usually from a JSON file) into a dictionary of Reaction objects by name.
- Return type:
dict {str: Reaction}
- schrodinger.application.pathfinder.reaction.parse_reagent_classes_data(raw_dict)¶
Convert a “raw dict” (usually from a JSON file) into a dictionary of ReagentClass objects by name.
- Return type:
dict {str: Reaction}
- schrodinger.application.pathfinder.reaction.write_reactions_file(reactions, filename)¶
Write a reactions file. :reactions: list or dict of reactions :type reactions: list or dict of Reaction
- schrodinger.application.pathfinder.reaction.write_reagent_classes_file(reagent_classes, filename)¶
Write a reagent classes file.
- Parameters:
reagent_classes – dict of reagent classes by name
filename (str) – file to write
- schrodinger.application.pathfinder.reaction.invert_reaction_smarts(smarts)¶
Given a reaction SMARTS, return the reaction SMARTS for the reverse reaction.
- Return type:
str
Return the path to the reagent directory installed with mmshare. :rtype: str
- schrodinger.application.pathfinder.reaction.get_libpath()¶
Return the reagent library search path. It consists of the directories listed in the SCHRODINGER_REAGENT_LIB environment variable, if it exists, followed by ~/.schrodinger/reagents or its Windows equivalent, followed by the mmshare data/reagents directory.
- Return type:
list of str
- schrodinger.application.pathfinder.reaction.debug_mols(message, mols, separator=' + ')¶
Print a debug message (if the logger level indicates it), appending a list of SMILES representation of the molecules.
- schrodinger.application.pathfinder.reaction.is_reagent_file(filename)¶
Check whether a given file is usable as a reagent file. A reagent file must be a structure file and the structures need to have a title. In the case of a csv file, we look for columns named ‘s_m_title’ or ‘NAME’.
- Parameters:
filename (str) – filename
- Returns:
True if the file is a reagent file
- Return type:
bool
- schrodinger.application.pathfinder.reaction.is_reagent_filename(filename)¶
Check whether a filename has the extension for a possible reagent file format. Unlike is_reagent_file, it does not open the file to try to confirm whether there are valid structures in it.
- Parameters:
filename (str) – filename
- Returns:
True if the filename may be a reagent file
- Return type:
bool
- schrodinger.application.pathfinder.reaction.get_title(mol, prop='s_m_title')¶
Return the title of a molecule. Looks for the property with the name specified by ‘prop’ but falls back to known aliases such as “NAME”.
- Parameters:
mol (Chem.Mol) – input molecule
prop (str) – title property name
- Returns:
molecule title, or None if unspecified
- Return type:
str or NoneType
- schrodinger.application.pathfinder.reaction.get_reactions(filename=None, reagent_classes_file=None, max_tier=None)¶
Convenience function to read the reactions and the reagent classes file with a single call, and optionally filtering the reactions by tier.
- Parameters:
filename (str) – reactions file (JSON formatted). If None, read the standard file.
filename – reagent classes file (JSON formatted). If None, read the standard file.
max_tier (int or NoneType) – maximum reaction tier (None means all reactions)
- Returns:
dictionary of reactions
- Return type:
{str: Reaction}