dgllife.utils.AttentiveFPBondFeaturizer

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

The bond featurizer used in AttentiveFP

AttentiveFP is introduced in Pushing the Boundaries of Molecular Representation for Drug Discovery with the Graph Attention Mechanism.

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.

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 AttentiveFPBondFeaturizer
>>> from rdkit import Chem
>>> mol = Chem.MolFromSmiles('CCO')
>>> bond_featurizer = AttentiveFPBondFeaturizer(bond_data_field='feat')
>>> bond_featurizer(mol)
{'feat': tensor([[1., 0., 0., 0., 0., 0., 1., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0.]])}
>>> # Get feature size
>>> bond_featurizer.feat_size('feat')
10
>>> # Featurization with self loops to add
>>> bond_featurizer = AttentiveFPBondFeaturizer(bond_data_field='feat', self_loop=True)
>>> bond_featurizer(mol)
{'feat': tensor([[1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0., 1., 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., 1.],
                 [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
                 [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])}
>>> # Get feature size
>>> bond_featurizer.feat_size('feat')
11
__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.