htesp.ml_processing

Install matminer to extract composition based magpie features and structure based Jarvis features.

FIX(15): matminer and scikit-learn are optional extras, but they used to be imported at module scope, so import htesp.ml_processing – and any package-wide import that reached it – failed with ImportError on an installation that only has the core dependencies. They are now imported inside the functions that use them, behind _require(), which explains how to install them.

Module Attributes

MUSTAR

Allen-Dynes Coulomb pseudopotential used by ml_tc()

Functions

allen_dynes(wlog, lam[, mustar])

Allen-Dynes Tc for array-like wlog (K) and lam.

class_accuracy([outfile])

Function to calculate accuracy measures for classification models.

mae_compute([outfile])

function to calculate mean-absolute-error (mae).

ml_tc([lam, wlog, calc_tc])

Function to compute critical temperature Tc from ML trained lambda and ML trained wlog :param lam: :type lam: .csv file for lambda :param wlog: :type wlog: .csv file for wlog :param calc_tc: :type calc_tc: .csv file to store calculated Tc :param Each .csv file has 3 columns: :param ID: :param target: :param prediction.: :param "ID.cif" be the structure file for particular "ID":

zip_alignn_output(folder, outfile[, epochs])

Function to compress output file of ALIGNN model to use as model for new prediction.

Classes

MlProcess([in_file])

This class processes output files from HTEPC package.

htesp.ml_processing.MUSTAR = 0.16

Allen-Dynes Coulomb pseudopotential used by ml_tc()

class htesp.ml_processing.MlProcess(in_file='result.csv')[source]

This class processes output files from HTEPC package. Command “mainprogram.py 21” extracts the result file “result.csv” from EPC calculation and stores relaxed structure in .cif format inside “cif” folder. Useful in Machine Learning work, especially for CGCNN, and ALIGNN models.

Parameters:

in_file (str, optional) – The input .csv file with at least an ID (material id). Default is ‘result.csv’.

data

DataFrame containing the data loaded from the input file.

Type:

pandas.DataFrame

prop

Placeholder for the property. Not initialized.

Type:

None

prop_list

List to store properties.

Type:

list

add_property(prop='energy_above_hull')[source]

Function to add a property in a new column.

Parameters:

prop (str, optional) – The name of the property as named in the Materials Project database. Default is “energy_above_hull”.

Returns:

Shape of the updated data.

Return type:

tuple

Notes

This method sets the specified property attribute, appends the property name to the property list, retrieves property data from Materials Project database using MpConnect, and adds the property data as a new column to the DataFrame.

If the property is “symmetry”, it retrieves the symmetry number from the Materials Project. For other properties, it retrieves the property value using MpConnect.

magpie_feature(outfile='magpie_featurize.csv')[source]

Function to add composition-based Magpie features from the matminer package.

Parameters:

outfile (str, optional) – The name of the .csv file to save the dataframe with columns containing Magpie features. Default is “magpie_featurize.csv”.

Notes

This method featurizes the composition data in the dataframe using Magpie features from the matminer package. It utilizes the StrToComposition class to convert composition strings into Composition objects, and then adds Magpie features using ElementProperty.from_preset.

The resulting dataframe with Magpie features is saved to the specified outfile.

jarvis_structure_feature(outfile='jarvis_featurize.csv')[source]

Function to add structure-based Jarvis features from the matminer package.

Parameters:

outfile (str, optional) – The name of the .csv file to save the dataframe with columns containing Jarvis features. Default is “jarvis_featurize.csv”.

Notes

This method retrieves structures using Materials Project API based on material IDs. It then adds Jarvis features using JarvisCFID from the matminer package.

If the file ‘config.json’ or its relative path exists, it assumes it contains an API key for the Materials Project database. It retrieves the key and uses it to authenticate with MPRester. If the file does not exist, it prints a message indicating that ‘config.json’ is not found.

The resulting dataframe with Jarvis features is saved to the specified outfile.

class_convert(prop='Tc', cutoff=1.0)[source]

Function to change a property into a label (0 or 1) used to train and test CGCNN classification models.

Parameters:
  • prop (str, optional) – The property to be used for labeling. Default is ‘Tc’.

  • cutoff (float, optional) – The cutoff value to separate data into binary labels. Default is 1.0.

Notes

This method creates a new column ‘target’ in the dataframe and assigns binary labels (0 or 1) based on whether the property value in the specified column ‘prop’ is greater than the cutoff value.

write_output(columns, outfile='result-new.csv')[source]

Function to write new file :param columns: :type columns: (list of str) columns to be extracted. :param outfile: :type outfile: .csv file

Return type:

shape of current state of data

write_id_prop_csv(mode='alignn', prop='Tc', outfile='id_prop.csv')[source]

function to write id_prop.csv file required to work with CGCNN and ALIGNN models. :param mode: :type mode: (str) name of model. Default: ‘alignn’ or ‘ALIGNN’ :param prop: :type prop: (float) property :param outfile: :type outfile: id_prop.csv file

htesp.ml_processing.allen_dynes(wlog, lam, mustar=0.16)[source]

Allen-Dynes Tc for array-like wlog (K) and lam.

FIX(14): the denominator lam - mustar*(1 + 0.62*lam) used to be wrapped in np.abs(). That turns the pole at lambda ~= 0.178 into a mirror and manufactures a finite, positive Tc for every lambda below it, where the Allen-Dynes formula in fact has no superconducting solution. The denominator is used as-is and a non-positive one yields NaN, which is the physically correct answer, with a warning.

htesp.ml_processing.ml_tc(lam='lambda.csv', wlog='wlog.csv', calc_tc='Tc_calc.csv')[source]

Function to compute critical temperature Tc from ML trained lambda and ML trained wlog :param lam: :type lam: .csv file for lambda :param wlog: :type wlog: .csv file for wlog :param calc_tc: :type calc_tc: .csv file to store calculated Tc :param Each .csv file has 3 columns: :param ID: :param target: :param prediction.: :param “ID.cif” be the structure file for particular “ID”:

htesp.ml_processing.mae_compute(outfile='mae.in')[source]

function to calculate mean-absolute-error (mae). :param outfile: :type outfile: .in file to store mae values for each file

htesp.ml_processing.class_accuracy(outfile='classification_score.in')[source]

Function to calculate accuracy measures for classification models. Accuracy: TP+TN/(TP+TN+FP+FN) Precision: TP/(TP+FP) Recall : TP/(TP+FN) F1-score : 2*(Precision*Recall)/(Precision+Recall) :param outfile: :type outfile: .in file to store mae values for each file

htesp.ml_processing.zip_alignn_output(folder, outfile, epochs=3000)[source]

Function to compress output file of ALIGNN model to use as model for new prediction. :param folder: :type folder: output folder to compress :param outfile: :type outfile: name of .zip file to be used as a ALIGNN model. :param epochs: :type epochs: (int) number of epochs for training