pyxtal_ff.models.neuralnetwork¶
-
class
pyxtal_ff.models.neuralnetwork.Dataset(data, softmax, device, memory, fc, sc)[source]¶ Bases:
torch.utils.data.dataset.DatasetDefined a Dataset class based on PyTorch Dataset.
Tutorial: https://pytorch.org/tutorials/beginner/data_loading_tutorial.html.
-
class
pyxtal_ff.models.neuralnetwork.NeuralNetwork(elements, hiddenlayers, activation, random_seed, batch_size, epoch, device, alpha, softmax_beta, unit, force_coefficient, stress_coefficient, stress_group, restart, path, memory)[source]¶ Bases:
objectAtom-centered Neural Network model. The inputs are atom-centered descriptors: BehlerParrinello or Bispectrum. The forward propagation of the Neural Network predicts energy per atom, and the derivative of the forward propagation predicts force.
A machine learning interatomic potential can developed by optimizing the weights of the Neural Network for a given system.
Parameters: - elements (list) – A list of atomic species in the crystal system.
- hiddenlayers (list or dict) – [3, 3] contains 2 layers with 3 nodes each. Each atomic species in the crystal system is assigned with its own neural network architecture.
- activation (str) – The activation function for the neural network model. Options: tanh, sigmoid, and linear.
- random_seed (int) – Random seed for generating random initial random weights.
- batch_size (int) – Determine the number of structures in a batch per optimization step.
- epoch (int) – A measure of the number of times all of the training vectors are used once to update the weights.
- device (str) – The device used to train: ‘cpu’ or ‘cuda’.
- force_coefficient (float) – This parameter is used as the penalty parameter to scale the force contribution relative to the energy.
- stress_coefficient (float) – This parameter is used as the balance parameter scaling the stress contribution relative to the energy.
- stress_group (list of strings) – Only the intended group will be considered in stress training, i.e. [‘Elastic’].
- alpha (float) – L2 penalty (regularization) parameter.
- softmax_beta (float) – The parameters used for Softmax Energy Penalty function.
- unit (str) – The unit of energy (‘eV’ or ‘Ha’).
- restart (str) – Continuing Neural Network training from where it was left off.
- path (str) – A path to the directory where everything is saved.
- memory (str) – There are two options: ‘in’ or ‘out’. ‘in’ will use load all descriptors to memory as ‘out’ will call from disk as needed.
-
calculate_loss(models, batch)[source]¶ Calculate the total loss and MAE for energy and forces for a batch of structures per one optimization step.
-
calculate_properties(descriptor, bforce=True, bstress=False)[source]¶ A routine to compute energy, forces, and stress.
- descriptor: list
- list of x, dxdr, and rdxdr.
- energy, force, stress: bool
- If False, excluding the property from calculation.
- energy: float
- The predicted energy
- forces: 2D array [N_atom, 3] (if dxdr is provided)
- The predicted forces
- stress: 2D array [3, 3] (if rdxdr is provided)
- The predicted stress
-
evaluate(data, figname)[source]¶ Evaluating the train or test data set based on trained Neural Network model. Evaluate will only be performed in cpu mode.
-
get_descriptors_range(data)[source]¶ Calculate the range (min and max values) of the descriptors corresponding to all of the crystal structures.
Parameters: data (dict) – data contains atom-centered descriptors. Returns: The ranges of the descriptors for each chemical specie. Return type: dict
-
load_checkpoint(filename=None, method=None, args=None)[source]¶ Load PyTorch Neural Network models at previously saved checkpoint.
-
normalize(data, drange, unit, norm=[0.0, 1.0])[source]¶ Normalizing the descriptors to the range of [0., 1.] based on the min and max value of the entire descriptors.
Example: X.shape == [60, 10]; len(self.elements) == 2 X_norm -> {‘element1’: [40, 10], ‘element2’: [20, 10]}
Parameters: - data (str) – The directory path to the database
- drange – The range of the descriptors for each element species.
- unit (str) – The unit of energy (‘eV’ or ‘Ha’).
- norm (tuple of floats.) – The lower and upper bounds of the normalization.
Returns: The normalized descriptors.
Return type: dict
-
preprocess(TrainData)[source]¶ Preprocess TrainData to a convenient format for Neural Network training.