Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alignn

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alignn

alignn

  • 2024.10.30
  • PyPI
  • Socket score

Maintainers
1

alt text codecov PyPI version GitHub tag (latest by date) GitHub code size in bytes GitHub commit activity Downloads

Table of Contents

ALIGNN & ALIGNN-FF (Introduction)

The Atomistic Line Graph Neural Network (https://www.nature.com/articles/s41524-021-00650-1) introduces a new graph convolution layer that explicitly models both two and three body interactions in atomistic systems. This is achieved by composing two edge-gated graph convolution layers, the first applied to the atomistic line graph L(g) (representing triplet interactions) and the second applied to the atomistic bond graph g (representing pair interactions).

Atomisitic line graph neural network-based FF (ALIGNN-FF) (https://pubs.rsc.org/en/content/articlehtml/2023/dd/d2dd00096b ) can be used to model both structurally and chemically diverse systems with any combination of 89 elements from the periodic table, specially for structural optimization. To train the ALIGNN-FF model, we have used the JARVIS-DFT dataset which contains around 75000 materials and 4 million energy-force entries, out of which 307113 are used in the training. These models can be further finetuned, or new models can be developed from scratch on a new dataset.

ALIGNN layer schematic

Installation

First create a conda environment: Install miniconda environment from https://conda.io/miniconda.html Based on your system requirements, you'll get a file something like 'Miniconda3-latest-XYZ'.

Now,

bash Miniconda3-latest-Linux-x86_64.sh (for linux)
bash Miniconda3-latest-MacOSX-x86_64.sh (for Mac)

Download 32/64 bit python 3.10 miniconda exe and install (for windows)

Now, let's make a conda environment, say "my_alignn", choose other name as you like::

conda create --name my_alignn python=3.10 -y
conda activate my_alignn
conda install dgl=2.1.0 pytorch torchvision torchaudio pytorch-cuda -c pytorch -c nvidia
conda install alignn -y
Method 2 (GitHub based installation)

You can laso install a development version of alignn by cloning the repository and installing in place with pip:

conda create --name my_alignn python=3.10 -y
conda activate my_alignn
conda install dgl=2.1.0 pytorch torchvision torchaudio pytorch-cuda -c pytorch -c nvidia
git clone https://github.com/usnistgov/alignn
cd alignn
python -m pip install -e .
Method 3 (using pypi):

As an alternate method, ALIGNN can also be installed using pip. Note, we have received several messages regarding dgl installation issues. You can look into dgl installation here. Example for PyTorch 2.1+CUDA 12.1+Pip(Stable)+Windows:

pip install  -q dgl -f https://data.dgl.ai/wheels/torch-2.1/cu121/repo.html
pip install alignn

With no GPU/CUDA:

pip install -q dgl -f https://data.dgl.ai/wheels/torch-2.1/repo.html
pip install alignn

You can find out installation examples in Google Colab notebooks below

Examples

NotebooksGoogle ColabDescriptions
Regression task (grpah wise prediction)Open in Google ColabExamples for developing single output regression model for exfoliation energies of 2D materials.
Machine learning force-field training from scratchOpen in Google ColabExamples of training a machine learning force field for Silicon.
ALIGNN-FF Relaxer+EV_curve+Phonons+Interface gamma_surface+Interface separationOpen in Google ColabExamples of using pre-trained ALIGNN-FF force-field model.
Scaling/timing comaprisonOpen in Google ColabExamples of analyzing scaling
Running MD for Melt-QuenchOpen in Google ColabExamples of making amorphous structure with moelcular dynamics.
Miscellaneous tasksOpen in Google ColabExamples for developing single output (such as formation energy, bandgaps) or multi-output (such as phonon DOS, electron DOS) Regression or Classification (such as metal vs non-metal), Using several pretrained models.

Here, we provide examples for property prediction tasks, development of machine-learning force-fields (MLFF), usage of pre-trained property predictor, MLFFs, webapps etc.

Dataset preparation for property prediction tasks

The main script to train model is train_alignn.py. A user needs at least the following info to train a model: 1) id_prop.csv with name of the file and corresponding value, 2) config_example.json a config file with training and hyperparameters.

Users can keep their structure files in POSCAR, .cif, .xyz or .pdb files in a directory. In the examples below we will use POSCAR format files. In the same directory, there should be an id_prop.csv file.

In this directory, id_prop.csv, the filenames, and correponding target values are kept in comma separated values (csv) format.

Here is an example of training OptB88vdw bandgaps of 50 materials from JARVIS-DFT database. The example is created using the generate_sample_data_reg.py script. Users can modify the script for more than 50 data, or make their own dataset in this format. For list of available datasets see Databases.

