Skip to content

Base featurizer

BaseAtomFeaturizer

Bases: ABC

Abstract base featurizer class for all atom featurization classes.

Source code in bionemo/geometric/base_featurizer.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class BaseAtomFeaturizer(ABC):
    """Abstract base featurizer class for all atom featurization classes."""

    @abstractproperty
    def n_dim(self) -> int:
        """Number of dimensions of computed feature."""
        ...

    @abstractmethod
    def get_atom_features(self):
        """Computes atom features."""
        ...

    def __call__(self, mol: Mol, atom_indices: Optional[Iterable] = None) -> list[int]:
        """Returns computed atom features."""
        return self.get_atom_features(mol, atom_indices)

__call__(mol, atom_indices=None)

Returns computed atom features.

Source code in bionemo/geometric/base_featurizer.py
37
38
39
def __call__(self, mol: Mol, atom_indices: Optional[Iterable] = None) -> list[int]:
    """Returns computed atom features."""
    return self.get_atom_features(mol, atom_indices)

get_atom_features() abstractmethod

Computes atom features.

Source code in bionemo/geometric/base_featurizer.py
32
33
34
35
@abstractmethod
def get_atom_features(self):
    """Computes atom features."""
    ...

n_dim()

Number of dimensions of computed feature.

Source code in bionemo/geometric/base_featurizer.py
27
28
29
30
@abstractproperty
def n_dim(self) -> int:
    """Number of dimensions of computed feature."""
    ...

BaseBondFeaturizer

Bases: ABC

Abstract base featurizer class for all bond featurization classes.

Source code in bionemo/geometric/base_featurizer.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class BaseBondFeaturizer(ABC):
    """Abstract base featurizer class for all bond featurization classes."""

    @abstractproperty
    def n_dim(self) -> int:
        """Number of dimensions of computed feature."""
        ...

    @abstractmethod
    def get_bond_features(self):
        """Computes bond features."""
        ...

    def __call__(self, mol: Mol, bond_indices: Optional[Iterable] = None) -> list[int]:
        """Returns computed bond features."""
        return self.get_bond_features(mol, bond_indices)

__call__(mol, bond_indices=None)

Returns computed bond features.

Source code in bionemo/geometric/base_featurizer.py
55
56
57
def __call__(self, mol: Mol, bond_indices: Optional[Iterable] = None) -> list[int]:
    """Returns computed bond features."""
    return self.get_bond_features(mol, bond_indices)

get_bond_features() abstractmethod

Computes bond features.

Source code in bionemo/geometric/base_featurizer.py
50
51
52
53
@abstractmethod
def get_bond_features(self):
    """Computes bond features."""
    ...

n_dim()

Number of dimensions of computed feature.

Source code in bionemo/geometric/base_featurizer.py
45
46
47
48
@abstractproperty
def n_dim(self) -> int:
    """Number of dimensions of computed feature."""
    ...

BaseMoleculeFeaturizer

Bases: ABC

Abstract base featurizer class for molecule featurization classes.

Source code in bionemo/geometric/base_featurizer.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class BaseMoleculeFeaturizer(ABC):
    """Abstract base featurizer class for molecule featurization classes."""

    @abstractproperty
    def n_dim(self) -> int:
        """Number of dimensions of computed feature."""
        ...

    @abstractmethod
    def get_molecule_features(self, mol: Mol) -> torch.Tensor:
        """Computes molecule features."""
        ...

    def __call__(self, mol: Mol) -> torch.Tensor:
        """Returns computed molecule features."""
        return self.get_molecule_features(mol)

__call__(mol)

Returns computed molecule features.

Source code in bionemo/geometric/base_featurizer.py
73
74
75
def __call__(self, mol: Mol) -> torch.Tensor:
    """Returns computed molecule features."""
    return self.get_molecule_features(mol)

get_molecule_features(mol) abstractmethod

Computes molecule features.

Source code in bionemo/geometric/base_featurizer.py
68
69
70
71
@abstractmethod
def get_molecule_features(self, mol: Mol) -> torch.Tensor:
    """Computes molecule features."""
    ...

