DFT Calculator
Overview
The calculator.py module sets up DFT calculators as ASE calculator objects
from the dft_calculator section of input.yaml. Six engines are supported:
|
Backend |
Notes |
|---|---|---|
|
|
All parameters read from INCAR template; requires POTCAR files ( |
|
|
Requires |
|
|
Molecular (non-periodic); periodicity auto-removed from structure |
|
|
Semi-empirical tight-binding; reads |
|
|
Quantum ESPRESSO |
|
|
Molecular (non-periodic); periodicity auto-removed from structure |
Configuration (input.yaml)
dft_calculator:
engine: "VASP" # Engine name (required)
template_file: "INCAR" # Engine-specific input template (required)
exe_command: "mpirun -np 4 vasp_std" # Executable command (optional; auto-detected if omitted)
Each engine reads its template file differently:
Engine |
Template file |
Notes |
|---|---|---|
|
|
Standard VASP INCAR format |
|
|
CP2K input file (comments stripped) |
|
|
ORCA simple input format |
|
|
|
|
|
Quantum ESPRESSO |
|
|
|
Note
For ORCA and Gaussian, any periodic boundary conditions on the input structure are automatically removed before the calculator is attached.
Note
Ensure that the VASP executable and VASP_PP_PATH are correctly set before
running. See SPARC Installation Guide for environment setup.
Template File Reference
Each engine reads its template_file in a different format. Minimal working
examples are shown below.
1. VASP (INCAR)
Standard VASP INCAR format. All keys are passed directly to the ASE Vasp
calculator.
ISTART = 0
ICHARG = 2
ENCUT = 520
EDIFF = 1E-6
NSW = 0
IBRION = -1
ISMEAR = 0
SIGMA = 0.05
LWAVE = .FALSE.
LCHARG = .FALSE.
NPAR = 4
2. CP2K (cp2k_template.inp)
Full CP2K input format. Lines starting with # or ! are stripped.
ASE injects the &COORD and &CELL sections automatically from the
Atoms object.
! This is a comment
# This is a comment
&GLOBAL
ECHO_INPUT
&END GLOBAL
&FORCE_EVAL
&DFT
CHARGE 0
MULTIPLICITY 1
&MGRID
REL_CUTOFF 50
NGRIDS 3
&END MGRID
&QS
METHOD GPW
EPS_DEFAULT 1.0E-10
EPS_PGF_ORB 1.0E-12
EXTRAPOLATION ASPC
EXTRAPOLATION_ORDER 3
&END QS
&SCF
EPS_SCF 1.0E-4
SCF_GUESS RESTART
&OT
PRECONDITIONER FULL_ALL
&END OT
&OUTER_SCF
EPS_SCF 1.0E-4
MAX_SCF 3
&END OUTER_SCF
&END SCF
&END DFT
&SUBSYS
&KIND B
ELEMENT B
&END KIND
&KIND N
ELEMENT N
&END KIND
&KIND H
ELEMENT H
&END KIND
&END SUBSYS
&END FORCE_EVAL
CP2K parameters (cp2k: section in input.yaml)
Top-level ASE CP2K() parameters are supplied in a separate cp2k:
section of input.yaml — not inside dft_calculator:.
Parameter precedence: values in cp2k: override the defaults listed
below. Parameters not present in cp2k: take their default values.
Settings controlled entirely by the template (cutoff,
pseudo_potential) default to null so that ASE does not inject
conflicting values.
dft_calculator:
engine: "CP2K"
template_file: "cp2k_template.inp"
exe_command: "mpirun -np 4 cp2k.psmp" # optional
cp2k:
xc: "PBE" # XC functional
max_scf: 500 # Max SCF iterations
basis_set_file: "BASIS_MOLOPT" # Basis set library file
potential_file: "GTH_POTENTIALS" # Pseudopotential library file
Key |
Default |
Description |
|---|---|---|
|
|
Exchange-correlation functional |
|
|
Maximum number of outer SCF cycles |
|
|
Filename of the basis set library ( |
|
|
Global basis set. When |
|
|
Filename of the pseudopotential library ( |
|
|
Global pseudopotential. When |
|
|
Output file prefix and working subdirectory |
Note
basis_set and pseudo_potential default to null. Define BASIS_SET
and POTENTIAL inside each &KIND block of the template to assign
different basis sets and pseudopotentials per species.
3. ORCA (orca_template.inp)
Requires one ! keyword line. Charge and multiplicity are read from the
*xyz line. The %pal block sets parallelism.
Note
ORCA uses MPI for parallel execution (%pal nprocs N end). Ensure that
MPI binaries (mpirun / mpiexec) are on your PATH and that the
correct MPI libraries are loaded before running, otherwise ORCA will fall
back to serial execution or fail to start.
! B3LYP 6-31G(d,p) Engrad
%scf Convergence tight
maxiter 300 end
%pal nprocs 4 end
*xyz 0 1
4. xTB (xtb_template.inp)
Simple key = value file. Comments start with #. Supported keys:
# xTB template for SPARC
method = GFN2-xTB
charge = 0
multiplicity = 1
accuracy = 1.0
electronic_temperature = 300.0
max_iterations = 250
solvent = none
solvent_method = none
directory = xtb_run
label = xtb
5. Quantum ESPRESSO (qe_template.in)
Standard pw.x input. ASE injects atomic positions and cell parameters.
The ATOMIC_SPECIES card maps elements to pseudopotential files.
K-points default to Gamma-only if the K_POINTS gamma card is used or
the card is omitted.
Note
calculation, tprnfor, and tstress are always overridden by
SPARC to scf, .true., and .true. respectively — they may be
included in the template for clarity but have no effect.
&CONTROL
calculation = 'scf'
tprnfor = .true.
tstress = .true.
pseudo_dir = '/path/to/pseudo'
outdir = './qe_out'
verbosity = 'low'
/
&SYSTEM
ibrav = 0
ecutwfc = 40
ecutrho = 320
occupations = 'fixed'
/
&ELECTRONS
conv_thr = 1.0d-5
mixing_beta = 0.3
electron_maxstep = 100
/
ATOMIC_SPECIES
B 10.811 b_pbe_v1.4.uspp.F.UPF
N 14.007 N.pbe-n-radius_5.UPF
H 1.008 H.pbe-rrkjus_psl.1.0.0.UPF
K_POINTS gamma
6. Gaussian (gaussian_template.inp)
Simple key = value file. Comments start with # or !.
method and basis are required. ASE always runs a force calculation.
# Gaussian template for SPARC
method = HF
basis = STO-3G
charge = 0
multiplicity = 1
mem = 2GB
nproc = 2
scf = qc,maxcycle=200
Module Contents
Unified interface for setting up DFT calculators as ASE calculator objects.
Supports VASP, CP2K, ORCA, xTB, Quantum ESPRESSO, and Gaussian. Each engine
reads its parameters from an engine-specific template file defined in the
dft_calculator section of input.yaml.
- exception sparc.src.calculator.CalculatorError[source]
Bases:
ExceptionException raised when calculator setup or execution fails.
This exception is raised for issues such as: - Missing required configuration parameters - Invalid template files - Calculator initialization failures - Unsupported calculator engines
- class sparc.src.calculator.SetupDFTCalculator(input_config, print_screen=False)[source]
Bases:
objectClass to set up DFT calculators for VASP, CP2K, ORCA, and xTB using ASE.
This class provides a unified interface for configuring different DFT engines based on template files and configuration dictionaries. It handles parsing of engine-specific input files and creates appropriate ASE calculator objects.
- Parameters:
- Raises:
ConfigurationError – If input_config is invalid or missing required keys
CalculatorError – If calculator setup fails
Examples
>>> config = {'dft_calculator': {'engine': 'VASP', 'template_file': 'INCAR', ...}} >>> calc_setup = SetupDFTCalculator(config, print_screen=True) >>> calculator = calc_setup.vasp()
- espresso()[source]
Set up the Quantum ESPRESSO calculator from a pw.x template file.
The template file should be a standard pw.x input containing namelists (&CONTROL, &SYSTEM, &ELECTRONS, …), ATOMIC_SPECIES, and K_POINTS cards. Coordinates are provided by ASE, so ATOMIC_POSITIONS and CELL_PARAMETERS in the template are ignored.
- sparc.src.calculator.dft_calculator(config, print_screen=False)[source]
Helper function to set up a DFT calculator based on configuration.
This is the main entry point for creating DFT calculators. It automatically determines the calculator engine from the configuration and creates the appropriate ASE calculator object.
- Parameters:
- Returns:
The configured ASE calculator instance (Vasp, CP2K, ORCA, or XTB)
- Return type:
ASE Calculator
- Raises:
CalculatorError – If engine is unsupported or calculator setup fails
Examples
>>> config = load_config('input.yaml') >>> calc = dft_calculator(config, print_screen=True) >>> atoms.calc = calc >>> energy = atoms.get_potential_energy()