xnn.gnn.models.cgcnn.CGCNN#

class xnn.gnn.models.cgcnn.CGCNN(n_features=64, n_interactions=3, n_rbf=41, cutoff=8.0, max_neighbors=12, rbf_start=0.0, rbf_max=None, gamma=None, readout_sizes=(128,), normalization='batch', residual_activation=True, n_outputs=1, classification=False, dropout=None, atom_features='cgcnn', n_elements=101, property_scale=1.0, property_shift=0.0, weight_init='torch')[source]#

Bases: ExactFloat64Constants, InteratomicPotential, FastPathModule

CGCNN property model of crystals.

See the module docstring for the equations and the defaults.

Parameters:
  • n_features (int, optional) – Width of the atom features, by default 64.

  • n_interactions (int, optional) – Number of convolutions, by default 3.

  • n_rbf (int, optional) – Number of Gaussians expanding the bond lengths, by default 41.

  • cutoff (float, optional) – Neighbor search radius in Angstrom, by default 8.0.

  • max_neighbors (int or None, optional) – Nearest neighbors kept per atom, by default 12; None keeps every neighbor within the cutoff.

  • rbf_start (float, optional) – Position of the first Gaussian, by default 0.

  • rbf_max (float or None, optional) – Position of the last Gaussian; None (default) is the cutoff.

  • gamma (float or None, optional) – Exponent of the Gaussians, exp(-gamma (r - mu)^2); None (default) is the inverse square of the center spacing (25 for the default 0.2 Angstrom grid).

  • readout_sizes (sequence of int, optional) – Hidden layers after the pooling, by default (128,).

  • normalization (str or None, optional) – "batch" (default) or None (the paper’s eq. 5).

  • residual_activation (bool, optional) – Softplus after every residual sum, by default True (the paper: False).

  • n_outputs (int, optional) – Number of properties per crystal, by default 1.

  • classification (bool, optional) – Two-class output: "properties" is the probability of the second class and "log_probabilities" holds both. Default False.

  • dropout (float or None, optional) – Dropout after the first hidden layer; None (default) is 0.5 for a classifier and 0 otherwise.

  • atom_features (str, path, mapping or array, optional) – The fixed element features: "cgcnn" (default, the authors’ table, downloaded on first use), "onehot", a file in the authors’ atom_init.json format, a mapping of atomic numbers to vectors or an array of rows (see read_atom_features()).

  • n_elements (int, optional) – Rows of the "onehot" table, by default 101.

  • property_scale (float, optional) – Standardization of the output, by default 1 and 0.

  • property_shift (float, optional) – Standardization of the output, by default 1 and 0.

  • weight_init (str, optional) – Initialization of the dense layers (a key of WEIGHT_INITS), by default "torch".

fast_supported(device, dtype)[source]#

The fast stage reads plain dense layers and plain batch normalizations with running statistics, the same in every convolution.

Parameters:
Return type:

bool

set_use_fast(use_fast)[source]#

Choose the implementation of the network up to the pooling.

Parameters:

use_fast (bool or str) – "auto" (the default): the compiled stage of xnn.gnn.fast.cgcnn on a GPU above the size crossover measured for evaluation (AUTO_POLICY) or training (AUTO_POLICY_TRAINING); True: always (as written on a CPU); False: the reference. The stage serves graphs whose atoms all keep the same number of neighbors (crystals) and agree with the reference to about 1e-6 relative in float32 and 1e-14 in float64, with the same first and second derivatives.

Returns:

self.

Return type:

CGCNN

set_property_scale_shift(scale, shift)[source]#

Set the output standardization scale * y + shift (e.g. the training-set std and mean).

Parameters:
Return type:

None

forward(data)[source]#

Predict the property of every crystal.

Parameters:

data (AtomicGraph) – The batch, with a neighbor list of at least cutoff.

Returns:

"properties", shape (B,) (or (B, n_outputs)), "structure_features", the pooled atom features (B, F), and for a classifier "log_probabilities" (B, 2).

Return type:

dict[str, Tensor]

classmethod from_foundation(name='cgcnn-formation-energy-per-atom', dtype=None, cache_dir=None, quiet=False)[source]#

Load one of the authors’ pretrained models (see xnn.gnn.models.cgcnn_foundation).

Parameters:
  • name (str, optional) – A key of FOUNDATION_MODELS, by default the formation energy per atom (eV/atom).

  • dtype (torch.dtype or str, optional) – Final dtype; None keeps the checkpoint’s float32.

  • cache_dir (str or pathlib.Path, optional) – Model cache directory.

  • quiet (bool, optional) – Hide the download progress bars. Default False.

Returns:

The converted model, in evaluation mode.

Return type:

CGCNN

classmethod from_config(cfg)[source]#

Build a CGCNN from a configuration object.

Core fields: cfg.n_features (atom feature width), cfg.n_interactions (convolutions), cfg.n_rbf and cfg.cutoff. Everything else is read from cfg.extra (max_neighbors, rbf_start, rbf_max, gamma, readout_sizes, normalization, residual_activation, n_outputs, classification, dropout, atom_features, n_elements, property_scale, property_shift, weight_init); the authors’ spellings are translated by xnn.common.config.translate.

Parameters:

cfg (xnn.common.config.schema.ModelConfig) – The core model config.

Returns:

Instantiated model.

Return type:

CGCNN