n_dim()

Number of dimensions of computed feature.

Source code in bionemo/geometric/base_featurizer.py
63
64
65
66
@abstractproperty
def n_dim(self) -> int:
    """Number of dimensions of computed feature."""
    ...

get_boolean_atomic_prop(atom, prop_list=None)

Retrieves boolean atomic properties for a given atom.

This function fetches boolean properties of an atom. If a specific list of properties is provided, it retrieves those properties. Otherwise, it fetches all available boolean properties for the atom.

Parameters:

Name Type Description Default
atom Atom

The atom object to retrieve properties from.

required
prop_list list

A list of specific property names to retrieve. If None, all available properties will be fetched. Defaults to None.

None

Returns:

Name Type Description
list list[bool]

A list of boolean values corresponding to the requested properties.

Source code in bionemo/geometric/base_featurizer.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def get_boolean_atomic_prop(atom: Atom, prop_list=None) -> list[bool]:
    """Retrieves boolean atomic properties for a given atom.

    This function fetches boolean properties of an atom. If a specific list of
    properties is provided, it retrieves those properties. Otherwise, it fetches
    all available boolean properties for the atom.

    Args:
        atom: The atom object to retrieve properties from.
        prop_list (list, optional): A list of specific property names to retrieve.
            If None, all available properties will be fetched. Defaults to None.

    Returns:
        list: A list of boolean values corresponding to the requested properties.
    """
    _prop_list = prop_list if prop_list else atom.GetPropNames()

    return [atom.GetBoolProp(prop) for prop in _prop_list]

get_double_atomic_prop(atom, prop_list=None)

Retrieves double atomic properties for a given atom.

This function fetches double properties of an atom. If a specific list of properties is provided, it retrieves those properties. Otherwise, it fetches all available double properties for the atom.

Parameters:

Name Type Description Default
atom

The atom object to retrieve properties from.

required
prop_list list

A list of specific property names to retrieve. If None, all available properties will be fetched. Defaults to None.

None

Returns:

Name Type Description
list list[float]

A list of float values corresponding to the requested properties.

Source code in bionemo/geometric/base_featurizer.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def get_double_atomic_prop(atom, prop_list=None) -> list[float]:
    """Retrieves double atomic properties for a given atom.

    This function fetches double properties of an atom. If a specific list of
    properties is provided, it retrieves those properties. Otherwise, it fetches
    all available double properties for the atom.

    Args:
        atom: The atom object to retrieve properties from.
        prop_list (list, optional): A list of specific property names to retrieve.
            If None, all available properties will be fetched. Defaults to None.

    Returns:
        list: A list of float values corresponding to the requested properties.
    """
    if prop_list is not None:
        _prop_list = prop_list
    else:
        _prop_list = atom.GetPropNames()

    return [atom.GetDoubleProp(prop) for prop in _prop_list]

one_hot_enc(val, num_class)

Performs one-hot encoding on an integer value.

This function creates a one-hot encoded representation of the input value as a list of boolean values. The resulting list has a length equal to num_class, where only the element at index val is set to True.

Parameters:

Name Type Description Default
val int

An integer representing the value to be one-hot encoded. Must be in the range [0, num_class - 1].

required
num_class int

An integer representing the total number of classes or possible classes.

required

Returns:

Type Description
list[bool]

One-hot encoding of val.

Source code in bionemo/geometric/base_featurizer.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def one_hot_enc(val: int, num_class: int) -> list[bool]:
    """Performs one-hot encoding on an integer value.

    This function creates a one-hot encoded representation of the input value
    as a list of boolean values. The resulting list has a length equal to
    `num_class`, where only the element at index `val` is set to True.

    Args:
        val (int): An integer representing the value to be one-hot encoded.
            Must be in the range [0, num_class - 1].
        num_class (int): An integer representing the total number of classes or
            possible classes.

    Returns:
        One-hot encoding of `val`.
    """
    one_hot = [False] * num_class
    one_hot[val] = True
    return one_hot