qmdesc package

Submodules

qmdesc.featurization module

class qmdesc.featurization.BatchMolGraph(mol_graphs: List[qmdesc.featurization.MolGraph])[source]

Bases: object

A BatchMolGraph represents the graph structure and featurization of a batch of molecules. A BatchMolGraph contains the attributes of a MolGraph plus: - smiles_batch: A list of smiles strings. - n_mols: The number of molecules in the batch. - atom_fdim: The dimensionality of the atom features. - bond_fdim: The dimensionality of the bond features (technically the combined atom/bond features). - a_scope: A list of tuples indicating the start and end atom indices for each molecule. - b_scope: A list of tuples indicating the start and end bond indices for each molecule. - max_num_bonds: The maximum number of bonds neighboring an atom in this batch. - b2b: (Optional) A mapping from a bond index to incoming bond indices. - a2a: (Optional): A mapping from an atom index to neighboring atom indices.

get_a2a() → torch.LongTensor[source]

Computes (if necessary) and returns a mapping from each atom index to all neighboring atom indices. :return: A PyTorch tensor containing the mapping from each bond index to all the incodming bond indices.

get_b2b() → torch.LongTensor[source]

Computes (if necessary) and returns a mapping from each bond index to all the incoming bond indices. :return: A PyTorch tensor containing the mapping from each bond index to all the incoming bond indices.

get_components() → Tuple[torch.FloatTensor, torch.FloatTensor, torch.LongTensor, torch.LongTensor, torch.LongTensor, List[Tuple[int, int]], List[Tuple[int, int]], torch.LongTensor, torch.FloatTensor][source]

Returns the components of the BatchMolGraph. :return: A tuple containing PyTorch tensors with the atom features, bond features, and graph structure and two lists indicating the scope of the atoms and bonds (i.e. which molecules they belong to).

class qmdesc.featurization.MolGraph(smiles: str)[source]

Bases: object

A MolGraph represents the graph structure and featurization of a single molecule. A MolGraph computes the following attributes: - smiles: Smiles string. - n_atoms: The number of atoms in the molecule. - n_bonds: The number of bonds in the molecule. - f_atoms: A mapping from an atom index to a list atom features. - f_bonds: A mapping from a bond index to a list of bond features. - a2b: A mapping from an atom index to a list of incoming bond indices. - b2a: A mapping from a bond index to the index of the atom the bond originates from. - b2revb: A mapping from a bond index to the index of the reverse bond.

qmdesc.featurization.atom_features(atom: rdkit.Chem.rdchem.Atom, functional_groups: List[int] = None) → List[Union[int, float]][source]

Builds a feature vector for an atom. :param atom: An RDKit atom. :param functional_groups: A k-hot vector indicating the functional groups the atom belongs to. :return: A list containing the atom features.

qmdesc.featurization.bond_features(bond: rdkit.Chem.rdchem.Bond) → List[Union[int, float]][source]

Builds a feature vector for a bond. :param bond: A RDKit bond. :return: A list containing the bond features.

qmdesc.featurization.clear_cache()[source]

Clears featurization cache.

qmdesc.featurization.get_atom_fdim() → int[source]

Gets the dimensionality of atom features. :param: Arguments.

qmdesc.featurization.get_bond_fdim() → int[source]

Gets the dimensionality of bond features. :param: Arguments.

qmdesc.featurization.mol2graph(smiles_batch: List[str])qmdesc.featurization.BatchMolGraph[source]

Converts a list of SMILES strings to a BatchMolGraph containing the batch of molecular graphs. :param smiles_batch: A list of SMILES strings. :return: A BatchMolGraph containing the combined molecular graph for the molecules

qmdesc.featurization.onek_encoding_unk(value: int, choices: List[int]) → List[int][source]

Creates a one-hot encoding. :param value: The value for which the encoding should be one. :param choices: A list of possible values. :return: A one-hot encoding of the value in a list of length len(choices) + 1. If value is not in the list of choices, then the final element in the encoding is 1.

qmdesc.ffn module

class qmdesc.ffn.AttrProxy(module, prefix)[source]

Bases: object

Translates index lookups into attribute lookups

qmdesc.handler module

This module defines the PathwayRankingHandler for use in Torchserve.

class qmdesc.handler.ReactivityDescriptorHandler[source]

Bases: object

Wrap the trained atom-bond qm descriptors predicting model

Predict QM descriptors for a given SMILES string of organic compound containing C, H, O, N, P, S, F, Cl, Br, I, B

Example

>>> from qmdesc import ReactivityDescriptorHandler
>>> handler = ReactivityDescriptorHandler()
>>> results = handler.predict('CCCC')
predict(smiles: str, sdf: str = None) → Dict[source]

Wrap the preprocess, inference, and postprocess

Parameters
  • smiles – Input SMILES string

  • sdf – Output .sdf file

Returns

A dictionary containing the prediction result

qmdesc.handler.qmdesc() → None[source]

This is the entry point for the command line command :code:’qmdesc’

Example

$ qmdesc CCCC –sdf CCCC.sdf

qmdesc.model module

qmdesc.mpn module

qmdesc.nn_utils module

qmdesc.nn_utils.index_select_ND(source: torch.Tensor, index: torch.Tensor) → torch.Tensor[source]

Selects the message features from source corresponding to the atom or bond indices in index. :param source: A tensor of shape (num_bonds, hidden_size) containing message features. :param index: A tensor of shape (num_atoms/num_bonds, max_num_bonds) containing the atom or bond

indices to select from source.

Returns

A tensor of shape (num_atoms/num_bonds, max_num_bonds, hidden_size) containing the message features corresponding to the atoms/bonds specified in index.

Module contents