This guide provides a structured introduction to InterfaceML for heterojunction modeling.
Note: interfaceml/core is the canonical API surface. The legacy scripts in
build_heterojunctions/ delegate to core utilities when available.
# Check Python version (must be 3.8+)
python --version
# Verify pip is installed
pip --version# Clone the repository
git clone https://github.com/ShaneLogic/InterfaceML.git
cd InterfaceML
# Install package
pip install -e .
# Or install dependencies only
pip install -r requirements.txt# Test CLI tools
python build_heterojunctions/interface_builder.py --help
# Test Python import
python -c "from interfaceml.core import io, layering; print('InterfaceML import: OK')"
# (Optional) Start web interface
python -m interfaceml.web.appThe web server uses an app factory with blueprint routes; the CLI entrypoint stays the same.
InterfaceML supports multiple file formats:
- CIF (.cif) - Crystallographic Information File
- POSCAR/VASP (.vasp, .poscar) - VASP format
- XYZ (.xyz) - CP2K-style with cell vectors
from interfaceml.core import io
# Load any supported format
structure = io.load_structure("path/to/file.cif")
print(f"Loaded {len(structure)} atoms")
print(f"Composition: {structure.composition.formula}")For perovskite structures, InterfaceML supports four termination types:
- PbI - Lead-iodide terminated (common for stability)
- FAI - Formamidinium-iodide terminated
- MAI - Methylammonium-iodide terminated
- AI - Generic A-site cation terminated
The algorithm automatically:
- Selects slabs with desired termination
- Ensures complete organic molecules at surfaces
- Creates symmetric slabs (same top/bottom termination)
For adsorbate modeling, supercells are needed to minimize periodic interactions:
- Auto mode: Automatically sizes based on adsorbate diameter (recommended)
- Manual mode: Specify exact nx x ny dimensions
Rule of thumb: Adsorbate-adsorbate distance should be greater than 10 Angstrom
InterfaceML can automatically detect atomic layers for:
- Fixing bulk regions in relaxation calculations
- Splitting multi-layer stacks
- Analyzing interface structure
Example: build a FAPbI3/C60 interface step-by-step.
# Check if example structures exist
ls structures/perovskites/fapbi3-1.cif
ls structures/etl/C60-Ih.cifpython build_heterojunctions/interface_builder.py \
--adsorbate_mode \
--base structures/perovskites/fapbi3-1.cif \
--adsorbate structures/etl/C60-Ih.cif \
--termination FAI \
--distance 2.5 \
--miller 0 0 1 \
--supercell auto \
--output fapbi3_c60_interface.vaspOutput:
fapbi3_c60_interface.vasp- Ready for DFT calculation- Console will show:
- Number of atoms
- Supercell dimensions
- Termination details
- Vacuum thickness
python build_heterojunctions/fix_interface_layers.py \
--by_z_layers \
--input fapbi3_c60_interface.vasp \
--n_fix_layers 3 \
--output fapbi3_c60_interface_fixed.vaspOutput:
fapbi3_c60_interface_fixed.vasp- With selective dynamics flags- Bottom 3 layers are fixed (F F F)
- Upper layers and adsorbate are relaxed (T T T)
- Organic molecules kept intact
Use VESTA, Ovito, or ASE to view the structure:
# With ASE (if installed)
ase gui fapbi3_c60_interface_fixed.vasp# 1. Build perovskite/ETL interface
python build_heterojunctions/interface_builder.py \
--adsorbate_mode \
--base structures/perovskites/H5PbCI3N2.cif \
--adsorbate structures/etl/C60-Ih.cif \
--termination PbI \
--distance 2.5 \
--supercell auto \
--output perovskite_etl.vasp
# 2. Fix bottom layers
python build_heterojunctions/fix_interface_layers.py \
--by_z_layers \
--input perovskite_etl.vasp \
--n_fix_layers 3 \
--output perovskite_etl_fixed.vasp
# 3. Run DFT (VASP example)
# Edit INCAR, KPOINTS, POTCAR as needed
# mpirun -np 16 vasp_std
# 4. Analyze charge transfer
python build_heterojunctions/delta_density_cube.py \
--interface CHGCAR_interface.cube \
--layer1 CHGCAR_perovskite.cube \
--layer2 CHGCAR_c60.cube \
--output delta_charge.cube# Build Perovskite/C70/C60 stack
python build_heterojunctions/interface_builder.py \
--adsorbate_mode \
--base structures/perovskites/fapbi3-1.cif \
--adsorbate structures/etl/C70-D5h.cif structures/etl/C60-Ih.cif \
--termination AI \
--layer_gaps 2.0 2.0 \
--supercell auto \
--output trilayer.vasp
# Split into layers and fix bottom
python build_heterojunctions/fix_interface_layers.py \
--by_layers \
--input trilayer.vasp \
--n_interfaces 2 \
--fixed_layers 1 \
--output trilayer_fixed.vasp# If you already have a relaxed slab
python build_heterojunctions/interface_builder.py \
--adsorbate_mode \
--slab_input my_relaxed_slab_supercell.vasp \
--adsorbate structures/etl/C60-Ih.cif \
--distance 2.5 \
--output relaxed_with_adsorbate.vaspSolution:
- Try different
--millerindices (e.g.,0 0 1,1 1 1) - Increase
--min_slab_sizeand--min_vacuum_size - For perovskites, ensure the input structure has complete formula units
- Check if your termination type matches the structure (FAI for FAPbI3, MAI for MAPbI3)
Solution:
- Reduce supercell size:
--supercell_xy 1 1(instead of auto) - Use a smaller adsorbate or fewer adsorbate layers
- Increase
--max_atomsif your hardware can handle it
Solution:
- Visualize with
--debug_layersflag - Adjust
--tolparameter (try 0.3-0.7 Angstrom) - Use
--layer_elementsto specify which elements define layers - For XYZ files, ensure cell vectors (Tv_1/Tv_2/Tv_3) are present
Solution:
- The
--no_include_moleculesflag should NOT be used (molecules are included by default) - Check that you're using the latest version of the script
- Verify with
--debug_layersthat molecules are being detected
Solution:
# Check Flask is installed
pip install flask flask-cors
# Try specifying port
python -m interfaceml.web.app --port 8000
# Check firewall settings
# Make sure port 5000 (or chosen port) is not blockedSolution:
# Update pymatgen
pip install --upgrade pymatgen
# Or use conda
conda install -c conda-forge pymatgen
# Verify installation
python -c "import pymatgen; print(pymatgen.__version__)"- Read the detailed CLI documentation
- Explore example structures in
structures/ - Try the web interface for interactive modeling
- Review discussions on GitHub for similar workflows
- Check the main README
- Report bugs on GitHub Issues
- Ask questions in Discussions
- Email: xchen565@connect.hkust-gz.edu.cn
For additional help, use the links above.