Featurizers¶
DeepChem contains an extensive collection of featurizers. If you haven’t run into this terminology before, a “featurizer” is chunk of code which transforms raw input data into a processed form suitable for machine learning. Machine learning methods often need data to be prechewed for them to process. Think of this like a mama penguin chewing up food so the baby penguin can digest it easily.
Now if you’ve watched a few introductory deep learning lectures, you might ask, why do we need something like a featurizer? Isn’t part of the promise of deep learning that we can learn patterns directly from raw data?
Unfortunately it turns out that deep learning techniques need
featurizers just like normal machine learning methods do. Arguably,
they are less dependent on sophisticated featurizers and more capable
of learning sophisticated patterns from simpler data. But
nevertheless, deep learning systems can’t simply chew up raw files.
For this reason, deepchem
provides an extensive collection of
featurization methods which we will review on this page.
Featurizer¶
The dc.feat.Featurizer
class is the abstract parent class for all featurizers.

class
deepchem.feat.
Featurizer
[source]¶ Abstract class for calculating a set of features for a datapoint.
This class is abstract and cannot be invoked directly. You’ll likely only interact with this class if you’re a developer. In that case, you might want to make a child class which implements the _featurize method for calculating features for a single datapoints if you’d like to make a featurizer for a new datatype.

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

featurize
(datapoints: Iterable[Any], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for datapoints.
Parameters:  datapoints (Iterable[Any]) – A sequence of objects that you’d like to featurize. Subclassses of Featurizer should instantiate the _featurize method that featurizes objects in the sequence.
 log_every_n (int, default 1000) – Logs featurization progress every log_every_n steps.
Returns: A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

MolecularFeaturizer¶
Molecular Featurizers are those that work with datasets of molecules.

class
deepchem.feat.
MolecularFeaturizer
[source]¶ Abstract class for calculating a set of features for a molecule.
The defining feature of a MolecularFeaturizer is that it uses SMILES strings and RDKit molecule objects to represent small molecules. All other featurizers which are subclasses of this class should plan to process input which comes as smiles strings or RDKit molecules.
Child classes need to implement the _featurize method for calculating features for a single molecule.
Notes
The subclasses of this class require RDKit to be installed.

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

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

Here are some constants that are used by the graph convolutional featurizers for molecules.

class
deepchem.feat.graph_features.
GraphConvConstants
[source]¶ This class defines a collection of constants which are useful for graph convolutions on molecules.

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

bond_fdim_base
= 6¶

intervals
= [1, 6, 48, 384, 1536, 9216, 27648]¶ Possible stereochemistry. We use EZ notation for stereochemistry https://en.wikipedia.org/wiki/E%E2%80%93Z_notation

possible_atom_list
= ['C', 'N', 'O', 'S', 'F', 'P', 'Cl', 'Mg', 'Na', 'Br', 'Fe', 'Ca', 'Cu', 'Mc', 'Pd', 'Pb', 'K', 'I', 'Al', 'Ni', 'Mn']¶ Allowed Numbers of Hydrogens

possible_bond_stereo
= ['STEREONONE', 'STEREOANY', 'STEREOZ', 'STEREOE']¶ Number of different bond types not counting stereochemistry.

possible_chirality_list
= ['R', 'S']¶ The set of all values allowed.

possible_formal_charge_list
= [3, 2, 1, 0, 1, 2, 3]¶ This is a placeholder for documentation. These will be replaced with corresponding values of the rdkit HybridizationType

possible_hybridization_list
= ['SP', 'SP2', 'SP3', 'SP3D', 'SP3D2']¶ Allowed number of radical electrons.

possible_numH_list
= [0, 1, 2, 3, 4]¶ Allowed Valences for Atoms

possible_number_radical_e_list
= [0, 1, 2]¶ Allowed types of Chirality

possible_valence_list
= [0, 1, 2, 3, 4, 5, 6]¶ Allowed Formal Charges for Atoms

reference_lists
= [['C', 'N', 'O', 'S', 'F', 'P', 'Cl', 'Mg', 'Na', 'Br', 'Fe', 'Ca', 'Cu', 'Mc', 'Pd', 'Pb', 'K', 'I', 'Al', 'Ni', 'Mn'], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5, 6], [3, 2, 1, 0, 1, 2, 3], [0, 1, 2], ['SP', 'SP2', 'SP3', 'SP3D', 'SP3D2'], ['R', 'S']]¶ The number of different values that can be taken. See get_intervals()

There are a number of helper methods used by the graph convolutional classes which we document here.

deepchem.feat.graph_features.
one_of_k_encoding
(x, allowable_set)[source]¶ Encodes elements of a provided set as integers.
Parameters:  x (object) – Must be present in allowable_set.
 allowable_set (list) – List of allowable quantities.
Example
>>> import deepchem as dc >>> dc.feat.graph_features.one_of_k_encoding("a", ["a", "b", "c"]) [True, False, False]
Raises: ValueError if x is not in allowable_set.

deepchem.feat.graph_features.
one_of_k_encoding_unk
(x, allowable_set)[source]¶ Maps inputs not in the allowable set to the last element.
Unlike one_of_k_encoding, if x is not in allowable_set, this method pretends that x is the last element of allowable_set.
Parameters:  x (object) – Must be present in allowable_set.
 allowable_set (list) – List of allowable quantities.
Examples
>>> dc.feat.graph_features.one_of_k_encoding_unk("s", ["a", "b", "c"]) [False, False, True]

deepchem.feat.graph_features.
get_intervals
(l)[source]¶ For list of lists, gets the cumulative products of the lengths
Note that we add 1 to the lengths of all lists (to avoid an empty list propagating a 0).
Parameters: l (list of lists) – Returns the cumulative product of these lengths. Examples
>>> dc.feat.graph_features.get_intervals([[1], [1, 2], [1, 2, 3]]) [1, 3, 12]
>>> dc.feat.graph_features.get_intervals([[1], [], [1, 2], [1, 2, 3]]) [1, 1, 3, 12]

