Network

Class

class atomdnn.network.Network(elements=None, descriptor=None, arch=None, activation_function=None, weights_initializer=<function random_normal>, bias_initializer=<function zeros>, import_dir=None)[source]

The nueral network is built based on tf.Module.

Parameters:
  • elements (python list) – list of element in the system, e.g. [C,O,H]

  • descriptor (dictionary) – descriptor parameters

  • arch – network architecture, e.g. [10,10,10], 3 dense layers each with 10 neurons

  • activation_function – any avialiable Tensorflow activation function, e.g. ‘relu’

  • weighs_initializer – the way to initialize weights, default one is tf.random.normal

  • bias_initializer – the way to initialize bias, default one is tf.zeros

  • import_dir – the directory of a saved model to be loaded

inflate_from_file(imported)[source]

Inflate network object from a SavedModel.

Parameters:

imported – a saved tensorflow neural network model

compute_pe(fingerprints, atom_type)[source]

Forward pass of the network to compute potential energy. Parallel networks are used for multiple atom types.

Parameters:
  • fingerprints – 3D array [batch_size,atom_num,fingerprints_num]

  • atom_type – 2D array [batch_size, atom_num]

Returns:

total potential energy and per-atom potential energy

compute_force_stress(dEdG, input_dict)[source]

Compute force and stress.

Parameters:
  • dEdG – derivatives of per-atom potential energy w.r.t. descriptors

  • input_dict – input dictionary data

Returns:

force per atom and stress tensor

predict(input_dict, compute_force=True, pe_peratom=False, training=False)[source]

Predict energy, force and stress.

Parameters:
  • input_dict – input dictionary data

  • compute_force (bool) – True to compute force and stress

  • pe_peratom (bool) – True to output per atom potential energy

  • training (bool) – True when used during training

Returns:

potential energy, force and stress

Return type:

dictionary

inference(filename, format, **kwargs)[source]

Predict potential energy, force and stress directly from one atomic structure input file. This function first computes descriptors and then call predict function.

Arg:

filename: name of the atomic structure input file format: ‘lammp-data’,’extxyz’,’vasp’ etc. See complete list on https://wiki.fysik.dtu.dk/ase/ase/io/io.html#ase.io.read kwargs: used to pass optional file styles

evaluate(dataset, batch_size=None, return_prediction=True, compute_force=True)[source]

Do evaluation on trained model.

Parameters:
  • dataset – tensorflow dataset used for evaluation

  • batch_size – default is total data size

  • return_prediction (bool) – True for returning prediction resutls

  • compute_force (bool) – True for computing force and stress

loss_function(true, pred)[source]

Build-in tensorflow loss functions can be used. Customized loss function can be also defined here.

Parameters:
  • true (tensorflow tensor) – true output data

  • pred (tensorflow tensor) – predicted results

loss(true_dict, pred_dict, training=False, validation=False)[source]

Compute losses for energy, force and stress.

Parameters:
  • true_dict (dictionary) – dictionary of outputs data

  • pred_dict (dictionary) – dictionary of predicted results

  • training (bool) – True for loss calculation during training

  • validation (bool) – True for loss calculation during validation

Returns:

if training is true, return total_loss and loss_dict(loss dictionary), otherwise(for evaluation) return loss_dict

train_step(input_dict, output_dict)[source]

A single training step.

Parameters:
  • input_dict – input dictionary data

  • output_dict – output dictionary data

Returns:

loss dictionary

validation_step(input_dict, output_dict)[source]

A single validation step.

Parameters:
  • input_dict – input dictionary data

  • output_dict – output dictionary data

Returns:

loss dictionary

compute_scaling_factors(train_dataset)[source]

Compute scaling factors using training dataset.

scaling_dataset(dataset)[source]

Scaling a dataset with the scaling factors calculated with compute_scaling_factors().

train(train_dataset, validation_dataset=None, early_stop=None, nepochs_checkpoint=None, scaling=None, batch_size=None, epochs=None, loss_fun=None, optimizer=None, lr=None, decay=None, loss_weights=None, compute_all_loss=False, shuffle=True, append_loss=False)[source]

Train the neural network.

Parameters:
  • train_dataset (tfdataset) – dataset used for training

  • validation_dataset (tfdataset) – dataset used for validation

  • early_stop (dictionary) – condition for stop training, e.g. {‘train_loss’:[0.01,3]} means stop when train loss is less than 0.01 for 3 times

  • scaling (string) – = None, ‘std’ or ‘norm’

  • batch_size – the training batch size

  • epochs – training epochs

  • loss_fun (string) – loss function, ‘mae’, ‘mse’, ‘rmse’ and others

  • opimizer (string) – any Tensorflow optimizer such as ‘Adam’

  • lr (float) – learning rate, it is ignored if decay is provided

  • decay (dictionary) – parameters for exponentialDecay, keys are: ‘initial_lr’,’decay_steps’ and ‘decay_rate’

  • loss_weight (dictionary) – weights assigned to loss function, e.g. {‘pe’:1,’force’:1,’stress’:0.1}

  • compute_all_loss (bool) – compute loss for force and stress even when they are not used for training

  • shuffle (bool) – shuffle training dataset during training

  • append_loss (bool) – append loss history

plot_loss(start_epoch=1, saveplot=False, **kwargs)[source]

Plot the losses.

Parameters:
  • start_epoch – plotting starts from start_epoch

  • figsize – set the fingersize, e.g. (8,4)

  • saveplot (bool) – if true, save the plots to “plot_loss” folder

  • kwargs – optional parameters for figures, default values are: figfolder = ‘./loss_figures’, the folder name for saving figures figsize = (8,5) linewidth = [1,1] for train and validation loss plot color =[‘blue’,’darkgreen’] label = [‘train loss’,’validation loss’] linestyle = [‘-‘,’-‘] markersize = [5,5] xlabel = ‘epoch’ ylabel = {‘pe’:’loss(eV)’, ‘force’:’loss(eV/A),’stress’:’loss(GPa)’} format = ‘pdf’

Functions

atomdnn.network.save(obj, model_dir)[source]

Save a trained model.

Parameters:
  • model_dir – directory for the saved neural network model

  • descriptor (dictionary) – descriptor parameters, used for LAMMPS prediction

atomdnn.network.load(model_dir)[source]

Load a saved model.

Parameters:

model_dir – directory of a saved neural network model

atomdnn.network.get_signature(model_dir)[source]

Run shell command ‘saved_model_cli show –dir model_dir –tag_set serve –signature_def serving_default’, and get the signature of the network from the shell outputs. SavedModel Command Line Interface (CLI) is a Tensorflow tool to inspect a SavedModel.

Parameters:

model_dir – directory for a saved neural network model

atomdnn.network.print_signature(model_dir)[source]

Print the neural network signature.

Parameters:

model_dir – directory for a saved neural network model