Manual Route Manipulation¶
Being able to manipulate the predicted routes means that you can include your domain knowledge directly into the output of the models! LinChemIn allows you to perform various operations on single and multiple routes
Node Removal¶
If looking at the predicted route(s) you realize that are some molecules or chemical reactions that you are not interested in, that re various functions and methods that you can use.
If you just want to remove a single node from a route, you can use the
remove_node() method, which is available for all types of SynGraph.
However, you need to build the Molecule or the
ChemicalEquation instance corresponding to the node to be removed
and use its unique identifier property.
from linchemin.cheminfo.constructors import MoleculeConstructor
smiles_to_remove = 'CC(=O)O' # the smiles of the molecule to be removed
mol_to_remove = MoleculeConstructor().build_from_molecule_string(smiles_to_remove, 'smiles') # the Molecule object is built
syngraph.remove_node(mol_to_remove.uid)
In case you want to remove a reaction node based on its smiles, you can use the
remove_reaction_from_syngraph() function. In this case, you
can also ask to remove the potential “dangling” nodes that the removal could leave behind.
A new SynGraph object is created.
from linchemin.cgu.syngraph_operations import remove_reaction_from_syngraph
smiles_to_remove = 'CCN.CCOC(=O)CC>>CCNC(=O)CC' # the smiles of the reaction to be removed
new_graph = remove_reaction_from_syngraph(original_syngraph, # the syngraph to be edited
smiles_to_remove, # the smiles of the reaction to be removed
remove_dandling_nodes=True) # whether dandling nodes should be removed
Route Mining and Node Addition¶
So, you predicted a nice set of routes for a target, but checking them, you notice that a particular reaction or a sequence of reactions that you think might be very useful is not included in any of them.
No worries, you can provide the already existing routes, the smiles of the target molecule and
a list of reactions that you want to add, and will be able to retrieve all
the routes from the obtained tree.
All you need is the mine_routes() function!
from linchemin.cgu.route_mining import mine_routes
input_list = [route1, route2] # the initial set of routes
root = 'CCC(=O)Nc1ccc(cc1)C(=O)N[C@@H](CO)C(=O)O' # the target molecule for which routes should be retrieved
new_reaction_list = ['CC=O.O=O>>CC(=O)O'] # the reaction(s) to be added
routes = mine_routes(input_list, root, new_reaction_list) # all the mined routes
The input routes should be instances of any SynGraph subclasses
and the output routes
will be MonopartiteReacSynGraph objects.