deepchem.feat.graph_features.
safe_index
(l, e)[source]¶ Gets the index of e in l, providing an index of len(l) if not found
Parameters:  l (list) – List of values
 e (object) – Object to check whether e is in l
Examples
>>> dc.feat.graph_features.safe_index([1, 2, 3], 1) 0 >>> dc.feat.graph_features.safe_index([1, 2, 3], 7) 3

deepchem.feat.graph_features.
get_feature_list
(atom)[source]¶ Returns a list of possible features for this atom.
Parameters: atom (RDKit.rdchem.Atom) – Atom to get features for Examples
>>> from rdkit import Chem >>> mol = Chem.MolFromSmiles("C") >>> atom = mol.GetAtoms()[0] >>> dc.feat.graph_features.get_feature_list(atom) [0, 4, 4, 3, 0, 2]
Note
This method requires RDKit to be installed.
Returns: features – List of length 6. The ith value in this list provides the index of the atom in the corresponding feature value list. The 6 feature values lists for this function are [GraphConvConstants.possible_atom_list, GraphConvConstants.possible_numH_list, GraphConvConstants.possible_valence_list, GraphConvConstants.possible_formal_charge_list, GraphConvConstants.possible_num_radical_e_list]. Return type: list

deepchem.feat.graph_features.
features_to_id
(features, intervals)[source]¶ Convert list of features into index using spacings provided in intervals
Parameters:  features (list) – List of features as returned by get_feature_list()
 intervals (list) – List of intervals as returned by get_intervals()
Returns: id – The index in a feature vector given by the given set of features.
Return type: int

deepchem.feat.graph_features.
id_to_features
(id, intervals)[source]¶ Given an index in a feature vector, return the original set of features.
Parameters:  id (int) – The index in a feature vector given by the given set of features.
 intervals (list) – List of intervals as returned by get_intervals()
Returns: features – List of features as returned by get_feature_list()
Return type: list

deepchem.feat.graph_features.
atom_to_id
(atom)[source]¶ Return a unique id corresponding to the atom type
Parameters: atom (RDKit.rdchem.Atom) – Atom to convert to ids. Returns: id – The index in a feature vector given by the given set of features. Return type: int
This function helps compute distances between atoms from a given base atom.

deepchem.feat.graph_features.
find_distance
(a1: Any, num_atoms: int, bond_adj_list, max_distance=7) → numpy.ndarray[source]¶ Computes distances from provided atom.
Parameters:  a1 (RDKit atom) – The source atom to compute distances from.
 num_atoms (int) – The total number of atoms.
 bond_adj_list (list of lists) – bond_adj_list[i] is a list of the atom indices that atom i shares a bond with. This list is symmetrical so if j in bond_adj_list[i] then i in bond_adj_list[j].
 max_distance (int, optional (default 7)) – The max distance to search.
Returns: distances – Of shape (num_atoms, max_distance). Provides a onehot encoding of the distances. That is, distances[i] is a onehot encoding of the distance from a1 to atom i.
Return type: np.ndarray
This function is important and computes peratom feature vectors used by graph convolutional featurizers.

deepchem.feat.graph_features.
atom_features
(atom, bool_id_feat=False, explicit_H=False, use_chirality=False)[source]¶ Helper method used to compute peratom feature vectors.
Many different featurization methods compute peratom features such as ConvMolFeaturizer, WeaveFeaturizer. This method computes such features.
Parameters:  bool_id_feat (bool, optional) – Return an array of unique identifiers corresponding to atom type.
 explicit_H (bool, optional) – If true, model hydrogens explicitly
 use_chirality (bool, optional) – If true, use chirality information.
Returns: Return type: np.ndarray of peratom features.
This function computes the bond features used by graph convolutional featurizers.

deepchem.feat.graph_features.
bond_features
(bond, use_chirality=False)[source]¶ Helper method used to compute bond feature vectors.
Many different featurization methods compute bond features such as WeaveFeaturizer. This method computes such features.
Parameters: use_chirality (bool, optional) – If true, use chirality information. Note
This method requires RDKit to be installed.
Returns: bond_feats – Array of bond features. This is a 1D array of length 6 if use_chirality is False else of length 10 with chirality encoded. Return type: np.ndarray
This function computes atomatom features (for atom pairs which may not have bonds between them.)

deepchem.feat.graph_features.
pair_features
(mol: Any, bond_features_map: dict, bond_adj_list: List[T], bt_len: int = 6, graph_distance: bool = True, max_pair_distance: Optional[int] = None) → numpy.ndarray[source]¶ Helper method used to compute atom pair feature vectors.
Many different featurization methods compute atom pair features such as WeaveFeaturizer. Note that atom pair features could be for pairs of atoms which aren’t necessarily bonded to one another.
Parameters:  mol (RDKit Mol) – Molecule to compute features on.
 bond_features_map (dict) – Dictionary that maps pairs of atom ids (say (2, 3) for a bond between atoms 2 and 3) to the features for the bond between them.
 bond_adj_list (list of lists) – bond_adj_list[i] is a list of the atom indices that atom i shares a bond with . This list is symmetrical so if j in bond_adj_list[i] then i in bond_adj_list[j].
 bt_len (int, optional (default 6)) – The number of different bond types to consider.
 graph_distance (bool, optional (default True)) – If true, use graph distance between molecules. Else use euclidean distance. The specified mol must have a conformer. Atomic positions will be retrieved by calling mol.getConformer(0).
 max_pair_distance (Optional[int], (default None)) – This value can be a positive integer or None. This parameter determines the maximum graph distance at which pair features are computed. For example, if max_pair_distance==2, then pair features are computed only for atoms at most graph distance 2 apart. If max_pair_distance is None, all pairs are considered (effectively infinite max_pair_distance)
