megnet.layers.graph.cgcnn module

class CrystalGraphLayer(activation='relu', use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None, **kwargs)[source]

Bases: megnet.layers.graph.base.GraphNetworkLayer

The CGCNN graph implementation as described in the paper

Xie et al. PHYSICAL REVIEW LETTERS 120, 145301 (2018)

Parameters
  • activation (str) – Default: None. The activation function used for each sub-neural network. Examples include ‘relu’, ‘softmax’, ‘tanh’, ‘sigmoid’ and etc.

  • use_bias (bool) – Default: True. Whether to use the bias term in the neural network.

  • kernel_initializer (str) – Default: ‘glorot_uniform’. Initialization function for the layer kernel weights,

  • bias_initializer (str) – Default: ‘zeros’

  • activity_regularizer (str) – Default: None. The regularization function for the output

  • kernel_constraint (str) – Default: None. Keras constraint for kernel values

  • bias_constraint (str) – Default: None .Keras constraint for bias values

call(inputs, mask=None)

the logic of the layer, returns the final graph

compute_output_shape(input_shape)[source]

compute static output shapes, returns list of tuple shapes

build(input_shape)[source]

initialize the weights and biases for each function

phi_e(inputs)[source]

update function for bonds and returns updated bond attribute e_p

rho_e_v(e_p, inputs)[source]

aggregate updated bonds e_p to per atom attributes, b_e_p

phi_v(b_e_p, inputs)[source]

update the atom attributes by the results from previous step b_e_p and all the inputs returns v_p.

rho_e_u(e_p, inputs)[source]

aggregate bonds to global attribute

rho_v_u(v_p, inputs)[source]

aggregate atom to global attributes

get_config()[source]

part of keras interface for serialization

build(input_shapes)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Parameters

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Parameters

input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns

An input shape tuple.

get_config()[source]

Part of keras layer interface, where the signature is converted into a dict :returns: configurational dictionary

phi_e(inputs)[source]

This is for updating the edge attributes ek’ = phi_e(ek, vrk, vsk, u)

Parameters

inputs (Sequence) – list or tuple for the graph inputs

Returns

updated edge/bond attributes

phi_u(b_e_p, b_v_p, inputs)[source]

u’ = phi_u(ar e’, ar v’, u) :param b_e_p: edge/bond to global aggregated tensor :type b_e_p: tf.Tensor :param b_v_p: node/atom to global aggregated tensor :type b_v_p: tf.Tensor :param inputs: list or tuple for the graph inputs :type inputs: Sequence

Returns

updated globa/state attributes

phi_v(b_ei_p, inputs)[source]

Step 3. Compute updated node attributes v_i’ = phi_v(ar e_i, vi, u)

Parameters
  • b_ei_p (tf.Tensor) – edge-to-node aggregated tensor

  • inputs (Sequence) – list or tuple for the graph inputs

Returns

updated node/atom attributes

rho_e_u(e_p, inputs)[source]

let V’ = {v’} i = 1:Nv let E’ = {(e_k’, rk, sk)} k = 1:Ne ar e’ = rho_e_u(E’)

Parameters
  • e_p (tf.Tensor) – updated edge/bond attributes

  • inputs (Sequence) – list or tuple for the graph inputs

Returns

edge/bond to global/state aggregated tensor

rho_e_v(e_p, inputs)[source]

Reduce edge attributes to node attribute, eqn 5 in the paper :param e_p: updated bond :param inputs: the whole input list

Returns: summed tensor

rho_v_u(v_p, inputs)[source]

ar v’ = rho_v_u(V’)

Parameters
  • v_p (tf.Tensor) – updated atom/node attributes

  • inputs (Sequence) – list or tuple for the graph inputs

Returns

atom/node to global/state aggregated tensor