Skip to content

Molecule featurizers

RDkit2DDescriptorFeaturizer

Bases: BaseMoleculeFeaturizer

Class for featurizing molecule by computed RDkit descriptors.

Typical usage example: rdf = RDkit2DDescriptorFeaturizer() rdf(Chem.MolFromSmiles("CCO"))

Source code in bionemo/geometric/molecule_featurizers.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class RDkit2DDescriptorFeaturizer(BaseMoleculeFeaturizer):
    """Class for featurizing molecule by computed RDkit descriptors.

    Typical usage example:
    rdf = RDkit2DDescriptorFeaturizer()
    rdf(Chem.MolFromSmiles("CCO"))
    """

    def __init__(self) -> None:
        """Initializes RDkit2DDescriptorFeaturizer class."""
        self.n_rdkit_descriptors = len(Descriptors.descList)

    @property
    def n_dim(self) -> int:
        """Returns dimensionality of the computed features."""
        return self.n_rdkit_descriptors

    def get_molecule_features(self, mol: Mol) -> torch.Tensor:
        """Returns features of the molecule.

        Args:
            mol: An RDkit Chem.Mol object

        Returns:
        A torch.tensor representing RDkit-computed 2D descriptors of the molecule.
        """
        return torch.Tensor([f(mol) for desc_name, f in Descriptors.descList])

n_dim: int property

Returns dimensionality of the computed features.

__init__()

Initializes RDkit2DDescriptorFeaturizer class.

Source code in bionemo/geometric/molecule_featurizers.py
33
34
35
def __init__(self) -> None:
    """Initializes RDkit2DDescriptorFeaturizer class."""
    self.n_rdkit_descriptors = len(Descriptors.descList)

get_molecule_features(mol)

Returns features of the molecule.

Parameters:

Name Type Description Default
mol Mol

An RDkit Chem.Mol object

required

Returns: A torch.tensor representing RDkit-computed 2D descriptors of the molecule.

Source code in bionemo/geometric/molecule_featurizers.py
42
43
44
45
46
47
48
49
50
51
def get_molecule_features(self, mol: Mol) -> torch.Tensor:
    """Returns features of the molecule.

    Args:
        mol: An RDkit Chem.Mol object

    Returns:
    A torch.tensor representing RDkit-computed 2D descriptors of the molecule.
    """
    return torch.Tensor([f(mol) for desc_name, f in Descriptors.descList])