Note
This method requires RDKit to be installed.
Returns:  features (np.ndarray) – Of shape (N_edges, bt_len + max_distance + 1). This is the array of pairwise features for all atom pairs, where N_edges is the number of edges within max_pair_distance of one another in this molecules.
 pair_edges (np.ndarray) – Of shape (2, num_pairs) where num_pairs is the total number of pairs within max_pair_distance of one another.
ConvMolFeaturizer¶

class
deepchem.feat.
ConvMolFeaturizer
(master_atom=False, use_chirality=False, atom_properties=[])[source]¶ This class implements the featurization to implement Duvenaud graph convolutions.
Duvenaud graph convolutions [1]_ construct a vector of descriptors for each atom in a molecule. The featurizer computes that vector of local descriptors.
References
[1] Duvenaud, David K., et al. “Convolutional networks on graphs for learning molecular fingerprints.” Advances in neural information processing systems. 2015. Note
This class requires RDKit to be installed.

__init__
(master_atom=False, use_chirality=False, atom_properties=[])[source]¶ Parameters:  master_atom (Boolean) – if true create a fake atom with bonds to every other atom. the initialization is the mean of the other atom features in the molecule. This technique is briefly discussed in Neural Message Passing for Quantum Chemistry https://arxiv.org/pdf/1704.01212.pdf
 use_chirality (Boolean) – if true then make the resulting atom features aware of the chirality of the molecules in question
 atom_properties (list of string or None) – properties in the RDKit Mol object to use as additional atomlevel features in the larger molecular feature. If None, then no atomlevel properties are used. Properties should be in the RDKit mol object should be in the form atom XXXXXXXX NAME where XXXXXXXX is a zeropadded 8 digit number coresponding to the zeroindexed atom index of each atom and NAME is the name of the property provided in atom_properties. So “atom 00000000 sasa” would be the name of the molecule level property in mol where the solvent accessible surface area of atom 0 would be stored.
 ConvMol is an object and not a numpy array, need to set dtype to (Since) –
 object. –

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

WeaveFeaturizer¶

class
deepchem.feat.
WeaveFeaturizer
(graph_distance: bool = True, explicit_H: bool = False, use_chirality: bool = False, max_pair_distance: Optional[int] = None)[source]¶ This class implements the featurization to implement Weave convolutions.
Weave convolutions were introduced in [1]_. Unlike Duvenaud graph convolutions, weave convolutions require a quadratic matrix of interaction descriptors for each pair of atoms. These extra descriptors may provide for additional descriptive power but at the cost of a larger featurized dataset.
Examples
>>> import deepchem as dc >>> mols = ["C", "CCC"] >>> featurizer = dc.feat.WeaveFeaturizer() >>> X = featurizer.featurize(mols)
References
[1] Kearnes, Steven, et al. “Molecular graph convolutions: moving beyond fingerprints.” Journal of computeraided molecular design 30.8 (2016): 595608. Note
This class requires RDKit to be installed.

__init__
(graph_distance: bool = True, explicit_H: bool = False, use_chirality: bool = False, max_pair_distance: Optional[int] = None)[source]¶ Initialize this featurizer with set parameters.
Parameters:  graph_distance (bool, (default True)) – If True, use graph distance for distance features. Otherwise, use Euclidean distance. Note that this means that molecules that this featurizer is invoked on must have valid conformer information if this option is set.
 explicit_H (bool, (default False)) – If true, model hydrogens in the molecule.
 use_chirality (bool, (default False)) – If true, use chiral information in the featurization
 max_pair_distance (Optional[int], (default None)) – This value can be a positive integer or None. This parameter determines the maximum graph distance at which pair features are computed. For example, if max_pair_distance==2, then pair features are computed only for atoms at most graph distance 2 apart. If max_pair_distance is None, all pairs are considered (effectively infinite max_pair_distance)

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

CircularFingerprint¶

class
deepchem.feat.
CircularFingerprint
(radius: int = 2, size: int = 2048, chiral: bool = False, bonds: bool = True, features: bool = False, sparse: bool = False, smiles: bool = False)[source]¶ Circular (Morgan) fingerprints.
Extended Connectivity Circular Fingerprints compute a bagofwords style representation of a molecule by breaking it into local neighborhoods and hashing into a bit vector of the specified size. See [1]_ for more details.
References
[1] Rogers, David, and Mathew Hahn. “Extendedconnectivity fingerprints.” Journal of chemical information and modeling 50.5 (2010): 742754. Notes
This class requires RDKit to be installed.

__init__
(radius: int = 2, size: int = 2048, chiral: bool = False, bonds: bool = True, features: bool = False, sparse: bool = False, smiles: bool = False)[source]¶ Parameters:  radius (int, optional (default 2)) – Fingerprint radius.
 size (int, optional (default 2048)) – Length of generated bit vector.
 chiral (bool, optional (default False)) – Whether to consider chirality in fingerprint generation.
 bonds (bool, optional (default True)) – Whether to consider bond order in fingerprint generation.
 features (bool, optional (default False)) – Whether to use feature information instead of atom information; see RDKit docs for more info.
 sparse (bool, optional (default False)) – Whether to return a dict for each molecule containing the sparse fingerprint.
 smiles (bool, optional (default False)) – Whether to calculate SMILES strings for fragment IDs (only applicable when calculating sparse fingerprints).

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

Mol2VecFingerprint¶

class
deepchem.feat.
Mol2VecFingerprint
(pretrain_model_path: Optional[str] = None, radius: int = 1, unseen: str = 'UNK', gather_method: str = 'sum')[source]¶ Mol2Vec fingerprints.
This class convert molecules to vector representations by using Mol2Vec. Mol2Vec is an unsupervised machine learning approach to learn vector representations of molecular substructures and the algorithm is based on Word2Vec, which is one of the most popular technique to learn word embeddings using neural network in NLP. Please see the details from [1]_.
The Mol2Vec requires the pretrained model, so we use the model which is put on the mol2vec github repository [2]_. The default model was trained on 20 million compounds downloaded from ZINC using the following paramters.
 radius 1
 UNK to replace all identifiers that appear less than 4 times
 skipgram and window size of 10
 embeddings size 300