The dataset in split in 80:10:10 as training-validation-test set (controlled by train_ratio, val_ratio, test_ratio) . To change the split proportion and other parameters, change the config_example.json file. If, users want to train on certain sets and val/test on another dataset, set n_train, n_val, n_test manually in the config_example.json and also set keep_data_order as True there so that random shuffle is disabled.

A brief help guide (-h) can be obtained as follows.

train_alignn.py -h
Regression example

Now, the model is trained as follows. Please increase the batch_size parameter to something like 32 or 64 in config_example.json for general trainings.

train_alignn.py --root_dir "alignn/examples/sample_data" --config "alignn/examples/sample_data/config_example.json" --output_dir=temp
Classification example

While the above example is for regression, the follwoing example shows a classification task for metal/non-metal based on the above bandgap values. We transform the dataset into 1 or 0 based on a threshold of 0.01 eV (controlled by the parameter, classification_threshold) and train a similar classification model. Currently, the script allows binary classification tasks only.

train_alignn.py --root_dir "alignn/examples/sample_data" --classification_threshold 0.01 --config "alignn/examples/sample_data/config_example.json" --output_dir=temp
Multi-output model example

While the above example regression was for single-output values, we can train multi-output regression models as well. An example is given below for training formation energy per atom, bandgap and total energy per atom simulataneously. The script to generate the example data is provided in the script folder of the sample_data_multi_prop. Another example of training electron and phonon density of states is provided also.

train_alignn.py --root_dir "alignn/examples/sample_data_multi_prop" --config "alignn/examples/sample_data/config_example.json" --output_dir=temp
Force-field training

To train ALIGNN-FF we can use the same train_alignn.py script which uses atomwise_alignn model.

AtomWise prediction example which looks for similar setup as before but unstead of id_prop.csv, it requires id_prop.json file (see example in the sample_data_ff directory). The json contains entries such as jid, energy, forces and stress. An example to compile vasprun.xml files into a id_prop.json is kept here. Note ALIGNN-FF requires energy stored as energy per atom:

train_alignn.py --root_dir "alignn/examples/sample_data_ff" --config "alignn/examples/sample_data_ff/config_example_atomwise.json" --output_dir="temp"

To finetune model, use --restart_model_path tag as well in the above with the path of a pretrained ALIGNN-FF model with same model confurations.

train_alignn.py --root_dir "alignn/examples/sample_data_ff" --restart_model_path "temp/best_model.pt" --config "alignn/examples/sample_data_ff/config_example_atomwise.json" --output_dir="temp1"

Starting version v2024.10.30, we also allow global training for multi-output along with energy (graph wise output), forces (atomwise gradients), charges/magnetic moments etc. (atomwise but non-gradients) properties with or without additional fingerprints/features in graph. See examples here.

Multi-GPU training is allowed with DistributedDataParallel with torchrun command. This feature is not thoroughly tested yet. Example:

torchrun --nproc_per_node=4 train_alignn.py --root_dir DataDir --config config.json --output_dir temp

For multi-GPU training make sure you have correct SLURM/PBS script setup correctly such as #SBATCH -n 4, #SBATCH -N 1, #SBATCH --gres=gpu:4 etc.

High-throughput like training: Users can also try training using multiple example scripts to run multiple dataset (such as JARVIS-DFT, Materials project, QM9_JCTC etc.). Look into the alignn/scripts/train_*.py folder. This is done primarily to make the trainings more automated rather than making folder/ csv files etc. These scripts automatically download datasets from Databases in jarvis-tools and train several models. Make sure you specify your specific queuing system details in the scripts.

Additional example trainings for property prediction task: 2D-exfoliation energy, superconductor transition temperature.

An example for training MLFF for Silicon is provided here. It is highly recommeded to get familiar with this example before developing a new model.

Using pre-trained models

