encodermap.models package#

Submodules#

encodermap.models.layers module#

Module that implements custom layers. Mainly needed for handling periodicity, backmapping or sparsity.

class encodermap.models.layers.BackMapLayer(*args, **kwargs)[source]#

Bases: Layer

Layer that implements backmapping from torsions-angles-distances to euclidean coordinates.

__init__()[source]#

Instantiate the layer

call(inputs)[source]#

Call the layers, inputs should be a tuple shaped, so that it can be split into distances, angles, dihedrals = inputs

class encodermap.models.layers.MeanAngles(*args, **kwargs)[source]#

Bases: Layer

Layer that implements the mean of periodic angles.

__init__(parameters, print_name, multiples_shape)[source]#

Instantiate the layer.

call(inputs)[source]#

Call the layer

class encodermap.models.layers.PeriodicInput(*args, **kwargs)[source]#

Bases: Layer

Layer that handles periodic input. Needed, if angles are treated. Input angles will be split into sin and cos components and a tensor with shape[0] = 2 * inp_shape[0] will be returned

__init__(parameters, print_name, trainable=False)[source]#

Instantiate the layer. Need parameters to get the info about the periodicity. Although angles are most often used, who knows what hyper-toroidal manifold your data lies in.

call(inputs)[source]#

Call the layer.

class encodermap.models.layers.PeriodicOutput(*args, **kwargs)[source]#

Bases: Layer

Layer that reverses the PeriodicInputLayer.

__init__(parameters, print_name, trainable=False)[source]#

Instantiate the layer, We also need to know here, what periodicity is needed.

call(inputs)[source]#

Calls the layer, Inputs shold be a tuple of (sin, cos) of the same angles

class encodermap.models.layers.Sparse(*args, **kwargs)[source]#

Bases: Dense

Simple subclass of tf.keras.layers.Dense, which implements sparse_dense_matmul

call(inputs)[source]#

Call the layer.

encodermap.models.models module#

ToDo: * Add some nice images to the plot_model of the functional model.

encodermap.models.models.gen_functional_model(input_dataset, parameters=None, reload_layers=None, sparse=False)[source]#

Builds a model to specification of parameters using the functional API.

The functional API is much more flexible than the sequential API, in that models with multiple inputs and outputs can be defined. Custom-layers and sub-models can be intermixed. In EncoderMap’s case the functional API is used to build the AngleDihedralCartesianAutoencoder, which takes input data in form of a tf.data.Dataset with:

  • backbone_angles (angles between C, CA, N - atoms in the backbone).

  • backbone_torsions (dihedral angles in the backbone, commonly known as omega, phi, psi).

  • cartesian_coordinates (coordinates of the C, CA, N backbone atoms. This data has ndim 3, the other have ndim 2).

  • backbone_distances (distances between the C, CA, N backbone atoms).

  • sidechain_torsions (dihedral angles in the sidechain, commonly known as chi1, chi2, chi3, chi4, chi5).

Packing and unpacking that data in the correct manner is important. Make sure to double check whether you are using angles or dihedrals. A simple print of the shape can be enough.

In the functional model all operations are tf.keras.layers, meaning that the projection onto a unit_circle that the SequentialModel does in its call() method needs to be a layer. The FunctionalModel consist of 5 main parts:

  • Angle Inputs: The provided dataset is unpacked and the periodic data of the angles is projected onto

    a unit-circle. If the angles are in gradians, they will also be normalized into a [-pi, pi) interval.

  • Autoencoder: The trainable part of the network consists of the Autoencoder part build to the specifications

    in the provided parameters. Here, Dense layers are stacked. Only the angles and torsions are fed into the Autoencoder. The Distances and Cartesians are used later.

  • Angle Outputs: The angles are recalculated from their unit-circle inputs.

  • Back-Mapping. The backmapping layer takes backbone_angles and backbone_dihedrals, backbone_distances to

    calculate new cartesian coordinates.

  • Pairwise Distances: The pairwise distances of the input cartesians and the back-mapped cartesians are calculated.

Parameters:
  • input_dataset (tf.data.Dataset) – The dataset with the data in the order given in the explanation.

  • parameters (Union[em.ADCParameters, None], optional) – The parameters to be used to build the network. If None is provided the default parameters in encodermap.ADCParameters.defaults is used. You can look at the defaults with print(em.ADCParameters.defaults_description()). Defaults to None.

  • reload_layers (Union[None, list], optional) – List of layers that will be reloaded when reloading the model from disk. Defaults to None, when a new model should be built.

Raises:

AssertionError – AssertionErrors will be raised when the input data is not formatted correctly. This means, if len(cartesians) != len(distances) - 1, or len(cartesians) != len(angles) - 2. This can also mean, the input dataset is not packed correctly. Please keep the order specified above. This can also mean, that the provided protein is not linear (branched, circular, …).

Returns:

A subclass of tf.keras.Model build with specified parameters.

Return type:

em.FunctionalModel

encodermap.models.models.gen_sequential_model(input_shape, parameters=None, sparse=False)[source]#

Returns a tf.keras Model build with the specified input shape and the parameters in the Parameters class.

Parameters:
  • input_shape (int) – The input shape of the returned model. In most cases that is data.shape[1] of your data.

  • parameters (Union[encodermap.Parameters, encodermap.ADCParameters, None], optional) – The parameters to use on the returned model. If None is provided the default parameters in encodermap.Parameters.defaults is used. You can look at the defaults with print(em.Parameters.defaults_description()). Defaults to None.

Returns:

A subclass of tf.keras.Model build with specified parameters.

Return type:

em.SequentialModel

Module contents#