Skip to content

Input and Script Generators (CLI)

Marco Buongiorno Nardelli edited this page Jun 8, 2026 · 2 revisions

Input and Script Generators (CLI)

Overview

PAOFLOW ships two small, dependency-light command-line generators that automate the repetitive parts of setting up a study. They are installed with the package as console commands:

  1. paoflow-gen-qe — build a Quantum ESPRESSO scf input from an AFLOW database entry, with sensible defaults for smearing, magnetism, spin–orbit coupling, and the number of bands needed for PAOFLOW's extended-basis projections.
  2. paoflow-gen — interactively generate a PAOFLOW driver script (main.py) from the output of a Quantum ESPRESSO run, and optionally a companion plotting script (plot.py) that visualizes exactly the properties you selected.

Both generators are otherwise dependency-light, using mostly the Python standard library (urllib, json, argparse, glob, os, re, math). The only exception is paoflow-gen-qe's automatic ibrav detection, which relies on NumPy through PAOFLOW.inputs.lattice_format (already a PAOFLOW dependency); with --ibrav 0 even that path is pure standard library. The generated PAOFLOW scripts of course require a working PAOFLOW installation. The generators emit static, heavily-commented scripts that are easy to inspect and tweak afterwards.

The code lives in the PAOFLOW.gen subpackage (src/PAOFLOW/gen/aflow_qe.py and src/PAOFLOW/gen/paoflow_driver.py) and is exposed through the paoflow-gen-qe and paoflow-gen console entry points defined in pyproject.toml. Once PAOFLOW is installed (pip install -e .), both commands are available on your PATH; they can also be invoked as python -m PAOFLOW.gen.aflow_qe and python -m PAOFLOW.gen.paoflow_driver.


1. paoflow-gen-qe — AFLOW → Quantum ESPRESSO input

Purpose

Given an AFLOW entry, the tool downloads the structure and metadata and writes a ready-to-run pw.x scf input file. It chooses energy cutoffs, k-point density, smearing scheme, magnetic configuration, and the number of bands (nbnd) appropriate for a subsequent PAOFLOW run that uses the extended pseudo-atomic basis.

Usage

paoflow-gen-qe <AFLOW-entry> -p <pseudo-dir> [options]

The <AFLOW-entry> positional argument accepts any of the following forms:

Form Example
AFLOWDATA URL https://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/RHL/Bi1_ICSD_616519/
Material-page URL https://aflow.org/material/?id=aflow:0a66d228d896a855
Bare AUID token aflow:0a66d228d896a855

