class dgl.data.chem.BaseBondFeaturizer(**kwargs)[source]

An abstract class for bond featurizers. Loop over all bonds in a molecule and featurize them with the featurizer_funcs. We assume the constructed DGLGraph is a bi-directed graph where the i th bond in the molecule, i.e. mol.GetBondWithIdx(i), corresponds to the (2i)-th and (2i+1)-th edges in the DGLGraph.

We assume the resulting DGLGraph will be created with :func:`smiles_to_bigraph` without self loops.

  • featurizer_funcs (dict) – Mapping feature name to the featurization function. Each function is of signature func(rdkit.Chem.rdchem.Bond) -> list or 1D numpy array.
  • feat_sizes (dict) – Mapping feature name to the size of the corresponding feature. If None, they will be computed when needed. Default: None.


>>> from dgl.data.chem import BaseBondFeaturizer, bond_type_one_hot, bond_is_in_ring
>>> from rdkit import Chem
>>> mol = Chem.MolFromSmiles('CCO')
>>> bond_featurizer = BaseBondFeaturizer({'bond_type': bond_type_one_hot, 'in_ring': bond_is_in_ring})
>>> bond_featurizer(mol)
{'bond_type': tensor([[1., 0., 0., 0.],
                      [1., 0., 0., 0.],
                      [1., 0., 0., 0.],
                      [1., 0., 0., 0.]]),
 'in_ring': tensor([[0.], [0.], [0.], [0.]])}


feat_size(feat_name) Get the feature size for feat_name.