dgllife.utils.mol_to_graph

dgllife.utils.mol_to_graph(mol, graph_constructor, node_featurizer, edge_featurizer, canonical_atom_order, explicit_hydrogens=False, num_virtual_nodes=0)[source]

Convert an RDKit molecule object into a DGLGraph and featurize for it.

This function can be used to construct any arbitrary DGLGraph from an RDKit molecule instance.

Parameters
  • mol (rdkit.Chem.rdchem.Mol) – RDKit molecule holder

  • graph_constructor (callable) – Takes an RDKit molecule as input and returns a DGLGraph

  • node_featurizer (callable, rdkit.Chem.rdchem.Mol -> dict) – Featurization for nodes like atoms in a molecule, which can be used to update ndata for a DGLGraph.

  • edge_featurizer (callable, rdkit.Chem.rdchem.Mol -> dict) – Featurization for edges like bonds in a molecule, which can be used to update edata for a DGLGraph.

  • canonical_atom_order (bool) – Whether to use a canonical order of atoms returned by RDKit. Setting it to true might change the order of atoms in the graph constructed.

  • explicit_hydrogens (bool) – Whether to explicitly represent hydrogens as nodes in the graph. If True, it will call rdkit.Chem.AddHs(mol). If False, it will do nothing. Default to False.

  • num_virtual_nodes (int) – The number of virtual nodes to add. The virtual nodes will be connected to all real nodes with virtual edges. If the returned graph has any node/edge feature, an additional column of binary values will be used for each feature to indicate the identity of virtual node/edges. The features of the virtual nodes/edges will be zero vectors except for the additional column. Default to 0.

Returns

Converted DGLGraph for the molecule if mol is valid and None otherwise.

Return type

DGLGraph or None