Material-page URLs and bare AUID tokens are resolved to their underlying AFLOWDATA location through the AFLUX API (https://aflow.org/API/aflux/?auid('aflow:…'),aurl).

Options

Flag Default Description
-p, --pseudo-dir (required) Directory containing the UPF pseudopotentials
--soc off Emit a non-collinear, spin–orbit (noncolin, lspinorb) input
-o, --out stdout Output file path
--degauss 0.05 Smearing width (Ry) for metallic systems
--nbnd (auto) Override the automatically computed number of bands
--ibrav auto Lattice mode: auto detects the QE ibrav + celldm; 0 always writes explicit CELL_PARAMETERS
--symprec 1e-4 Symmetry tolerance (Bohr) for the ibrav detection

What it does

  • Structure — downloads CONTCAR.relax.qe and, by default (--ibrav auto), detects the matching Quantum ESPRESSO ibrav and celldm for the cell, emitting a compact symmetric input. When the lattice cannot be classified it falls back to an ibrav=0 cell with explicit CELL_PARAMETERS. Pass --ibrav 0 to force the explicit-cell output (see Automatic ibrav detection below).

  • Cutoffs — reads recommended wavefunction cutoffs from a bundled reference.json (converted from Hartree to Rydberg).

  • Masses — looks up atomic masses from a bundled periodic-table table.

  • Smearing (metal vs. insulator) — if the AFLOW band gap is essentially zero (≤ 1e-6 eV) the system is treated as a metal: smearing occupations plus a conservative mixing_beta = 0.2. Otherwise it uses fixed occupations and mixing_beta = 0.7.

  • Magnetism — if any per-atom spin moment exceeds 1e-3, the input is made spin-polarized (nspin = 2) with per-type starting_magnetization.

  • Spin–orbit — with --soc, a non-collinear spin–orbit input is produced.

  • Band count for PAOFLOW — nbnd is sized so that the extended basis can be projected. For each atom the number of extended orbitals is (l_max + 2)², where l_max is parsed from the PP_CHI channels of the UPF. These are summed (and doubled for spin–orbit), and

    nbnd = max(nawf + 2, ceil(nawf × 1.15))
    

    An explicit --nbnd always wins.

Example

paoflow-gen-qe aflow:0a66d228d896a855 \
    -p /path/to/PSEUDOS/nc-sr-05_pbe_standard_upf \
    -o Bi.scf.in

For the bismuth example above this yields nbnd = 37; adding --soc doubles the orbital count to nbnd = 74.

Automatic ibrav detection

By default (--ibrav auto) the generator classifies the Bravais lattice of the downloaded structure and writes a native Quantum ESPRESSO ibrav + celldm input instead of a generic ibrav=0 cell. This produces cleaner inputs and lets QE regenerate the conventional/primitive cell with full symmetry.

How it works:

  • The CONTCAR.relax.qe cell (in Å or Bohr) is converted to lattice vectors and passed to qe_ibrav_from_lattice in PAOFLOW.inputs.lattice_format, together with AFLOW's pre-computed symmetry hints (Bravais_lattice_relax and the space group sg/spacegroup_relax) to disambiguate centred lattices.
  • The detector returns the ibrav, the celldm slots QE reads for that ibrav, and an integer cell map M relating the input cell to the QE convention.
  • ATOMIC_POSITIONS are rewritten in crystal coordinates of the QE cell via f_qe = f_in · M⁻¹, and the CELL_PARAMETERS card is dropped. Only the celldm(i) entries meaningful for the detected ibrav are emitted (e.g. celldm(1) for cubic, celldm(1,3) for hexagonal).
  • Each fractional coordinate is wrapped into the minimum-image range [-0.5, 0.5) rather than [0, 1). This keeps bonded atoms inside the home unit cell — e.g. the primitive-cell Si basis atom is written as -0.25 -0.25 -0.25 instead of the equivalent 0.75 0.75 0.75. The two are identical for an ordinary scf run, but a later U + V (eACBN0) calculation needs the bonded neighbour to sit in the home cell so its intersite-V neighbour search can find it.
  • All 20 supported ibrav values are covered (cubic 1,2,3; hexagonal 4; trigonal 5; tetragonal 6,7; orthorhombic 8,9,-9,91,10,11; monoclinic 12,-12,13,-13; triclinic 14).

The detection is intentionally conservative — it never emits a wrong cell silently. It falls back to the explicit ibrav=0 path whenever:

  • the cell unit is something other than angstrom/bohr (e.g. alat);
  • the lattice does not match any ibrav within --symprec;
  • the atom positions cannot be remapped (unsupported position units).

--symprec (default 1e-4) controls the tolerance of the lattice match; loosen it for noisy/relaxed cells. --ibrav 0 disables detection entirely and restores the original behaviour (explicit CELL_PARAMETERS copied verbatim).

Note: -p/--pseudo-dir must point at the folder containing the UPF files (plus PeriodicTableJSON.json and reference.json), not at an individual .upf file.

Suggested intersite-V cutoff

To help set up a later U + V (eACBN0) run, the generator also computes a recommended intersite-neighbour cutoff directly from the structure and prints it both to stderr and as a comment block at the top of the generated input:

! Suggested eACBN0 intersite V cutoff: 3.10 Angstrom
!   nearest-neighbour distance: 2.35 Angstrom
!   covers the first neighbour shell; use as V_CUTOFF /
!   set_intersite_pairs(cutoff=...) in the PAOFLOW U+V driver.

The value is obtained by enumerating periodic-image distances between all atoms, collapsing them into neighbour shells, and placing the cutoff midway between the first and second shells so the intersite-V search captures exactly the nearest-neighbour bonds. Feed it to V_CUTOFF in the generated paoflow-gen driver (or directly to eACBN0.set_intersite_pairs(cutoff=…)); the value is in Ångström, matching that API. The leading ! lines are QE comments and are ignored by pw.x.


2. paoflow-gen — PAOFLOW driver and plot generator

Purpose

Starting from a finished Quantum ESPRESSO run (a <prefix>.save directory plus the UPF used to produce it), this CLI asks a handful of questions and writes a minimal, well-commented PAOFLOW main.py. It supports two workflows and can additionally emit a matching plot.py.

Usage

paoflow-gen [-d WORKDIR] [options]

The tool auto-detects the <prefix>.save directory, the UPF file, and the prefix (from scf.in / nscf.in) inside the working directory; every detected value can be overridden.

Options

Flag Default Description
-d, --workdir . Directory scanned for QE artifacts
--prefix (auto) QE prefix override
--savedir (auto) <prefix>.save override
--upf (auto) Pseudopotential file override
-o, --out main.py Driver-script output path
--plot off Force generation of a plotting script (run workflow)
--plot-out plot.py Plotting-script output path
-f, --force off Overwrite existing output files

Workflow A — ACBN0 / eACBN0

Generates a self-consistent Hubbard U (ACBN0) or joint on-site U + intersite V (eACBN0) driver. The PAO projections use the minimal basis, as required by ACBN0. You are prompted for:

  • whether to include intersite V (eACBN0) or stay on-site only (ACBN0);
  • the projection scheme (default ortho-atomic);
  • the U/V convergence threshold;
  • one or more Hubbard manifolds and their initial U (e.g. Si-3p 0.5);
  • (eACBN0 only) the intersite neighbour cutoff and initial V;
  • the parallel launch commands and executable paths for pw.x, the Python layer, and the Hartree step.

The generated script reconstructs the PAO band structure after convergence and prints the converged U (and V) values.

Workflow B — Full property run

Generates a property-driver script. You pick properties from a menu:

# Property PAOFLOW call(s)
1 Band structure bands()
2 DOS / projected DOS dos(do_dos, do_pdos)
3 Boltzmann transport transport()
4 Fermi surface fermi_surface()
5 Spin texture spin_texture()
6 Spin Hall conductivity spin_Hall()
7 Anomalous Hall / Berry curvature anomalous_Hall()
8 Band topology (Berry, effective mass) topology()
9 Optical / dielectric tensor dielectric_tensor()

Key behaviours:

  • Standard properties use the basis you choose (minimal / standard / extended, default standard).
  • Optical properties require the non-local velocity correction and the extended basis, so they are emitted as a separate run_optical() function (a second PAOFLOW instance) within the same script.
  • Spin-dependent properties (spin texture, spin Hall) automatically insert the required spin_operator() call.
  • For ibrav = 0, PAOFLOW needs an explicit band path; the script emits BAND_PATH / HIGH_SYM TODO stubs for you to fill in.

All tunable quantities (energy windows, k-point density, smearing, FFT interpolation grid, projectability threshold, …) are written as clearly-labelled constants at the top of the generated main.py.


3. The generated plotting script (plot.py)

When you choose the full-property workflow, the generator offers to also write a plotting script (or force it with --plot). The plot.py it produces:

  • Mirrors your property selection. Its menu lists only the properties you selected when generating main.py.
  • Mimics the generator's CLI. It prints a numbered menu and accepts a comma/space separated list (or all) of plots to draw.
  • Locates output files automatically by globbing the PAOFLOW output/ directory, so it adapts to whatever prefix your run used.
  • Uses PAOFLOW.GPAO for all plotting.

Property → plot mapping

Selected property Plot function Output file(s)
Band structure plot_bands *.bands_0.dat, *.kpath_points.txt
DOS plot_dos (+ plot_pdos) *.dosdk_0.dat, *.pdosdk*
Bands + DOS together plot_dos_beside_bands bands + DOS files
Transport plot_electrical_conductivity, plot_seebeck *.sigmadk_0.dat, *.Seebeck_0.dat
Spin Hall plot_shc *.shcEf*.dat
Anomalous Hall plot_ahc *.ahcEf*.dat
Berry / topology plot_berry (+ plot_berry_under_bands) *.Omega_*.dat
Optical / dielectric plot_dielectric epsi_*.dat, epsr_*.dat
Fermi surface (pointer) FermiSurf_*.bxsf → open in XCrySDen
Spin texture (pointer) spin-texture-bands.dat

When both band structure and DOS are selected, the plot menu includes a combined Bands + DOS (side by side) entry that uses plot_dos_beside_bands, as recommended for this pairing.

Fermi surface and spin texture are not one-dimensional spectra, so rather than producing a figure the script prints a pointer to the relevant data/BXSF file (e.g. the XCrySDen command for the Fermi-surface .bxsf).


4. New GPAO plotting helpers

To support the property menu above, two methods were added to PAOFLOW.GPAO.GPAO, built on the existing helpers as templates:

  • plot_ahc(fname, …) — anomalous Hall conductivity vs. energy. Accepts a single ahcEf_{ij}.dat file or a list of tensor components to overlay (modeled on plot_shc).
  • plot_dielectric(fname, …) — optical/dielectric spectra vs. energy (epsi_*, epsr_*, eels_*, sigmar_*, …). Accepts a single file or a list to overlay several spectra (modeled on plot_dos / plot_shc).

Both follow the existing convention of reading the two-column .dat output with read_dos_PAO and delegating to the shared plotting primitives.


End-to-end example

# 1. Build a QE scf input from an AFLOW entry.
paoflow-gen-qe aflow:0a66d228d896a855 -p ./PSEUDOS -o Si.scf.in

# 2. Run pw.x (scf, then nscf) to produce Si.save/ … (external step)

# 3. Generate a PAOFLOW driver + matching plot script.
paoflow-gen -d . -o main.py --plot-out plot.py
#   → choose "run", select e.g. bands, DOS, transport, optical …

# 4. Run PAOFLOW.
mpirun -np 4 python main.py

# 5. Visualize the results.
python plot.py        # pick what to plot from the menu

Clone this wiki locally