All the trained models are distributed on [Figshare](https://figshare.com/projects/ALIGNN_models/126478.

The pretrained.py script can be applied to use them. These models can be used to directly make predictions.

A brief help section (-h) is shown using:

pretrained.py -h

An example of prediction formation energy per atom using JARVIS-DFT dataset trained model is shown below:

pretrained.py --model_name jv_formation_energy_peratom_alignn --file_format poscar --file_path alignn/examples/sample_data/POSCAR-JVASP-10.vasp

A pretrained ALIGNN-FF (under active development right now) can be used for predicting several properties, such as:

run_alignn_ff.py --file_path alignn/examples/sample_data/POSCAR-JVASP-10.vasp --task="unrelaxed_energy"
run_alignn_ff.py --file_path alignn/examples/sample_data/POSCAR-JVASP-10.vasp --task="optimize"
run_alignn_ff.py --file_path alignn/examples/sample_data/POSCAR-JVASP-10.vasp --task="ev_curve"

To know about other tasks, type.

run_alignn_ff.py -h

Several supporting scripts for stucture optimization, equation of states, phonon and related calculations are provided in the repo as well. If you need further assistance for a particular task, feel free to raise an GitHus issue.

Web-apps

A basic web-app is for direct-prediction available at JARVIS-ALIGNN app. Given atomistic structure in POSCAR format it predict formation energy, total energy per atom and bandgap using data trained on JARVIS-DFT dataset.

Similarly, a web-app for ALIGNN-FF for structure optimization is also available.

JARVIS-ALIGNN

ALIGNN-FF ASE Calculaor

ASE calculator provides interface to various codes. An example for ALIGNN-FF is give below. Note that there are multiple pretrained ALIGNN-FF models available, here we use the deafult_path model. As more accurate models are developed, they will be made available as well:

from alignn.ff.ff import AlignnAtomwiseCalculator,default_path
from jarvis.io.vasp.inputs import Poscar
import numpy as np
import matplotlib.pyplot as plt
model_path = default_path()
calc = AlignnAtomwiseCalculator(path=model_path)
# Source: https://www.ctcms.nist.gov/~knc6/static/JARVIS-DFT/JVASP-1002.xml
poscar="""Si2
1.0
3.3641499856336465 -2.5027128e-09 1.94229273881412
1.121382991333525 3.1717517190189715 1.9422927388141193
-2.5909987e-09 -1.8321133e-09 3.884586486670313
Si
2
Cartesian
3.92483875 2.77528125 6.7980237500000005
0.56069125 0.39646875 0.9711462500000001
"""
dx=np.arange(-0.1, 0.1, 0.01)
atoms=Poscar.from_string(poscar).atoms
print(atoms)
y = []
vol = []
for i in dx:
    struct = atoms.strain_atoms(i)
    struct_ase=struct.ase_converter()
    struct_ase.calc=calc
    y.append(struct_ase.get_potential_energy())
    vol.append(struct.volume)



plt.plot(vol,y,'-o')
plt.xlabel('Volume ($\AA^3$)')
plt.ylabel('Total energy (eV)')
plt.savefig('Si_JVASP-1002.png')
plt.close()

Performances

Please refer to JARVIS-Leaderboard to check the performance of ALIGNN models on several databases.

1) On JARVIS-DFT 2021 dataset (classification)

ModelThresholdALIGNN
Metal/non-metal classifier (OPT)0.01 eV0.92
Metal/non-metal classifier (MBJ)0.01 eV0.92
Magnetic/non-Magnetic classifier0.05 µB0.91
High/low SLME10 %0.83
High/low spillage0.10.80
Stable/unstable (ehull)0.1 eV0.94
High/low-n-Seebeck-100 µVK-10.88
High/low-p-Seebeck100 µVK-10.92
High/low-n-powerfactor1000 µW(mK2)-10.74
High/low-p-powerfactor1000µW(mK2)-10.74

2) On JARVIS-DFT 2021 dataset (regression)

PropertyUnitsMADCFIDCGCNNALIGNNMAD: MAE
Formation energyeV(atom)-10.860.140.0630.03326.06
Bandgap (OPT)eV0.990.300.200.147.07
Total energyeV(atom)-11.780.240.0780.03748.11
EhulleV1.140.220.170.07615.00
Bandgap (MBJ)eV1.790.530.410.315.77
KvGPa52.8014.1214.4710.405.08
GvGPa27.1611.9811.759.482.86
Mag. momµB1.270.450.370.264.88
SLME (%)No unit10.936.225.664.522.42
SpillageNo unit0.520.390.400.351.49
Kpoint-lengthÅ17.889.6810.609.511.88
Plane-wave cutoffeV260.4139.4151.0133.81.95
єx (OPT)No unit57.4024.8327.1720.402.81
єy (OPT)No unit57.5425.0326.6219.992.88
єz (OPT)No unit56.0324.7725.6919.572.86
єx (MBJ)No unit64.4330.9629.8224.052.68
єy (MBJ)No unit64.5529.8930.1123.652.73
єz (MBJ)No unit60.8829.1830.5323.732.57
є (DFPT:elec+ionic)No unit45.8143.7138.7828.151.63
Max. piezoelectric strain coeff (dij)CN-124.5736.4134.7120.571.19
Max. piezo. stress coeff (eij)Cm-20.260.230.190.1471.77
Exfoliation energymeV(atom)-162.6363.3150.051.421.22
Max. EFG1021 Vm-243.9024.5424.719.122.30
avg. meelectron mass unit0.220.140.120.0852.59
avg. mhelectron mass unit0.410.200.170.1243.31
n-SeebeckµVK-1113.056.3849.3240.922.76
n-PFµW(mK2)-1697.80521.54552.6442.301.58
p-SeebeckµVK-1166.3362.7452.6842.423.92
p-PFµW(mK2)-1691.67505.45560.8440.261.57

