Skip to content

About

A composition-based ML framework for predicting electronic band gaps of inorganic materials. XGBoost & Random Forest on 15,537 Materials Project compounds using Magpie descriptors.

Topics

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

Repository files navigation

Predicting Materials Band Gaps from Chemical Composition

A composition-based machine learning framework for predicting electronic band gaps of inorganic materials.

Python 3.10+ License: MIT Materials Project Open In Colab arXiv DOI

Quick Start Β· CLI Usage Β· Results Β· Contributing Β· Citation


Why This Project?

Band gap β€” the energy difference between a material's valence and conduction bands β€” determines whether a compound is a metal, semiconductor, or insulator. Accurate band gap prediction accelerates discovery of:

  • Photovoltaic absorbers (optimal ~1.1–1.5 eV)
  • LED phosphors and display materials
  • Wide-gap power electronics (SiC, GaN replacements)
  • Transparent conductors and dielectrics

This repository provides a complete, reproducible pipeline that predicts PBE-level DFT band gaps from chemical composition alone β€” no crystal structure required.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        INPUT                                     β”‚
β”‚              Chemical formula (e.g., "SrTiO3")                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FEATURIZATION                                  β”‚
β”‚         matminer Magpie preset β†’ 132 descriptors                β”‚
β”‚   (electronegativity, atomic radius, valence electrons, ...)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  ML REGRESSION                                    β”‚
β”‚         Random Forest  Β·  XGBoost  Β·  (extensible)              β”‚
β”‚                StandardScaler preprocessing                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       OUTPUT                                     β”‚
β”‚         Predicted band gap (eV) + feature importance            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benchmark Results

Model RΒ² MAE (eV) RMSE (eV) Training Samples Features
Random Forest 0.89 0.36 0.56 15,537 132 (Magpie)
XGBoost 0.91 0.32 0.51 15,537 132 (Magpie)

Note: Band gaps are PBE-GGA values from the Materials Project, which systematically underestimate experimental gaps. Relative trends and ranking remain valid.

Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/neweracy/Prediction-model.git
cd Prediction-model

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # Linux/Mac
# venv\Scripts\activate   # Windows

# Install dependencies
pip install -r requirements.txt

Configure API Key

cp .env.example .env
# Edit .env and add your Materials Project API key

Run the Notebook

jupyter notebook bandgap_prediction.ipynb

Or run the full pipeline headlessly:

jupyter nbconvert --to notebook --execute bandgap_prediction.ipynb

CLI / API Usage

Use the trained model as a standalone prediction tool β€” no notebook required:

Command Line

# Single prediction
python predict.py SrTiO3

# Multiple formulas
python predict.py GaN ZnO CdTe Si3N4

# JSON output (for scripting / pipelines)
python predict.py --format json GaN ZnO

Example output:

Formula          Predicted Band Gap (eV)
─────────────────────────────────────────
SrTiO3           3.21
GaN              2.04
ZnO              1.87

Python API

from predict import BandGapPredictor

predictor = BandGapPredictor()  # Loads saved model from models/

# Single prediction
gap = predictor.predict("SrTiO3")
print(f"Predicted band gap: {gap:.3f} eV")

# Batch prediction
results = predictor.predict_batch(["GaN", "ZnO", "CdTe", "BaTiO3"])
for formula, gap in results.items():
    print(f"  {formula}: {gap:.3f} eV")

Dataset

Property Value
Source Materials Project v2024+
Compounds 15,537 thermodynamically stable phases
Filter is_stable=True, band_gap > 0.1 eV
Target PBE-GGA band gap (eV)
Features 132 Magpie compositional descriptors
Train/Test 80/20 split, random_state=42

Project Structure

Prediction-model/
β”œβ”€β”€ bandgap_prediction.ipynb    # Full ML pipeline (6-stage notebook)
β”œβ”€β”€ predict.py                  # CLI & Python API entrypoint
β”œβ”€β”€ requirements.txt            # Pinned dependencies
β”œβ”€β”€ .env.example                # API key template
β”œβ”€β”€ CONTRIBUTING.md             # Contribution guide
β”œβ”€β”€ CODE_OF_CONDUCT.md          # Community standards
β”œβ”€β”€ CITATION.cff                # Machine-readable citation
β”œβ”€β”€ LICENSE                     # MIT License
β”‚
β”œβ”€β”€ data/                       # Cached datasets
β”‚   └── mp_bandgap_data.csv     # Materials Project query cache
β”œβ”€β”€ models/                     # Trained model artifacts
β”‚   β”œβ”€β”€ xgb_model.joblib        # Best model (XGBoost)
β”‚   β”œβ”€β”€ rf_model.joblib         # Random Forest baseline
β”‚   β”œβ”€β”€ scaler.joblib           # StandardScaler (fitted)
β”‚   └── featurizer.joblib       # Magpie featurizer (fitted)
β”œβ”€β”€ figures/                    # Publication-quality plots
β”‚   β”œβ”€β”€ bandgap_distribution.png
β”‚   β”œβ”€β”€ correlation_heatmap.png
β”‚   β”œβ”€β”€ feature_importance.png
β”‚   └── parity_plot.png
β”œβ”€β”€ tests/                      # Property-based tests
β”‚   └── test_properties.py
└── .github/                    # GitHub automation
    β”œβ”€β”€ ISSUE_TEMPLATE/
    └── PULL_REQUEST_TEMPLATE.md

Figures

Click to expand sample outputs
Band Gap Distribution Parity Plot (XGBoost)
distribution parity
Feature Importance Correlation Heatmap
importance correlation

Reproduction Checklist

To fully reproduce results from scratch:

  • Obtain a Materials Project API key
  • Run all cells in bandgap_prediction.ipynb sequentially
  • Verify data/mp_bandgap_data.csv contains ~15,500 rows
  • Confirm RΒ² > 0.88 for Random Forest, > 0.90 for XGBoost
  • Check figures/ directory contains 4 PNG files
  • Run pytest tests/ to verify model properties

Contributing

We welcome contributions from materials scientists, ML researchers, and software engineers alike. See CONTRIBUTING.md for:

  • Adding new featurizers (e.g., SOAP, orbital-field matrix)
  • Implementing additional ML models (e.g., neural networks, Gaussian processes)
  • Extending the dataset (multi-fidelity, experimental band gaps)
  • Improving documentation or adding tutorials

Quick contribution paths:

Path Difficulty Impact
Fix typos / improve docs Beginner Medium
Add a new ML model Intermediate High
Add structural descriptors Advanced High
Multi-fidelity learning Advanced Very High

Citation

If you use this code or data in your research, please cite:

@software{bandgap_prediction_2024,
  author       = {Your Name},
  title        = {Predicting Materials Band Gaps from Chemical Composition},
  year         = {2024},
  url          = {https://github.com/neweracy/Prediction-model},
  license      = {MIT}
}

See CITATION.cff for a machine-readable citation file.

License

This project is licensed under the MIT License β€” see LICENSE for details.

Acknowledgements


Report Bug Β· Request Feature Β· Ask Question

Made with care for the materials informatics community.

About

A composition-based ML framework for predicting electronic band gaps of inorganic materials. XGBoost & Random Forest on 15,537 Materials Project compounds using Magpie descriptors.

Topics

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages