Skip to content

Commit 06ef820

Browse files
release 2.2.5 (#25)
New functionalities are implemented to: add reaction nodes to a SynGraph object remove reaction nodes from a SynGraph object extract synthetic routes from the network obtained by merging a group of SynGraph objects Improvements in ChemicalEquationConstructor and ChemicalEquation object are implemented: better handling of Disconnection information better handling of stoichiometry Various bugs are solved.
1 parent 14feb9d commit 06ef820

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+8644
-3071
lines changed

docs/source/chemical_objects_classes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ passing a ``molecular_identity_property_name`` string, indicating which property
5151
of the molecules involved in the reaction (e.g. ‘smiles’) and a ``chemical_equation_identity_name`` string,
5252
indicating which representation of the reaction should be used for determining the identity (e.g., 'r_p'
5353
only considers reactants and products, while 'r_r_p' also takes into account the reagents.
54+
The methods :method:`~linchemin.cheminfo.constructors.ChemicalEquationConstructor.build_from_reaction_string`
55+
and :method:`~linchemin.cheminfo.constructors.ChemicalEquationConstructor.build_from_rdrxn` can then be used to
56+
create the new :class:`~models.ChemicalEquation` by passing, respectively, a reaction string and the type of string
57+
(e.g., 'smiles' or 'smarts'), or an rdkit ChemicalReaction object.
5458

5559
:class:`~models.ChemicalEquation` objects are characterized by various attributes.
5660
The ``catalog`` attribute stores the instances of the Molecule objects involved in the reaction
@@ -65,6 +69,10 @@ The ``rdrxn`` attribute, storing the rdkit ChemicalReaction object associated wi
6569
can be used to compute reaction properties and fingerprints. The ``smiles`` attribute
6670
contains the smiles string associated with the ChemicalEquation instance.
6771

72+
If the object used to instantiate the new :class:`~models.ChemicalEquation` instance contains
73+
the atom mapping information, three additional attributes will also be created:
74+
``mapping``, ``disconnection`` and ``template``.
75+
6876

6977
.. code-block:: python
7078

docs/source/code_customization/code_customization_translate.rst

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ Implementing a new input format
5151
In order to include a new input format among those that LinChemIn can 'read', you
5252
firstly need to create a new subclass of the abstract class
5353
:class:`~linchemin.cgu.translate.AbsTranslator` in the :mod:`~linchemin.cgu.translate` module.
54+
The new subclass should also be decorated with the ``@TranslatorFactory.register_format_translator``
55+
decorator: it is used by the :class:`~linchemin.cgu.translate.TranslatorFactory` to register
56+
the new translator among the available ones. The decorator takes two arguments: the name that will be used
57+
to select the translator and a brief description that will appear in the heper functions.
5458

5559
.. code-block:: python
5660
61+
@TranslatorFactory.register_format_translator("new_input", "brief description")
5762
class TranslatorNewInputFormat(AbsTranslator):
5863
""" Translator subclass to handle translations from NewInputFormat objects """
5964
as_input = None
@@ -76,14 +81,15 @@ objects, not list of objects.
7681
If you need more information regarding the Iron format, you can have a look at the
7782
:ref:`Iron <iron_link>` description.
7883
You should also set the ``as_input`` attribute of the subclass to ``implemented``, so that
79-
the new format will appear as available in the helper function.
84+
the new format will appear as available input format in the helper function.
8085

8186

8287
When the code will be implemented you will have something similar
8388
to this:
8489

8590
.. code-block:: python
8691
92+
@TranslatorFactory.register_format_translator("new_input", "brief description")
8793
class TranslatorNewInputFormat(AbsTranslator):
8894
""" Translator subclass to handle translations from NewInputFormat objects """
8995
as_input = 'implemented'
@@ -96,29 +102,12 @@ to this:
96102
# some super cool code
97103
return iron_graph
98104
99-
The last step is to add the 'name' of your new format in the ``translators`` dictionary
100-
of :class:`~linchemin.cgu.translate.TranslatorFactory`, to make it available to the factory.
101105
102-
.. code-block:: python
103106
104-
translators = {
105-
'networkx': {'value': TranslatorNetworkx, 'info': 'Translating from/into Networkx objects'},
106-
'pydot': {'value': TranslatorDot, 'info': 'Translating from/into Pydot objects'},
107-
'ibm_retro': {'value': TranslatorIbm, 'info': 'Translating from outputs generated by the IBMRXN CASP tool'},
108-
'az_retro': {'value': TranslatorAz,
109-
'info': 'Translating from outputs generated by the AiZynthFinder CASP tool'},
110-
'mit_retro': {'value': TranslatorMit,
111-
'info': 'Translating from outputs generated by the Askos CASP tool'},
112-
'syngraph': {'value': None,
113-
'info': 'Translating from/into SynGraph objects'},
114-
'pydot_visualization': {'value': TranslatorDotVisualization,
115-
'info': 'Creates PNG pictures of the input routes'},
116-
'iron': {'value': None, 'info': 'Translating from/into a list of Iron objects'},
117-
'noc': {'value': TranslatorNOC,
118-
'info': 'Translating to a format compatible with a Network of Organic Chemistry'},
119-
'new_input': {'value': TranslatorNewInputFormat,
120-
'info': 'Brief description that will appear in the helper function'}
121-
}
107+
108+
All the available formats are stored in the ``_formats`` attributes of the
109+
:class:`~linchemin.cgu.translate.TranslatorFactory` class. As previously mentioned, the factory can
110+
self-register new options via the decorator.
122111

123112
That's it, you are all done! Now your newly developed format is available to all the LinChemIn
124113
functionalities that use the
@@ -152,6 +141,7 @@ return a graph object in the new format.
152141

153142
.. code-block:: python
154143
144+
@TranslatorFactory.register_format_translator("new_output", "brief description")
155145
class TranslatorNewOutputFormat(AbsTranslator):
156146
""" Translator subclass to handle translations from NewOutputFormat objects """
157147
as_input = None

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
autosummary_generate = True
2323

24-
version = "2.0.3"
24+
version = "2.2.5"
2525
# The full version, including dev info
2626
release = version.replace("_", "")
2727

docs/source/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Contents
3131
data_structure
3232
chemical_objects_classes
3333
atom_mapping
34+
route_sanity_check
35+
manual_manipulation
3436
reference/index
3537

3638
License
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Manual Route Manipulation
2+
==========================
3+
4+
5+
Being able to manipulate the predicted routes means that you can include your domain knowledge directly into
6+
the output of the models!
7+
LinChemIn allows you to perform various operations on single and multiple routes
8+
9+
.. currentmodule:: linchemin.cgu.syngraph_operations
10+
11+
Node Removal
12+
---------------
13+
If looking at the predicted route(s) you realize that are some molecules or chemical reactions
14+
that you are not interested in, that re various functions and methods that you can use.
15+
16+
If you just want to remove a single node from a route, you can use the
17+
:meth:`~linchemin.cgu.syngraph.remove_node` method, which is available for all types of SynGraph.
18+
However, you need to build the :class:`~linchemin.cheminfo.models.Molecule` or the
19+
:class:`~linchemin.cheminfo.models.ChemicalEquation` instance corresponding to the node to be removed
20+
and use its unique identifier property.
21+
22+
.. code-block:: python
23+
24+
from linchemin.cheminfo.constructors import MoleculeConstructor
25+
26+
smiles_to_remove = 'CC(=O)O' # the smiles of the molecule to be removed
27+
mol_to_remove = MoleculeConstructor().build_from_molecule_string(smiles_to_remove, 'smiles') # the Molecule object is built
28+
syngraph.remove_node(mol_to_remove.uid)
29+
30+
31+
In case you want to remove a reaction node based on its smiles, you can use the
32+
:func:`~linchemin.cgu.syngraph_operations.remove_reaction_from_syngraph` function. In this case, you
33+
can also ask to remove the potential "dangling" nodes that the removal could leave behind.
34+
A new SynGraph object is created.
35+
36+
.. code-block:: python
37+
38+
from linchemin.cgu.syngraph_operations import remove_reaction_from_syngraph
39+
40+
smiles_to_remove = 'CCN.CCOC(=O)CC>>CCNC(=O)CC' # the smiles of the reaction to be removed
41+
new_graph = remove_reaction_from_syngraph(original_syngraph, # the syngraph to be edited
42+
smiles_to_remove, # the smiles of the reaction to be removed
43+
remove_dandling_nodes=True) # whether dandling nodes should be removed
44+
45+
46+
.. currentmodule:: linchemin.cgu.route_mining
47+
48+
Route Mining and Node Addition
49+
----------------------------------
50+
So, you predicted a nice set of routes for a target,
51+
but checking them, you notice that
52+
a particular reaction or a sequence of reactions that you think might be very useful
53+
is not included in any of them.
54+
55+
No worries, you can provide the already existing routes, the smiles of the target molecule and
56+
a list of reactions that you want to add, and will be able to retrieve all
57+
the routes from the obtained tree.
58+
All you need is the :func:`~linchemin.cgu.route_mining.mine_routes` function!
59+
60+
.. code-block:: python
61+
62+
from linchemin.cgu.route_mining import mine_routes
63+
64+
input_list = [route1, route2] # the initial set of routes
65+
root = 'CCC(=O)Nc1ccc(cc1)C(=O)N[C@@H](CO)C(=O)O' # the target molecule for which routes should be retrieved
66+
new_reaction_list = ['CC=O.O=O>>CC(=O)O'] # the reaction(s) to be added
67+
routes = mine_routes(input_list, root, new_reaction_list) # all the mined routes
68+
69+
The input routes should be instances of any :class:`~linchemin.cgu.syngraph.SynGraph` subclasses
70+
and the output routes
71+
will be :class:`~linchemin.cgu.syngraph.MonopartiteReacSynGraph` objects.

docs/source/reference/generated/linchemin.cgu.syngraph.BipartiteSynGraph.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
.. autosummary::
1515

1616
~BipartiteSynGraph.__init__
17+
~BipartiteSynGraph.add_molecular_roots
1718
~BipartiteSynGraph.add_node
1819
~BipartiteSynGraph.add_nodes_sequence
20+
~BipartiteSynGraph.build_chemical_equations
1921
~BipartiteSynGraph.builder_from_iron
2022
~BipartiteSynGraph.builder_from_reaction_list
23+
~BipartiteSynGraph.find_reactants_products
2124
~BipartiteSynGraph.get_leaves
2225
~BipartiteSynGraph.get_roots
26+
~BipartiteSynGraph.get_unique_nodes
27+
~BipartiteSynGraph.initialize_with_iron
28+
~BipartiteSynGraph.remove_isolated_ces
29+
~BipartiteSynGraph.remove_node
2330
~BipartiteSynGraph.set_source
2431

2532

docs/source/reference/generated/linchemin.cgu.syngraph.MonopartiteMolSynGraph.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
.. autosummary::
1515

1616
~MonopartiteMolSynGraph.__init__
17+
~MonopartiteMolSynGraph.add_molecular_roots
1718
~MonopartiteMolSynGraph.add_node
19+
~MonopartiteMolSynGraph.build_chemical_equations
1820
~MonopartiteMolSynGraph.builder_from_iron
1921
~MonopartiteMolSynGraph.builder_from_reaction_list
22+
~MonopartiteMolSynGraph.find_reactants_products
2023
~MonopartiteMolSynGraph.get_leaves
2124
~MonopartiteMolSynGraph.get_roots
25+
~MonopartiteMolSynGraph.get_unique_nodes
26+
~MonopartiteMolSynGraph.initialize_with_iron
27+
~MonopartiteMolSynGraph.remove_node
2228
~MonopartiteMolSynGraph.set_source
2329

2430

docs/source/reference/generated/linchemin.cgu.syngraph.MonopartiteReacSynGraph.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
.. autosummary::
1515

1616
~MonopartiteReacSynGraph.__init__
17+
~MonopartiteReacSynGraph.add_molecular_roots
1718
~MonopartiteReacSynGraph.add_node
19+
~MonopartiteReacSynGraph.build_chemical_equations
1820
~MonopartiteReacSynGraph.builder_from_iron
1921
~MonopartiteReacSynGraph.builder_from_reaction_list
22+
~MonopartiteReacSynGraph.find_reactants_products
2023
~MonopartiteReacSynGraph.get_leaves
2124
~MonopartiteReacSynGraph.get_molecule_leaves
2225
~MonopartiteReacSynGraph.get_molecule_roots
2326
~MonopartiteReacSynGraph.get_roots
27+
~MonopartiteReacSynGraph.get_unique_nodes
28+
~MonopartiteReacSynGraph.initialize_with_iron
29+
~MonopartiteReacSynGraph.remove_isolated_ces
30+
~MonopartiteReacSynGraph.remove_node
2431
~MonopartiteReacSynGraph.set_source
2532

2633

docs/source/reference/generated/linchemin.cgu.syngraph.SynGraph.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
.. autosummary::
1515

1616
~SynGraph.__init__
17+
~SynGraph.add_molecular_roots
1718
~SynGraph.add_node
19+
~SynGraph.build_chemical_equations
1820
~SynGraph.builder_from_iron
1921
~SynGraph.builder_from_reaction_list
22+
~SynGraph.find_reactants_products
2023
~SynGraph.get_leaves
2124
~SynGraph.get_roots
25+
~SynGraph.get_unique_nodes
26+
~SynGraph.initialize_with_iron
27+
~SynGraph.remove_node
2228
~SynGraph.set_source
2329

2430

docs/source/reference/generated/linchemin.cgu.translate.AbsTranslator.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
.. autosummary::
1515

1616
~AbsTranslator.__init__
17+
~AbsTranslator.build_iron_node
1718
~AbsTranslator.from_iron
19+
~AbsTranslator.get_node_info
1820
~AbsTranslator.to_iron
1921

2022

0 commit comments

Comments
 (0)