Models

chemprop.models.py contains the core Chemprop message passing neural network.

Model

chemprop.models.model.py contains the MoleculeModel class, which contains the full Chemprop model. It consists of an MPN, which performs message passing, along with a feed-forward neural network which combines the output of the message passing network along with any additional molecule-level features and makes the final property predictions.

class chemprop.models.model.MoleculeModel(args: chemprop.args.TrainArgs)[source]

A MoleculeModel is a model which contains a message passing network following by feed-forward layers.

Parameters

args – A TrainArgs object containing model arguments.

create_encoder(args: chemprop.args.TrainArgs) None[source]

Creates the message passing encoder for the model.

Parameters

args – A TrainArgs object containing model arguments.

create_ffn(args: chemprop.args.TrainArgs) None[source]

Creates the feed-forward layers for the model.

Parameters

args – A TrainArgs object containing model arguments.

fingerprint(batch: Union[List[List[str]], List[List[rdkit.Chem.rdchem.Mol]], List[List[Tuple[rdkit.Chem.rdchem.Mol, rdkit.Chem.rdchem.Mol]]], List[chemprop.features.featurization.BatchMolGraph]], features_batch: Optional[List[numpy.ndarray]] = None, atom_descriptors_batch: Optional[List[numpy.ndarray]] = None, atom_features_batch: Optional[List[numpy.ndarray]] = None, bond_features_batch: Optional[List[numpy.ndarray]] = None, fingerprint_type='MPN') torch.FloatTensor[source]

Encodes the latent representations of the input molecules from intermediate stages of the model.

Parameters
  • batch – A list of list of SMILES, a list of list of RDKit molecules, or a list of BatchMolGraph. The outer list or BatchMolGraph is of length num_molecules (number of datapoints in batch), the inner list is of length number_of_molecules (number of molecules per datapoint).

  • features_batch – A list of numpy arrays containing additional features.

  • atom_descriptors_batch – A list of numpy arrays containing additional atom descriptors.

  • fingerprint_type – The choice of which type of latent representation to return as the molecular fingerprint. Currently supported MPN for the output of the MPNN portion of the model or last_FFN for the input to the final readout layer.

Returns

The latent fingerprint vectors.

forward(batch: Union[List[List[str]], List[List[rdkit.Chem.rdchem.Mol]], List[List[Tuple[rdkit.Chem.rdchem.Mol, rdkit.Chem.rdchem.Mol]]], List[chemprop.features.featurization.BatchMolGraph]], features_batch: Optional[List[numpy.ndarray]] = None, atom_descriptors_batch: Optional[List[numpy.ndarray]] = None, atom_features_batch: Optional[List[numpy.ndarray]] = None, bond_features_batch: Optional[List[numpy.ndarray]] = None) torch.FloatTensor[source]

Runs the MoleculeModel on input.

Parameters
  • batch – A list of list of SMILES, a list of list of RDKit molecules, or a list of BatchMolGraph. The outer list or BatchMolGraph is of length num_molecules (number of datapoints in batch), the inner list is of length number_of_molecules (number of molecules per datapoint).

  • features_batch – A list of numpy arrays containing additional features.

  • atom_descriptors_batch – A list of numpy arrays containing additional atom descriptors.

  • atom_features_batch – A list of numpy arrays containing additional atom features.

  • bond_features_batch – A list of numpy arrays containing additional bond features.

Returns

The output of the MoleculeModel, containing a list of property predictions

MPN

chemprop.models.model.py contains the MPNEncoder class, which is the core message passing network, along with a wrapper MPN which is used within a MoleculeModel.

class chemprop.models.mpn.MPN(args: chemprop.args.TrainArgs, atom_fdim: Optional[int] = None, bond_fdim: Optional[int] = None)[source]

An MPN is a wrapper around MPNEncoder which featurizes input as needed.

Parameters
  • args – A TrainArgs object containing model arguments.

  • atom_fdim – Atom feature vector dimension.

  • bond_fdim – Bond feature vector dimension.

forward(batch: Union[List[List[str]], List[List[rdkit.Chem.rdchem.Mol]], List[List[Tuple[rdkit.Chem.rdchem.Mol, rdkit.Chem.rdchem.Mol]]], List[chemprop.features.featurization.BatchMolGraph]], features_batch: Optional[List[numpy.ndarray]] = None, atom_descriptors_batch: Optional[List[numpy.ndarray]] = None, atom_features_batch: Optional[List[numpy.ndarray]] = None, bond_features_batch: Optional[List[numpy.ndarray]] = None) torch.FloatTensor[source]

Encodes a batch of molecules.

Parameters
  • batch – A list of list of SMILES, a list of list of RDKit molecules, or a list of BatchMolGraph. The outer list or BatchMolGraph is of length num_molecules (number of datapoints in batch), the inner list is of length number_of_molecules (number of molecules per datapoint).

  • features_batch – A list of numpy arrays containing additional features.

  • atom_descriptors_batch – A list of numpy arrays containing additional atom descriptors.

  • atom_features_batch – A list of numpy arrays containing additional atom features.

  • bond_features_batch – A list of numpy arrays containing additional bond features.

Returns

A PyTorch tensor of shape (num_molecules, hidden_size) containing the encoding of each molecule.

class chemprop.models.mpn.MPNEncoder(args: chemprop.args.TrainArgs, atom_fdim: int, bond_fdim: int)[source]

An MPNEncoder is a message passing neural network for encoding a molecule.

Parameters
  • args – A TrainArgs object containing model arguments.

  • atom_fdim – Atom feature vector dimension.

  • bond_fdim – Bond feature vector dimension.

forward(mol_graph: chemprop.features.featurization.BatchMolGraph, atom_descriptors_batch: Optional[List[numpy.ndarray]] = None) torch.FloatTensor[source]

Encodes a batch of molecular graphs.

Parameters
  • mol_graph – A BatchMolGraph representing a batch of molecular graphs.

  • atom_descriptors_batch – A list of numpy arrays containing additional atomic descriptors

Returns

A PyTorch tensor of shape (num_molecules, hidden_size) containing the encoding of each molecule.