dgllife.utils.CanonicalBondFeaturizer

class dgllife.utils.CanonicalBondFeaturizer(bond_data_field='e', self_loop=False)[source]

A default featurizer for bonds.

The bond features include: * One hot encoding of the bond type. The supported bond types include

SINGLE, DOUBLE, TRIPLE, AROMATIC.

  • Whether the bond is conjugated..

  • Whether the bond is in a ring of any size.

  • One hot encoding of the stereo configuration of a bond. The supported bond stereo configurations include STEREONONE, STEREOANY, STEREOZ, STEREOE, STEREOCIS, STEREOTRANS.

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

Parameters
  • bond_data_field (str) – Name for storing bond features in DGLGraphs, default to 'e'.

  • self_loop (bool) – Whether self loops will be added. Default to False. If True, it will use an additional column of binary values to indicate the identity of self loops. The feature of the self loops will be zero except for the additional column.

Examples

>>> from dgllife.utils import CanonicalBondFeaturizer
>>> from rdkit import Chem
>>> mol = Chem.MolFromSmiles('CCO')
>>> bond_featurizer = CanonicalBondFeaturizer(bond_data_field='feat')
>>> bond_featurizer(mol)
{'feat': tensor([[1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.]])}
>>> # Get feature size
>>> bond_featurizer.feat_size('feat')
12

# Featurization with self loops to add >>> bond_featurizer = CanonicalBondFeaturizer(bond_data_field=’feat’, self_loop=True) >>> bond_featurizer(mol) {‘feat’: tensor([[1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],

[1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])}

>>> # Get feature size
>>> bond_featurizer.feat_size('feat')
13

See also

BaseBondFeaturizer, WeaveEdgeFeaturizer, PretrainBondFeaturizer, AttentiveFPBondFeaturizer, PAGTNEdgeFeaturizer

__init__(bond_data_field='e', self_loop=False)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([bond_data_field, self_loop])

Initialize self.

feat_size([feat_name])

Get the feature size for feat_name.