References
[1] Jaeger, Sabrina, Simone Fulle, and Samo Turk. “Mol2vec: unsupervised machine learning approach with chemical intuition.” Journal of chemical information and modeling 58.1 (2018): 2735. [2] https://github.com/samoturk/mol2vec/ Notes
This class requires mol2vec to be installed.

__init__
(pretrain_model_path: Optional[str] = None, radius: int = 1, unseen: str = 'UNK', gather_method: str = 'sum')[source]¶ Parameters:  pretrain_file (str, optional) – The path for pretrained model. If this value is None, we use the model which is put on github repository (https://github.com/samoturk/mol2vec/tree/master/examples/models). The model is trained on 20 million compounds downloaded from ZINC.
 radius (int, optional (default 1)) – The fingerprint radius. The default value was used to train the model which is put on github repository.
 unseen (str, optional (default 'UNK')) – The string to used to replace uncommon words/identifiers while training.
 gather_method (str, optional (default 'sum')) – How to aggregate vectors of identifiers are extracted from Mol2vec. ‘sum’ or ‘mean’ is supported.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray
RDKitDescriptors¶

class
deepchem.feat.
RDKitDescriptors
[source]¶ RDKit descriptors.
This class computes a list of chemical descriptors using RDKit.

descriptors
¶ List of RDKit descriptor names used in this class.
Type: List[str]
Notes
This class requires RDKit to be installed.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

MordredDescriptors¶

class
deepchem.feat.
MordredDescriptors
(ignore_3D: bool = True)[source]¶ Mordred descriptors.
This class computes a list of chemical descriptors using Mordred. Please see the details about all descriptors from [1]_, [2]_.

descriptors
¶ List of Mordred descriptor names used in this class.
Type: List[str]
References
[1] Moriwaki, Hirotomo, et al. “Mordred: a molecular descriptor calculator.” Journal of cheminformatics 10.1 (2018): 4. [2] http://mordreddescriptor.github.io/documentation/master/descriptors.html Notes
This class requires Mordred to be installed.

__init__
(ignore_3D: bool = True)[source]¶ Parameters: ignore_3D (bool, optional (default True)) – Whether to use 3D information or not.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

CoulombMatrix¶

class
deepchem.feat.
CoulombMatrix
(max_atoms: int, remove_hydrogens: bool = False, randomize: bool = False, upper_tri: bool = False, n_samples: int = 1, seed: Optional[int] = None)[source]¶ Calculate Coulomb matrices for molecules.
Coulomb matrices provide a representation of the electronic structure of a molecule. This method is described in [1]_.
Examples
>>> import deepchem as dc >>> featurizers = dc.feat.CoulombMatrix(max_atoms=23) >>> input_file = 'deepchem/feat/tests/data/water.sdf' # really backed by water.sdf.csv >>> tasks = ["atomization_energy"] >>> loader = dc.data.SDFLoader(tasks, featurizer=featurizers) >>> dataset = loader.create_dataset(input_file)
References
[1] Montavon, Grégoire, et al. “Learning invariant representations of molecules for atomization energy prediction.” Advances in neural information processing systems. 2012. Notes
This class requires RDKit to be installed.

__init__
(max_atoms: int, remove_hydrogens: bool = False, randomize: bool = False, upper_tri: bool = False, n_samples: int = 1, seed: Optional[int] = None)[source]¶ Initialize this featurizer.
Parameters:  max_atoms (int) – The maximum number of atoms expected for molecules this featurizer will process.
 remove_hydrogens (bool, optional (default False)) – If True, remove hydrogens before processing them.
 randomize (bool, optional (default False)) – If True, use method randomize_coulomb_matrices to randomize Coulomb matrices.
 upper_tri (bool, optional (default False)) – Generate only upper triangle part of Coulomb matrices.
 n_samples (int, optional (default 1)) – If randomize is set to True, the number of random samples to draw.
 seed (int, optional (default None)) – Random seed to use.

coulomb_matrix
(mol: Any) → numpy.ndarray[source]¶ Generate Coulomb matrices for each conformer of the given molecule.
Parameters: mol (rdkit.Chem.rdchem.Mol) – RDKit Mol object Returns: The coulomb matrices of the given molecule Return type: np.ndarray

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

static
get_interatomic_distances
(conf: Any) → numpy.ndarray[source]¶ Get interatomic distances for atoms in a molecular conformer.
Parameters: conf (rdkit.Chem.rdchem.Conformer) – Molecule conformer. Returns: The distances matrix for all atoms in a molecule Return type: np.ndarray

randomize_coulomb_matrix
(m: numpy.ndarray) → List[numpy.ndarray][source]¶ Randomize a Coulomb matrix as decribed in [1]_:
 Compute row norms for M in a vector row_norms.
 Sample a zeromean unitvariance noise vector e with dimension equal to row_norms.
 Permute the rows and columns of M with the permutation that sorts row_norms + e.
Parameters: m (np.ndarray) – Coulomb matrix. Returns: List of the random coulomb matrix Return type: List[np.ndarray] References
[1] Montavon et al., New Journal of Physics, 15, (2013), 095003

CoulombMatrixEig¶

class
deepchem.feat.
CoulombMatrixEig
(max_atoms: int, remove_hydrogens: bool = False, randomize: bool = False, n_samples: int = 1, seed: Optional[int] = None)[source]¶ Calculate the eigenvalues of Coulomb matrices for molecules.
This featurizer computes the eigenvalues of the Coulomb matrices for provided molecules. Coulomb matrices are described in [1]_.
Examples
>>> import deepchem as dc >>> featurizers = dc.feat.CoulombMatrixEig(max_atoms=23) >>> input_file = 'deepchem/feat/tests/data/water.sdf' # really backed by water.sdf.csv >>> tasks = ["atomization_energy"] >>> loader = dc.data.SDFLoader(tasks, featurizer=featurizers) >>> dataset = loader.create_dataset(input_file)
References
[1] Montavon, Grégoire, et al. “Learning invariant representations of molecules for atomization energy prediction.” Advances in neural information processing systems. 2012. 
__init__
(max_atoms: int, remove_hydrogens: bool = False, randomize: bool = False, n_samples: int = 1, seed: Optional[int] = None)[source]¶ Initialize this featurizer.
Parameters:  max_atoms (int) – The maximum number of atoms expected for molecules this featurizer will process.
 remove_hydrogens (bool, optional (default False)) – If True, remove hydrogens before processing them.
 randomize (bool, optional (default False)) – If True, use method randomize_coulomb_matrices to randomize Coulomb matrices.
 n_samples (int, optional (default 1)) – If randomize is set to True, the number of random samples to draw.
 seed (int, optional (default None)) – Random seed to use.

coulomb_matrix
(mol: Any) → numpy.ndarray[source]¶ Generate Coulomb matrices for each conformer of the given molecule.
Parameters: mol (rdkit.Chem.rdchem.Mol) – RDKit Mol object Returns: The coulomb matrices of the given molecule Return type: np.ndarray

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

static
get_interatomic_distances
(conf: Any) → numpy.ndarray[source]¶ Get interatomic distances for atoms in a molecular conformer.
Parameters: conf (rdkit.Chem.rdchem.Conformer) – Molecule conformer. Returns: The distances matrix for all atoms in a molecule Return type: np.ndarray

randomize_coulomb_matrix
(m: numpy.ndarray) → List[numpy.ndarray][source]¶ Randomize a Coulomb matrix as decribed in [1]_:
 Compute row norms for M in a vector row_norms.
 Sample a zeromean unitvariance noise vector e with dimension equal to row_norms.
 Permute the rows and columns of M with the permutation that sorts row_norms + e.
Parameters: m (np.ndarray) – Coulomb matrix. Returns: List of the random coulomb matrix Return type: List[np.ndarray] References
[1] Montavon et al., New Journal of Physics, 15, (2013), 095003

AtomCoordinates¶

class
deepchem.feat.
AtomicCoordinates
(use_bohr: bool = False)[source]¶ Calculate atomic coordinates.
Notes
This class requires RDKit to be installed.

__init__
(use_bohr: bool = False)[source]¶ Parameters: use_bohr (bool, optional (default False)) – Whether to use bohr or angstrom as a coordinate unit.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

SmilesToSeq¶

class
deepchem.feat.
SmilesToSeq
(char_to_idx: Dict[str, int], max_len: int = 250, pad_len: int = 10)[source]¶ SmilesToSeq Featurizer takes a SMILES string, and turns it into a sequence. Details taken from [1]_.
SMILES strings smaller than a specified max length (max_len) are padded using the PAD token while those larger than the max length are not considered. Based on the paper, there is also the option to add extra padding (pad_len) on both sides of the string after length normalization. Using a character to index (char_to_idx) mapping, the SMILES characters are turned into indices and the resulting sequence of indices serves as the input for an embedding layer.
References
[1] Goh, Garrett B., et al. “Using rulebased labels for weak supervised learning: a ChemNet for transferable chemical property prediction.” Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. 2018. Notes
This class requires RDKit to be installed.

__init__
(char_to_idx: Dict[str, int], max_len: int = 250, pad_len: int = 10)[source]¶ Initialize this class.
Parameters:  char_to_idx (Dict) – Dictionary containing character to index mappings for unique characters
 max_len (int, default 250) – Maximum allowed length of the SMILES string.
 pad_len (int, default 10) – Amount of padding to add on either side of the SMILES seq

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

SmilesToImage¶

class
deepchem.feat.
SmilesToImage
(img_size: int = 80, res: float = 0.5, max_len: int = 250, img_spec: str = 'std')[source]¶ Convert SMILES string to an image.
SmilesToImage Featurizer takes a SMILES string, and turns it into an image. Details taken from [1]_.
The default size of for the image is 80 x 80. Two image modes are currently supported  std & engd. std is the gray scale specification, with atomic numbers as pixel values for atom positions and a constant value of 2 for bond positions. engd is a 4channel specification, which uses atom properties like hybridization, valency, charges in addition to atomic number. Bond type is also used for the bonds.
The coordinates of all atoms are computed, and lines are drawn between atoms to indicate bonds. For the respective channels, the atom and bond positions are set to the property values as mentioned in the paper.
References
[1] Goh, Garrett B., et al. “Using rulebased labels for weak supervised learning: a ChemNet for transferable chemical property prediction.” Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. 2018. Notes
This class requires RDKit to be installed.

__init__
(img_size: int = 80, res: float = 0.5, max_len: int = 250, img_spec: str = 'std')[source]¶ Parameters:  img_size (int, default 80) – Size of the image tensor
 res (float, default 0.5) – Displays the resolution of each pixel in Angstrom
 max_len (int, default 250) – Maximum allowed length of SMILES string
 img_spec (str, default std) – Indicates the channel organization of the image tensor

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

OneHotFeaturizer¶

class
deepchem.feat.
OneHotFeaturizer
(charset: List[str] = ['#', ')', '(', '+', '', '/', '1', '3', '2', '5', '4', '7', '6', '8', '=', '@', 'C', 'B', 'F', 'I', 'H', 'O', 'N', 'S', '[', ']', '\', 'c', 'l', 'o', 'n', 'p', 's', 'r'], max_length: int = 100)[source]¶ Encodes SMILES as a onehot array.
This featurizer encodes SMILES string as a onehot array.
Notes
This class requires RDKit to be installed.

__init__
(charset: List[str] = ['#', ')', '(', '+', '', '/', '1', '3', '2', '5', '4', '7', '6', '8', '=', '@', 'C', 'B', 'F', 'I', 'H', 'O', 'N', 'S', '[', ']', '\\', 'c', 'l', 'o', 'n', 'p', 's', 'r'], max_length: int = 100)[source]¶ Initialize featurizer.
Parameters:  charset (List[str], optional (default ZINC_CHARSET)) – A list of strings, where each string is length 1 and unique.
 max_length (int, optional (default 100)) – The max length for SMILES string. If the length of SMILES string is shorter than max_length, the SMILES is padded using space.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

ComplexFeaturizer¶
The dc.feat.ComplexFeaturizer
class is the abstract parent class for all featurizers that work with three dimensional molecular complexes.

class
deepchem.feat.
ComplexFeaturizer
[source]¶ ” Abstract class for calculating features for mol/protein complexes.

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

featurize
(mol_files: Sequence[str], protein_pdbs: Sequence[str]) → Tuple[numpy.ndarray, List[T]][source]¶ Calculate features for mol/protein complexes.
Parameters:  mols (List[str]) – List of PDB filenames for molecules.
 protein_pdbs (List[str]) – List of PDB filenames for proteins.
Returns:  features (np.ndarray) – Array of features
 failures (List) – Indices of complexes that failed to featurize.

RdkitGridFeaturizer¶

class
deepchem.feat.
RdkitGridFeaturizer
(nb_rotations=0, feature_types=None, ecfp_degree=2, ecfp_power=3, splif_power=3, box_width=16.0, voxel_width=1.0, flatten=False, verbose=True, sanitize=False, **kwargs)[source]¶ Featurizes proteinligand complex using flat features or a 3D grid (in which each voxel is described with a vector of features).

__init__
(nb_rotations=0, feature_types=None, ecfp_degree=2, ecfp_power=3, splif_power=3, box_width=16.0, voxel_width=1.0, flatten=False, verbose=True, sanitize=False, **kwargs)[source]¶ Parameters:  nb_rotations (int, optional (default 0)) – Number of additional random rotations of a complex to generate.
 feature_types (list, optional (default ['ecfp'])) –
 Types of features to calculate. Available types are
 flat features > ‘ecfp_ligand’, ‘ecfp_hashed’, ‘splif_hashed’, ‘hbond_count’ voxel features > ‘ecfp’, ‘splif’, ‘sybyl’, ‘salt_bridge’, ‘charge’, ‘hbond’, ‘pi_stack, ‘cation_pi’
 There are also 3 predefined sets of features
 ’flat_combined’, ‘voxel_combined’, and ‘all_combined’.
Calculated features are concatenated and their order is preserved (features in predefined sets are in alphabetical order).
 ecfp_degree (int, optional (default 2)) – ECFP radius.
 ecfp_power (int, optional (default 3)) – Number of bits to store ECFP features (resulting vector will be 2^ecfp_power long)
 splif_power (int, optional (default 3)) – Number of bits to store SPLIF features (resulting vector will be 2^splif_power long)
 box_width (float, optional (default 16.0)) – Size of a box in which voxel features are calculated. Box is centered on a ligand centroid.
 voxel_width (float, optional (default 1.0)) – Size of a 3D voxel in a grid.
 flatten (bool, optional (defaul False)) – Indicate whether calculated features should be flattened. Output is always flattened if flat features are specified in feature_types.
 verbose (bool, optional (defaul True)) – Verbolity for logging
 sanitize (bool, optional (defaul False)) – If set to True molecules will be sanitized. Note that calculating some features (e.g. aromatic interactions) require sanitized molecules.
 **kwargs (dict, optional) – Keyword arguments can be usaed to specify custom cutoffs and bins (see default values below).
 cutoffs and bins (Default) –
  –
 hbond_dist_bins ([(2.2, 2.5), (2.5, 3.2), (3.2, 4.0)]) –
 hbond_angle_cutoffs ([5, 50, 90]) –
 splif_contact_bins ([(0, 2.0), (2.0, 3.0), (3.0, 4.5)]) –
 ecfp_cutoff (4.5) –
 sybyl_cutoff (7.0) –
 salt_bridges_cutoff (5.0) –
 pi_stack_dist_cutoff (4.4) –
 pi_stack_angle_cutoff (30.0) –
 cation_pi_dist_cutoff (6.5) –
 cation_pi_angle_cutoff (30.0) –

featurize
(mol_files: Sequence[str], protein_pdbs: Sequence[str]) → Tuple[numpy.ndarray, List[T]][source]¶ Calculate features for mol/protein complexes.
Parameters:  mols (List[str]) – List of PDB filenames for molecules.
 protein_pdbs (List[str]) – List of PDB filenames for proteins.
Returns:  features (np.ndarray) – Array of features
 failures (List) – Indices of complexes that failed to featurize.

AtomConvFeaturizer¶

class
deepchem.feat.
NeighborListComplexAtomicCoordinates
(max_num_neighbors=None, neighbor_cutoff=4)[source]¶ Adjacency list of neighbors for proteinligand complexes in 3space.
Neighbors dtermined by userdfined distance cutoff.

__init__
(max_num_neighbors=None, neighbor_cutoff=4)[source]¶ Initialize self. See help(type(self)) for accurate signature.

featurize
(mol_files: Sequence[str], protein_pdbs: Sequence[str]) → Tuple[numpy.ndarray, List[T]][source]¶ Calculate features for mol/protein complexes.
Parameters:  mols (List[str]) – List of PDB filenames for molecules.
 protein_pdbs (List[str]) – List of PDB filenames for proteins.
Returns:  features (np.ndarray) – Array of features
 failures (List) – Indices of complexes that failed to featurize.

MaterialStructureFeaturizer¶
Material Structure Featurizers are those that work with datasets of crystals with periodic boundary conditions. For inorganic crystal structures, these featurizers operate on pymatgen.Structure objects, which include a lattice and 3D coordinates that specify a periodic crystal structure. They should be applied on systems that have periodic boundary conditions. Structure featurizers are not designed to work with molecules.

class
deepchem.feat.
MaterialStructureFeaturizer
[source]¶ Abstract class for calculating a set of features for an inorganic crystal structure.
The defining feature of a MaterialStructureFeaturizer is that it operates on 3D crystal structures with periodic boundary conditions. Inorganic crystal structures are represented by Pymatgen structure objects. Featurizers for inorganic crystal structures that are subclasses of this class should plan to process input which comes as pymatgen structure objects.
This class is abstract and cannot be invoked directly. You’ll likely only interact with this class if you’re a developer. Child classes need to implement the _featurize method for calculating features for a single crystal structure.
Notes
Some subclasses of this class will require pymatgen and matminer to be installed.

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

featurize
(structures: Iterable[Union[Dict[str, Any], Any]], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for crystal structures.
Parameters:  structures (Iterable[Union[Dict, pymatgen.Structure]]) – Iterable sequence of pymatgen structure dictionaries or pymatgen.Structure. Please confirm the dictionary representations of pymatgen.Structure from https://pymatgen.org/pymatgen.core.structure.html.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of structures.
Return type: np.ndarray

SineCoulombMatrix¶

class
deepchem.feat.
SineCoulombMatrix
(max_atoms: int = 100, flatten: bool = True)[source]¶ Calculate sine Coulomb matrix for crystals.
A variant of Coulomb matrix for periodic crystals.
The sine Coulomb matrix is identical to the Coulomb matrix, except that the inverse distance function is replaced by the inverse of sin**2 of the vector between sites which are periodic in the dimensions of the crystal lattice.
Features are flattened into a vector of matrix eigenvalues by default for MLreadiness. To ensure that all feature vectors are equal length, the maximum number of atoms (eigenvalues) in the input dataset must be specified.
This featurizer requires the optional dependencies pymatgen and matminer. It may be useful when crystal structures with 3D coordinates are available.
See [1]_ for more details.
References
[1] Faber et al. Inter. J. Quantum Chem. 115, 16, 2015. Examples
>>> import pymatgen as mg >>> lattice = mg.Lattice.cubic(4.2) >>> structure = mg.Structure(lattice, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) >>> featurizer = SineCoulombMatrix(max_atoms=2) >>> features = featurizer.featurize([structure])
Notes
This class requires matminer and Pymatgen to be installed.

__init__
(max_atoms: int = 100, flatten: bool = True)[source]¶ Parameters:  max_atoms (int (default 100)) – Maximum number of atoms for any crystal in the dataset. Used to pad the Coulomb matrix.
 flatten (bool (default True)) – Return flattened vector of matrix eigenvalues.

featurize
(structures: Iterable[Union[Dict[str, Any], Any]], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for crystal structures.
Parameters:  structures (Iterable[Union[Dict, pymatgen.Structure]]) – Iterable sequence of pymatgen structure dictionaries or pymatgen.Structure. Please confirm the dictionary representations of pymatgen.Structure from https://pymatgen.org/pymatgen.core.structure.html.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of structures.
Return type: np.ndarray

CGCNNFeaturizer¶

class
deepchem.feat.
CGCNNFeaturizer
(radius: float = 8.0, max_neighbors: float = 12, step: float = 0.2)[source]¶ Calculate structure graph features for crystals.
Based on the implementation in Crystal Graph Convolutional Neural Networks (CGCNN). The method constructs a crystal graph representation including atom features and bond features (neighbor distances). Neighbors are determined by searching in a sphere around atoms in the unit cell. A Gaussian filter is applied to neighbor distances. All units are in angstrom.
This featurizer requires the optional dependency pymatgen. It may be useful when 3D coordinates are available and when using graph network models and crystal graph convolutional networks.
See [1]_ for more details.
References
[1]  Xie and J. C. Grossman, Phys. Rev. Lett. 120, 2018.
Examples
>>> import pymatgen as mg >>> lattice = mg.Lattice.cubic(4.2) >>> structure = mg.Structure(lattice, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) >>> featurizer = CGCNNFeaturizer() >>> features = featurizer.featurize([structure]) >>> feature = features[0] >>> print(type(feature)) <class 'deepchem.feat.graph_data.GraphData'>
Notes
This class requires Pymatgen to be installed.

__init__
(radius: float = 8.0, max_neighbors: float = 12, step: float = 0.2)[source]¶ Parameters:  radius (float (default 8.0)) – Radius of sphere for finding neighbors of atoms in unit cell.
 max_neighbors (int (default 12)) – Maximum number of neighbors to consider when constructing graph.
 step (float (default 0.2)) – Step size for Gaussian filter. This value is used when building edge features.

featurize
(structures: Iterable[Union[Dict[str, Any], Any]], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for crystal structures.
Parameters:  structures (Iterable[Union[Dict, pymatgen.Structure]]) – Iterable sequence of pymatgen structure dictionaries or pymatgen.Structure. Please confirm the dictionary representations of pymatgen.Structure from https://pymatgen.org/pymatgen.core.structure.html.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of structures.
Return type: np.ndarray
MaterialCompositionFeaturizer¶
Material Composition Featurizers are those that work with datasets of crystal compositions with periodic boundary conditions. For inorganic crystal structures, these featurizers operate on chemical compositions (e.g. “MoS2”). They should be applied on systems that have periodic boundary conditions. Composition featurizers are not designed to work with molecules.

class
deepchem.feat.
MaterialCompositionFeaturizer
[source]¶ Abstract class for calculating a set of features for an inorganic crystal composition.
The defining feature of a MaterialCompositionFeaturizer is that it operates on 3D crystal chemical compositions. Inorganic crystal compositions are represented by Pymatgen composition objects. Featurizers for inorganic crystal compositions that are subclasses of this class should plan to process input which comes as Pymatgen composition objects.
This class is abstract and cannot be invoked directly. You’ll likely only interact with this class if you’re a developer. Child classes need to implement the _featurize method for calculating features for a single crystal composition.
Notes
Some subclasses of this class will require pymatgen and matminer to be installed.

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

featurize
(compositions: Iterable[str], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for crystal compositions.
Parameters:  compositions (Iterable[str]) – Iterable sequence of composition strings, e.g. “MoS2”.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of compositions.
Return type: np.ndarray

ElementPropertyFingerprint¶

class
deepchem.feat.
ElementPropertyFingerprint
(data_source: str = 'matminer')[source]¶ Fingerprint of elemental properties from composition.
Based on the data source chosen, returns properties and statistics (min, max, range, mean, standard deviation, mode) for a compound based on elemental stoichiometry. E.g., the average electronegativity of atoms in a crystal structure. The chemical fingerprint is a vector of these statistics. For a full list of properties and statistics, see
matminer.featurizers.composition.ElementProperty(data_source).feature_labels()
.This featurizer requires the optional dependencies pymatgen and matminer. It may be useful when only crystal compositions are available (and not 3D coordinates).
See references [1]_ [2]_ [3] [4] for more details.
References
[1] MagPie data: Ward, L. et al. npj Comput Mater 2, 16028 (2016). https://doi.org/10.1038/npjcompumats.2016.28 [2] Deml data: Deml, A. et al. Physical Review B 93, 085142 (2016). 10.1103/PhysRevB.93.085142 [3] Matminer: Ward, L. et al. Comput. Mater. Sci. 152, 6069 (2018). [4] Pymatgen: Ong, S.P. et al. Comput. Mater. Sci. 68, 314319 (2013). Examples
>>> import pymatgen as mg >>> comp = mg.Composition("Fe2O3") >>> featurizer = ElementPropertyFingerprint() >>> features = featurizer.featurize([comp])
Notes
This class requires matminer and Pymatgen to be installed. NaN feature values are automatically converted to 0 by this featurizer.

__init__
(data_source: str = 'matminer')[source]¶ Parameters: data_source (str of "matminer", "magpie" or "deml" (default "matminer")) – Source for element property data.

featurize
(compositions: Iterable[str], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for crystal compositions.
Parameters:  compositions (Iterable[str]) – Iterable sequence of composition strings, e.g. “MoS2”.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of compositions.
Return type: np.ndarray

BindingPocketFeaturizer¶

class
deepchem.feat.
BindingPocketFeaturizer
[source]¶ Featurizes binding pockets with information about chemical environments.
In many applications, it’s desirable to look at binding pockets on macromolecules which may be good targets for potential ligands or other molecules to interact with. A BindingPocketFeaturizer expects to be given a macromolecule, and a list of pockets to featurize on that macromolecule. These pockets should be of the form produced by a dc.dock.BindingPocketFinder, that is as a list of dc.utils.CoordinateBox objects.
The base featurization in this class’s featurization is currently very simple and counts the number of residues of each type present in the pocket. It’s likely that you’ll want to overwrite this implementation for more sophisticated downstream usecases. Note that this class’s implementation will only work for proteins and not for other macromolecules
Notes
This class requires mdtraj to be installed.

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

featurize
(protein_file: str, pockets: List[deepchem.utils.coordinate_box_utils.CoordinateBox]) → numpy.ndarray[source]¶ Calculate atomic coodinates.
Parameters:  protein_file (str) – Location of PDB file. Will be loaded by MDTraj
 pockets (List[CoordinateBox]) – List of dc.utils.CoordinateBox objects.
Returns: A numpy array of shale (len(pockets), n_residues)
Return type: np.ndarray

UserDefinedFeaturizer¶

class
deepchem.feat.
UserDefinedFeaturizer
(feature_fields)[source]¶ Directs usage of usercomputed featurizations.

featurize
(datapoints: Iterable[Any], log_every_n: int = 1000) → numpy.ndarray[source]¶ Calculate features for datapoints.
Parameters:  datapoints (Iterable[Any]) – A sequence of objects that you’d like to featurize. Subclassses of Featurizer should instantiate the _featurize method that featurizes objects in the sequence.
 log_every_n (int, default 1000) – Logs featurization progress every log_every_n steps.
Returns: A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

BPSymmetryFunctionInput¶

class
deepchem.feat.
BPSymmetryFunctionInput
(max_atoms: int)[source]¶ Calculate symmetry function for each atom in the molecules
This method is described in [1]_
References
[1] Behler, Jörg, and Michele Parrinello. “Generalized neuralnetwork representation of highdimensional potentialenergy surfaces.” Physical review letters 98.14 (2007): 146401. Notes
This class requires RDKit to be installed.

__init__
(max_atoms: int)[source]¶ Initialize this featurizer.
Parameters: max_atoms (int) – The maximum number of atoms expected for molecules this featurizer will process.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray

RawFeaturizer¶

class
deepchem.feat.
RawFeaturizer
(smiles: bool = False)[source]¶ Encodes a molecule as a SMILES string or RDKit mol.
This featurizer can be useful when you’re trying to transform a large collection of RDKit mol objects as Smiles strings, or alternatively as a “noop” featurizer in your molecular pipeline.
Notes
This class requires RDKit to be installed.

__init__
(smiles: bool = False)[source]¶ Initialize this featurizer.
Parameters: smiles (bool, optional (default False)) – If True, encode this molecule as a SMILES string. Else as a RDKit mol.

featurize
(molecules, log_every_n=1000)[source]¶ Calculate features for molecules.
Parameters:  molecules (rdkit.Chem.rdchem.Mol / SMILES string / iterable) – RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES strings.
 log_every_n (int, default 1000) – Logging messages reported every log_every_n samples.
Returns: features – A numpy array containing a featurized representation of datapoints.
Return type: np.ndarray
