跳到内容

分子特征化器

RDkit2DDescriptorFeaturizer

基类: BaseMoleculeFeaturizer

用于通过计算 RDkit 描述符来特征化分子的类。

典型用法示例:rdf = RDkit2DDescriptorFeaturizer() rdf(Chem.MolFromSmiles("CCO"))

源代码位于 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

返回计算出的特征的维度。

__init__()

初始化 RDkit2DDescriptorFeaturizer 类。

源代码位于 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)

返回分子的特征。

参数

名称 类型 描述 默认
mol Mol

一个 RDkit Chem.Mol 对象

必需

返回值: 一个 torch.tensor,表示分子 RDkit 计算的 2D 描述符。

源代码位于 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])