pyxtal_ff.models.polynomialregression

class pyxtal_ff.models.polynomialregression.PR(elements, force_coefficient, stress_coefficient, stress_group, order, path, alpha, norm, d_max=None)[source]

Bases: object

Atom-centered Polynomial Regression (PR) model. PR utilizes linear regression to predict the energy and forces based on the atom-centered descriptors as the input values.

Parameters:
  • elements (list) – A list of atomic species in the crystal system.
  • force_coefficient (float) – This parameter is used in the penalty function 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.
  • order (int) – The order of the polynomial. Order 1 is for linear and order 2 is for quadratic.
  • path (str) – The path of the directory where everything is saved.
  • alpha (float) – L2 penalty (regularization term) parameter.
  • norm (int (*PR)) – This argument defines a model to calculate the regularization term. It takes only 1 or 2 as its value: Manhattan or Euclidean norm, respectively. If alpha is None, norm is ignored.
  • d_max (int) – The maximum number of descriptors (d) used in Linear Regression model.
LinearRegression(X, y, w, alpha, norm=2)[source]

Perform linear regression.

calculate_properties(descriptor, bforce=True, bstress=False)[source]

A routine to compute energy, forces, and stress.

descriptor: list
list of x, dxdr, and rdxdr.
benergy, bforce, bstress: 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
dump_evaluate(predicted, true, filename)[source]

Dump the evaluate results to text files.

evaluate(data, figname)[source]

Evaluating the train or test data set.

load_checkpoint(filename=None)[source]

Load Polynomial Regression file from PyTorch.

mean_absolute_error(true, predicted)[source]

Calculate mean absolute error of energy or force.

mean_squared_error(true, predicted)[source]

Calculate mean square error of energy or force.

parse_descriptors(data, fc=True, sc=False, train=True)[source]

Parse descriptors and its gradient to 2-D array.

Returns:X – d is the total number of descriptors, n is the total number of structures, and m is the total number atoms in the entire structures. If force_coefficient is None, X has the shape of [n, d].
Return type:2-D array [n+m*3, d]
parse_features(data)[source]

Parse features (energy, forces, and stress) into 1-D array.

Returns:
  • y (1-D array [n+m*3+n*3*3,]) – y contains the energy, forces, and stress of structures in 1-D array. Force and stress may not be present.

    n = # of structures m = # of atoms in a unit cell

  • w (1-D array [n+m*3+n*3*3,]) – w contains the relative importance between energy, forces, and stress.
r2_score(true, predicted)[source]

Calculate the r square of energy or force.

save_checkpoint(des_info, filename=None)[source]

Save Polynomial Regression model to PyTorch.

save_weights_to_txt(des_info)[source]

Saving the model weights to txt file.

train(TrainData, optimizer)[source]

Fitting Linear Regression model.