Package: elasticnet
Elastic netMachine learning model for predicting multi-component transition metal carbides (MTMCs)This is the manual to reproduce  results and support conclusions ofLattice Distortion Informed Exceptional Multi-Component Transition Metal Carbides Discovered by Machine Learning.We recommend using a Linux/Windows operating system to run the following examples, under thecurrent directory.Table of ContentsInstallationExample of using the well-trained modelTrain a new model from scratchPrepare DFT calculationsCollect DFT resultsRun main functionCollect input features and labelsTrainCheck training resultsPredictHigh-throughput predictTernary plotOther scriptsGet ROMget VECAbbreviationsInstallationInstall undercondaenvironmentCreate a new environmentconda create -n ElasticNet python==3.10Activate the environmentconda activate ElasticNetInstall packagepip install elasticnetAlternatively, you can install withpip.Install the package. Use--useroption if you don't have the root permission.pip install elasticnet --userIf your IP locates in mainland China, you may need to install it from the tsinghua mirror.pip install elasticnet -i https://pypi.tuna.tsinghua.edu.cn/simpleRequirements file:requirements.txtKey modulesnumpy==1.25.0    
scikit-learn==1.2.2   
tensorflow==2.10.0   
ase==3.22.1  
pandas==1.5.3Example of using the well-trained modelDownload the well-trained parameters:checkpointRun the following python code:fromelasticnetimportpredict_formulapf=predict_formula(config='input_config.json',ckpt_file='checkpoint')pf.predict(*['VNbTa','TiNbTa'])The mechanical properties of (VNbTa)C3 and (TiNbTa)C3 will show on the screen. The specific modulus of each column is: B, G, E, Hv, C11, C44.array([[294.43195,203.70157,496.67032,25.989697,632.3356,175.50716],[283.17245,201.96506,489.7816,26.824062,607.07336,178.52579]],dtype=float32)Train a new model from scratchPrepare DFT calculationsBulk optimization.Elastic constants calculation.Collect DFT resultsCollect elastic constants into a file withcsvextension. See example:files/HECC_properties_over_sample.CSV.You may refer to these papers to calculate modulus from C11, C12, and C44:PHYSICAL REVIEW B 87, 094114 (2013)andJournal of the European Ceramic Society 41 (2021) 6267-6274The*csvfile should contain at least these columns:nominal_formula,C11,C12,C44,B,G,E,Hv, andreal_formula. See example:files/HECC_properties_over_sample.CSV.Prepare configurations filesinput_config.json: defines how to generate input features and labels. You are recommended to download this file and modify then.VariableTypeMeaninginclude_moreboolIfTrue, thebulk_energy_per_formulaandvolume_per_formulaare also be included in the input features.split_testboolIfTrue, a new test set will be split from the dataset. For cross validation, it is OK to set this asFalse.clean_by_pearson_rboolClean input features. Highly correlated features will be removed if this isTrue.reduce_dimension_by_pcaboolClean input features byPCA. Choose one amongclean_by_pearson_randreduce_dimension_by_pca.prop_precursor_pathstrA file storing the properties of precursory binary carbides. File extension can be*.csvand*.json.  See example:file/HECC_precursors.csvmodel_save_pathstrPath for storingPCAmodel and other information when generating input features and labelspropslistA list of properties that are encoded into the input features. Choose among the column names offiles/HECC_precursors.csv.operatorslistA list of operators to expand the input dimension. Choose among: ['cube', 'exp_n', 'exp', 'plus', 'minus', 'multiply', 'sqrt', 'log10', 'log', 'square'].HECC_properties_pathstrA file contains the collected properties of MTMCs.labelslistA list of label names that need to fit/learn.soap_featuresboolWhether to useSOAPdescriptor.soap_configdictA python dict that defines the configuration ofSOAPdescriptor.   - input_structure_type: 'POSCAR' or 'CONTCAR'. Use 'POSCAR' or 'CONTCAR' to generateSOAPfeatures.   - You can find the explanations for other specifications here:SOAP.__init__train.json: defines how to train the machine-learning model.VariableTypeMeaningNodes_per_layerlistNumber of nodes of every hidden layersNumber_of_foldintNumber of cross-validation folds. Normally5or10.feature_filestrA file contains input features.label_filestrA file contains labels of samples.Activation_functionstrActivation function of hidden layers. Alternatives: 'relu', 'softmax', 'sigmoid', 'tanh'Output_activationstrActivation function of the output layer. Alternatives: 'relu', 'softmax', 'sigmoid', 'tanh'Number_of_out_nodeint/'auto'Number of nodes of the output layer. If there is onlyonecolumn in thelabel_file, this variable should be1. 'auto' is for multiple columns.OptimizerstrThe name of the optimizer. Examples:tf.keras.optimizersCost_functionstrName of cost function inTensorflow. Examples:tf.keras.lossesMetricslistA list of metrics to evaluate the model. Examples:tf.keras.metricsBatch_sizeintThe batch size. Seetf.keras.Model.fitEpochsintNumber of epochs for training. Seetf.keras.Model.fitVerboseintVerbosity mode. Seetf.keras.Model.fitRegularizationboolWhether to used the L2 regularization. Seetf.keras.regularizers.L2.Model_save_pathstrA folder to store the well-trained NN model.Log_save_pathstrA folder to store the training log.Prediction_save_pathstrA folder to store the predictions of input features after training.SEEDintRandom seed for shuffling input dataset.Run main functionpython -m elasticnetThe following python code will be executed.defmain():# prepare datasetfromelasticnet.prepare_inputimportx_main,y_mainx_main('input_config.json',load_PCA=False,save_PCA=True)y_main('input_config.json')# trainfromelasticnet.annimportCV_ML_RUN,load_and_predCV_ML_RUN('train.json')load_and_pred('train.json','x_data_after_pca.txt',write_pred_log=True,drop_cols=None)main()You may want to prepare the dataset and train the model in separate steps, see below â†“.Collect input features and labelsfromelasticnet.prepare_inputimportx_main,y_mainx_main('input_config.json',load_PCA=False,save_PCA=True)y_main('input_config.json')Three files will be generated:x_data_init.txt: input features withoutPCA.x_data_after_pca.txt: input features afterPCA.y_data.txt: labelsTrainRun the following python code.fromelasticnetimportCV_ML_RUN,load_and_predif__name__=='__main__':CV_ML_RUN('train.json')load_and_pred('train.json','x_data_after_pca.txt',write_pred_log=True,drop_cols=None)You can also executepython -m elasticnetdirectly in the console.  SeeRun main function.Check training resultsGenerated files/folderscheckpoint: A folder forPCAmodel, NN model, and other information for generating input features.cp.ckpt: Location of NN model.log: Learning curves and weights of all CV models.The file with extension*.global.acc.losssummarizes the model performance. Example:4_layer-80_80_80_80_nodes.global.acc.losspred: Predictions of input features.prediction_all.txt: all CV models.prediction_mean.txt: average of CV models.pca_model.joblib:PCAmodel.scale_range.json: Range to rescale input features.scale_range_1.json: Range to rescale input features again.PredictAfter training, run the following python code:fromelasticnetimportpredict_formulapf=predict_formula(config='input_config.json',ckpt_file='checkpoint')pf.predict(*['VNbTa','TiNbTa'])The mechanical properties of (VNbTa)C3 and (TiNbTa)C3 will show on the screen. The specific modulus of each column is: B, G, E, Hv, C11, C44.array([[294.43195,203.70157,496.67032,25.989697,632.3356,175.50716],[283.17245,201.96506,489.7816,26.824062,607.07336,178.52579]],dtype=float32)High-throughput predictRun the following python code:fromelasticnetimporthigh_throughput_predicthigh_throughput_predict()Output: ANN_predictions.xlsxTernary plotRun the following python code:fromelasticnetimportternary_plotternary_plot(elements=['Ti','Nb','Ta'])Alternatively,elements = ['VNbTa', 'Ti', 'Hf'].Output: phase_diagrams/**_diagram.csvPlot.Other scriptsGet ROMRun the following python code:fromelasticnetimportget_romROM=get_rom(config='input_config.json',formulas='formulas.txt',props=['B','G','E','Hv','VEC'])print(ROM)Output. If the formulas.txt contains ['VNbTa', 'TiNbTa'] only.array([[310.33922223,210.80075867,515.61666613,26.20022487,9.],[291.74733333,199.9075404,488.11937417,25.52194014,8.66666667]])Get VECVEC is simply the last column ofGet ROM.AbbreviationsAbbr.Full nameMTMCMulti-component transition metal carbidesHECCHigh-entropy carbide ceramicHECHigh-entropy ceramicMLMachine learningSOAPSmooth overlap of atomic positionsNNNeural networksCVcross validationROMRule of mixturesVECValence electron concentration