molreps package

Submodules

molreps.descriptors module

Common Molecular descriptors for (classical) machine learning.

Note they are defined only for one molecule not for batches.

molreps.descriptors.bond_angles(atoms, coordinates, bond_table=None)[source]
molreps.descriptors.coulomb_matrix(atoms, coordinates)[source]

Calculate the Coulombmatrix representation of a molecule.

Parameters
  • atoms (list) – List of atoms as string, e.g. [“H”,”H”,”O”]

  • coordinates (np.array, list) – List or numpy array of coordinates of shape (N,3)

Returns

Coulombmatrix of shape (N,N).

Return type

np.array

molreps.graph module

Main graph generator for making molecular graphs.

It uses networkx as graph interface and a mol object from rdkit, ase, pymatgen or similar.

class molreps.graph.MolGraph(mol=None, **kwargs)[source]

Bases: networkx.classes.graph.Graph

Molecular Graph which inherits from networkx graph.

make(nodes=None, edges=None, state=None)[source]

Construct graph from mol instance.

The input is a dictionary of properties to calculate. The dict-key can be chosen freely and will be graph attributes. The identifier is a string for built-in function e.g. ‘proton’. Or if args have to be provided: key : {‘class’: identifier, ‘args’:{ args_dict }} Otherwise you can provide a custom method via the the identifier dict of the form: key : {‘class’: function/class, ‘args’:{ args_dict }} The callable object of ‘class’ must accept as first argument this instance. Then key=key and then additional args from ‘args’:{ args_dict }.

Parameters
  • nodes (dict, optional) – Properties for nodes. Defaults to {‘proton’ : “proton” }

  • edges (dict, optional) – Properties for edges. Defaults to {‘bond’: ‘bond’} or {‘distance’: {‘class’: ‘distance’, ‘args’: {}}

  • state (dict, optional) – Properties for graph state. Defaults to {‘size’ : ‘size’}

Raises
Returns

This instance.

Return type

self

to_tensor(nodes=None, edges=None, state=None, trafo_nodes=None, trafo_edges=None, trafo_state=None, default_nodes=None, default_edges=None, default_state=None, out_tensor=<built-in function array>)[source]

Convert the nx graph into a dict of tensors which can be directly used for GCN.

The desired attributes must be given with a suitable conversion function plus default value. Here, one can add also the type of tensor or one-Hot mappings etc. and its default/zero state, if the attributes is not specified for a specific node/edge. The properties are always mapped to numpy arrays and then converted to out_tensor.

Parameters
  • nodes (list, optional) – Nodes properties. Defaults to [‘proton’].

  • edges (list, optional) – Edge properties. Defaults to [‘bond’].

  • state (list, optional) – State Properties. Defaults to [‘size’].

  • trafo_nodes (dict, optional) – Transformation function for nodes. Defaults to np.array.

  • trafo_edges (dict, optional) – Transformation function for edges. Defaults to np.array.

  • trafo_state (dict, optional) – Transformation function for state. Defaults to np.array.

  • default_nodes (dict, optional) – Zero Nodes properties. Defaults to np.array(0).

  • default_edges (dict, optional) – Zero Edge properties. Defaults to np.array(0).

  • default_state (dict, optional) – Zero State Properties. Defaults to np.array(0).

  • out_tensor (func) – Final Function for each node/edge/state. Default is np.array.

Returns

Graph tensors as dictionary.

Return type

dict

molreps.graph.rdkit_get_property_atoms(mol, key, prop, **kwargs)[source]
molreps.graph.rdkit_get_property_bonds(mol, key, prop, **kwargs)[source]
molreps.graph.rdkit_get_property_molstate(mol, key, prop, **kwargs)[source]

Module contents