3) On Materials project 2018 dataset

The results from models other than ALIGNN are reported as given in corresponding papers, not necessarily reproduced by us.

PropUnitMADCFIDCGCNNMEGNetSchNetALIGNNMAD:MAE
EfeV(atom)-10.930.1040.0390.0280.0350.02242.27
EgeV1.350.4340.3880.33-0.2186.19

4) On QM9 dataset

Note the issue related to QM9 dataset. The results from models other than ALIGNN are reported as given in corresponding papers, not necessarily reproduced by us. These models were trained with same parameters as solid-state databases but for 1000 epochs.

TargetUnitsSchNetMEGNetDimeNet++ALIGNN
HOMOeV0.0410.0430.02460.0214
LUMOeV0.0340.0440.01950.0195
GapeV0.0630.0660.03260.0381
ZPVEeV0.00170.001430.001210.0031
µDebye0.0330.050.02970.0146
αBohr30.2350.0810.04350.0561
R2Bohr20.0730.3020.3310.5432
U0eV0.0140.0120.006320.0153
UeV0.0190.0130.006280.0144
HeV0.0140.0120.006530.0147
GeV0.0140.0120.007560.0144

5) On hMOF dataset

PropertyUnitMADMAEMAD:MAER2RMSE
Grav. surface aream2 g-11430.8291.1515.700.99180.89
Vol. surface aream2 cm-3561.44107.815.210.91229.24
Void fractionNo unit0.160.0179.410.980.03
LCDÅ3.440.754.560.831.83
PLDÅ3.550.923.860.782.12
All adspmol kg-11.700.189.440.950.49
Adsp at 0.01barmol kg-10.120.043.000.770.11
Adsp at 2.5barmol kg-12.160.484.500.900.97

6) On qMOF dataset

MAE on electronic bandgap 0.20 eV

7) On OMDB dataset

coming soon!

8) On HOPV dataset

coming soon!

9) On QETB dataset

coming soon!

10) On OpenCatalyst dataset

On 10k dataset:

DataSplitCGCNNDimeNetSchNetDimeNet++ALIGNNMAD: MAE
10k0.9881.01171.0590.88370.61-

Useful notes (based on some of the queries we received)

  1. If you are using GPUs, make sure you have a compatible dgl-cuda version installed, for example: dgl-cu101 or dgl-cu111, so e.g. pip install dgl-cu111 .
  2. While comnventional '.cif' and '.pdb' files can be read using jarvis-tools, for complex files you might have to install cif2cell and pytraj respectively i.e.pip install cif2cell==2.0.0a3 and conda install -c ambermd pytraj.
  3. Make sure you use batch_size as 32 or 64 for large datasets, and not 2 as given in the example config file, else it will take much longer to train, and performnce might drop a lot.
  4. Note that train_alignn.py and pretrained.py in alignn folder are actually python executable scripts. So, even if you don't provide absolute path of these scripts, they should work.
  5. Learn about the issue with QM9 results here: https://github.com/usnistgov/alignn/issues/54
  6. Make sure you have pandas version as >1.2.3.
  7. Starting March 2024, pytroch-ignite dependency will be removed to enable conda-forge build.

References

  1. Atomistic Line Graph Neural Network for improved materials property predictions
  2. Prediction of the Electron Density of States for Crystalline Compounds with Atomistic Line Graph Neural Networks (ALIGNN)
  3. Recent advances and applications of deep learning methods in materials science
  4. Designing High-Tc Superconductors with BCS-inspired Screening, Density Functional Theory and Deep-learning
  5. A Deep-learning Model for Fast Prediction of Vacancy Formation in Diverse Materials
  6. Graph neural network predictions of metal organic framework CO2 adsorption properties
  7. Rapid Prediction of Phonon Structure and Properties using an Atomistic Line Graph Neural Network (ALIGNN)
  8. Unified graph neural network force-field for the periodic table
  9. Large Scale Benchmark of Materials Design Methods
  10. Prediction of Magnetic Properties in van der Waals Magnets using Graph Neural Networks
  11. CHIPS-FF: Benchmarking universal force-fields

Please see detailed publications list here.

How to contribute

For detailed instructions, please see Contribution instructions

Correspondence

Please report bugs as Github issues (https://github.com/usnistgov/alignn/issues) or email to kamal.choudhary@nist.gov.

Funding support

NIST-MGI (https://www.nist.gov/mgi)

NIST-CHIPS (https://www.nist.gov/chips)

Code of conduct

Please see Code of conduct

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc