chemprop.featurizers.molgraph
=============================

.. py:module:: chemprop.featurizers.molgraph


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/chemprop/featurizers/molgraph/cache/index
   /autoapi/chemprop/featurizers/molgraph/mixins/index
   /autoapi/chemprop/featurizers/molgraph/molecule/index
   /autoapi/chemprop/featurizers/molgraph/reaction/index


Attributes
----------

.. autoapisummary::

   chemprop.featurizers.molgraph.CGRFeaturizer


Classes
-------

.. autoapisummary::

   chemprop.featurizers.molgraph.MolGraphCache
   chemprop.featurizers.molgraph.MolGraphCacheFacade
   chemprop.featurizers.molgraph.MolGraphCacheOnTheFly
   chemprop.featurizers.molgraph.CuikmolmakerMolGraphFeaturizer
   chemprop.featurizers.molgraph.SimpleMoleculeMolGraphFeaturizer
   chemprop.featurizers.molgraph.CondensedGraphOfReactionFeaturizer
   chemprop.featurizers.molgraph.RxnMode


Package Contents
----------------

.. py:class:: MolGraphCache(inputs, V_fs, E_fs, featurizer, n_workers = 0)

   Bases: :py:obj:`MolGraphCacheFacade`


   A :class:`MolGraphCache` precomputes the corresponding
   :class:`~chemprop.data.molgraph.MolGraph`\s and caches them in memory.


   .. py:method:: __len__()


   .. py:method:: __getitem__(index)


.. py:class:: MolGraphCacheFacade(inputs, V_fs, E_fs, featurizer)

   Bases: :py:obj:`collections.abc.Sequence`\ [\ :py:obj:`chemprop.data.molgraph.MolGraph`\ ], :py:obj:`Generic`\ [\ :py:obj:`chemprop.featurizers.base.S`\ ]


   A :class:`MolGraphCacheFacade` provided an interface for caching
   :class:`~chemprop.data.molgraph.MolGraph`\s.

   .. note::
       This class only provides a facade for a cached dataset, but it *does not guarantee*
       whether the underlying data is truly cached.


   :param inputs: The inputs to be featurized.
   :type inputs: Iterable[S]
   :param V_fs: The node features for each input.
   :type V_fs: Iterable[np.ndarray]
   :param E_fs: The edge features for each input.
   :type E_fs: Iterable[np.ndarray]
   :param featurizer: The featurizer with which to generate the
                      :class:`~chemprop.data.molgraph.MolGraph`\s.
   :type featurizer: Featurizer[S, MolGraph]


.. py:class:: MolGraphCacheOnTheFly(inputs, V_fs, E_fs, featurizer)

   Bases: :py:obj:`MolGraphCacheFacade`


   A :class:`MolGraphCacheOnTheFly` computes the corresponding
   :class:`~chemprop.data.molgraph.MolGraph`\s as they are requested.


   .. py:method:: __len__()


   .. py:method:: __getitem__(index)


.. py:class:: CuikmolmakerMolGraphFeaturizer

   Bases: :py:obj:`chemprop.featurizers.base.Featurizer`\ [\ :py:obj:`list`\ [\ :py:obj:`str`\ ]\ , :py:obj:`BatchCuikMolGraph`\ ]


   A :class:`CuikmolmakerMolGraphFeaturizer` featurizes a list of molecules at once instead of
   one molecule at a time for efficiency.

   :param atom_featurizer_mode: The mode of the atom featurizer (V1, V2, ORGANIC, RIGR) to use.
   :type atom_featurizer_mode: str, default="V2"
   :param extra_atom_fdim: the dimension of the additional features that will be concatenated onto the calculated
                           features of each atom
   :type extra_atom_fdim: int, default=0
   :param extra_bond_fdim: the dimension of the additional features that will be concatenated onto the calculated
                           features of each bond
   :type extra_bond_fdim: int, default=0
   :param add_h: whether to add hydrogens to the `Chem.Mol` objects created from the input SMILES strings
   :type add_h: bool, default=False


   .. py:attribute:: atom_featurizer_mode
      :type:  Literal['V1', 'V2', 'ORGANIC', 'RIGR']
      :value: 'V2'



   .. py:attribute:: extra_atom_fdim
      :type:  int
      :value: 0



   .. py:attribute:: extra_bond_fdim
      :type:  int
      :value: 0



   .. py:attribute:: add_h
      :type:  bool
      :value: False



   .. py:attribute:: atom_fdim
      :type:  int


   .. py:attribute:: bond_fdim
      :type:  int


   .. py:method:: __post_init__()


   .. py:method:: __call__(smiles_list, atom_features_extra = None, bond_features_extra = None)

      featurize an input



.. py:class:: SimpleMoleculeMolGraphFeaturizer

   Bases: :py:obj:`chemprop.featurizers.molgraph.mixins._MolGraphFeaturizerMixin`, :py:obj:`chemprop.featurizers.base.GraphFeaturizer`\ [\ :py:obj:`rdkit.Chem.Mol`\ ]


   A :class:`SimpleMoleculeMolGraphFeaturizer` is the default implementation of a
   :class:`MoleculeMolGraphFeaturizer`

   :param atom_featurizer: the featurizer with which to calculate feature representations of the atoms in a given
                           molecule
   :type atom_featurizer: AtomFeaturizer, default=MultiHotAtomFeaturizer()
   :param bond_featurizer: the featurizer with which to calculate feature representations of the bonds in a given
                           molecule
   :type bond_featurizer: BondFeaturizer, default=MultiHotBondFeaturizer()
   :param extra_atom_fdim: the dimension of the additional features that will be concatenated onto the calculated
                           features of each atom
   :type extra_atom_fdim: int, default=0
   :param extra_bond_fdim: the dimension of the additional features that will be concatenated onto the calculated
                           features of each bond
   :type extra_bond_fdim: int, default=0


   .. py:attribute:: extra_atom_fdim
      :type:  int
      :value: 0



   .. py:attribute:: extra_bond_fdim
      :type:  int
      :value: 0



   .. py:method:: __post_init__()


   .. py:method:: __call__(mol, atom_features_extra = None, bond_features_extra = None)


.. py:type:: CGRFeaturizer
   :canonical: CondensedGraphOfReactionFeaturizer


.. py:class:: CondensedGraphOfReactionFeaturizer

   Bases: :py:obj:`chemprop.featurizers.molgraph.mixins._MolGraphFeaturizerMixin`, :py:obj:`chemprop.featurizers.base.GraphFeaturizer`\ [\ :py:obj:`chemprop.types.Rxn`\ ]


   A :class:`CondensedGraphOfReactionFeaturizer` featurizes reactions using the condensed
   reaction graph method utilized in [1]_

   **NOTE**: This class *does not* accept a :class:`AtomFeaturizer` instance. This is because
   it requries the :meth:`num_only()` method, which is only implemented in the concrete
   :class:`AtomFeaturizer` class

   :param atom_featurizer: the featurizer with which to calculate feature representations of the atoms in a given
                           molecule
   :type atom_featurizer: AtomFeaturizer, default=AtomFeaturizer()
   :param bond_featurizer: the featurizer with which to calculate feature representations of the bonds in a given
                           molecule
   :type bond_featurizer: BondFeaturizerBase, default=BondFeaturizer()
   :param mode_: the mode by which to featurize the reaction as either the string code or enum value
   :type mode_: Union[str, ReactionMode], default=ReactionMode.REAC_DIFF

   .. rubric:: References

   .. [1] Heid, E.; Green, W.H. "Machine Learning of Reaction Properties via Learned
       Representations of the Condensed Graph of Reaction." J. Chem. Inf. Model. 2022, 62,
       2101-2110. https://doi.org/10.1021/acs.jcim.1c00975


   .. py:attribute:: mode_
      :type:  dataclasses.InitVar[str | RxnMode]


   .. py:method:: __post_init__(mode_)


   .. py:property:: mode
      :type: RxnMode



   .. py:method:: __call__(rxn, atom_features_extra = None, bond_features_extra = None)

      Featurize the input reaction into a molecular graph

      :param rxn: a 2-tuple of atom-mapped rdkit molecules, where the 0th element is the reactant and the
                  1st element is the product
      :type rxn: Rxn
      :param atom_features_extra: *UNSUPPORTED* maintained only to maintain parity with the method signature of the
                                  `MoleculeFeaturizer`
      :type atom_features_extra: np.ndarray | None, default=None
      :param bond_features_extra: *UNSUPPORTED* maintained only to maintain parity with the method signature of the
                                  `MoleculeFeaturizer`
      :type bond_features_extra: np.ndarray | None, default=None

      :returns: the molecular graph of the reaction
      :rtype: MolGraph



   .. py:method:: map_reac_to_prod(reacs, pdts)
      :classmethod:


      Map atom indices between corresponding atoms in the reactant and product molecules

      :param reacs: An RDKit molecule of the reactants
      :type reacs: Chem.Mol
      :param pdts: An RDKit molecule of the products
      :type pdts: Chem.Mol

      :returns: * **ri2pi** (*dict[int, int]*) -- A dictionary of corresponding atom indices from reactant atoms to product atoms
                * **pdt_idxs** (*list[int]*) -- atom indices of poduct atoms
                * **rct_idxs** (*list[int]*) -- atom indices of reactant atoms



.. py:class:: RxnMode

   Bases: :py:obj:`chemprop.utils.utils.EnumMapping`


   The mode by which a reaction should be featurized into a `MolGraph`


   .. py:attribute:: REAC_PROD

      concatenate the reactant features with the product features.


   .. py:attribute:: REAC_PROD_BALANCE

      concatenate the reactant features with the products feature and balances imbalanced
      reactions


   .. py:attribute:: REAC_DIFF

      concatenates the reactant features with the difference in features between reactants and
      products


   .. py:attribute:: REAC_DIFF_BALANCE

      concatenates the reactant features with the difference in features between reactants and
      product and balances imbalanced reactions


   .. py:attribute:: PROD_DIFF

      concatenates the product features with the difference in features between reactants and
      products


   .. py:attribute:: PROD_DIFF_BALANCE

      concatenates the product features with the difference in features between reactants and
      products and balances imbalanced reactions


