graspElems
Runs the Grasp2K atomic-structure programs for specified elements and writes each orbital of the atom or ion on a numerical radial grid. Grasp2K solves the multi-configuration Dirac-Hartree-Fock equations for a free atom; its orbitals are what org_radwavefn.py reads and interFit.py fits with Gaussians to build Imago’s relativistic basis.
Recipes. One Grasp2K calculation is described completely by a recipe: the element, the charge of the ion, the orbital the calculation exists to produce (the target, if any), the electron configuration, the radial grid, and the optimization steps with their stopping conditions. A recipe is built by rule from the command line or read from a TOML file. Every run writes the recipe it used as recipe.toml, and running that file repeats the run.
Why ions. A basis needs orbitals the neutral atom leaves empty (Si 3d, 4s, 4p). An atomic-like shape for such an orbital comes from a calculation in which the orbital holds an electron, and the positive charge of an ion keeps that electron bound and compact. Which charge suits which orbital is not yet settled, so the charge is always stated with --charges.
The configuration rule. For an element, a charge and a target: start from the neutral ground state in isotopes.dat; remove one electron per unit of charge from the outermost occupied subshell (largest n, then largest l, so iron loses 4s before 3d); then move one electron into the target if it is empty. Iron at charge 1 with target 4p is 3d(6) 4p(1). For an ion the rule gets wrong, state core, peel and occupation in a recipe file.
The sequence of programs. For each recipe the script drives seven Grasp2K programs, giving each the answers it would otherwise prompt for:
rnucleus, the nuclear model (the script then writes the radial grid into its output file);csl, the list of states of the configuration;rcsfblock, which sorts the states into groups of equal total angular momentum J and parity;rangular, the angular coefficients;rwfnestimate, the first guess for the orbitals;rmcdhf, the self-consistent Dirac-Hartree-Fock solve;readrwf, which converts the binary orbitals to the readablerwfn.out.
Steps 5 and 6 are repeated for each optimization step of the recipe.
Processes. A process is a named sequence of optimization steps.
| Process | What it does |
|---|---|
fixed_ion | For a recipe with a target: the orbitals of the ion WITHOUT the target electron (the parent, the same element at one more unit of charge) are computed first in a run of their own and held fixed, and only the target is varied. The parent runs are added automatically. A recipe without a target runs as configuration_average. Uses an accuracy of 1e-10. |
configuration_average | One step in which every orbital is varied, optimized for every level of the configuration weighted by 2J+1. |
lowest_level | The configuration_average step, then a second step for the level of lowest energy alone. |
fixed_ion exists because varying everything fails when the target has the same orbital angular momentum as another partly filled subshell (3s(1) 4s(1), for example): the two orbitals mix into each other and the calculation does not settle. With fixed_ion, if a step does not converge from the Thomas-Fermi first guess for the target it is run again from the screened hydrogenic one.
Convergence. Grasp2K exits with status zero whether or not it converged, so the script decides. A step has converged when Grasp2K wrote a complete summary, printed neither Maximum iterations in SCF Exceeded nor Convergence not obtained, and left no orbital with an inconsistency above the limit (1e-4 by default). The last test is the script’s own: Grasp2K also stops when the total energy stops changing, whatever state the orbitals are in. A run that does not converge is recorded as such and the script goes on to the next; its exit status is 1 if any run did not converge.
Requirements. The Grasp2K binaries must be in the directory named by $GRASP_BIN, or under $GRASP_DIR/bin; the script stops if neither is set.
Hydrogen and helium. Three things are done differently for them. Grasp2K’s csl crashes on a single electron in a lone s orbital, so for that one configuration the script writes the list of states itself. Hydrogen and helium are given a point nucleus: Grasp2K’s finite nucleus cannot be built for a mass number below 4, and its one-electron atoms do not settle with a finite nucleus. And an atom with one electron has no parent under fixed_ion, there being nothing to hold fixed.
Charges an element does not allow. Hydrogen has one electron to give and lithium at charge 1 has none left outside its core to move into a target. When ELEM BASIS with --charges asks for such a combination it is left out, the script prints what was left out and why, and the rest are run. A recipe file that asks for one stops the script.
Author: Patrick Ryan Thomas. Reworked around recipes in 2026.
Defaults. Read from graspElemsrc.py in the directory named by $IMAGO_RC: the batch flag, the number of runs per job file, the radial grid, the cycle limit, the inconsistency limit and the process.
Usage
Commandline:
graspElems.py SPEC [SPEC ...] [options]
graspElems.py --recipe FILE [FILE ...] [options]
Give the SPECs before any option that takes a list, such as --charges.
Examples:
graspElems.py Si MB # neutral Si only: every
# MB orbital is occupied
graspElems.py Si FB --charges 1 # neutral Si, the Si ion
# parents, and 3d, 4s, 4p
# each at charge 1
graspElems.py C all --charges 1 2 # carbon, all three bases,
# two charges
graspElems.py Si MB --targets 4s --charges 0 1 2 3
# one orbital at four charges
graspElems.py Si FB --charges 1 --summarize
# table of results; runs
# nothing
graspElems.py --recipe Si/q1_4s/recipe.toml
# repeat one run
graspElems.py total FB --charges 1 --batch -nc 16
# job files, 16 families
# of runs per job
graspElems.py Fe EB --charges 2 --process configuration_average
# vary every orbital
Variable Table:
| SPEC form | Meaning |
|---|---|
ELEM BASIS | One element with one basis: MB, FB or EB. |
ELEM all | One element with all three bases. |
total | All elements with all bases. |
total BASIS | All elements with one basis. |
ELEM BASIS stands for several runs: the neutral atom, and for every orbital of that basis (the VALE line of isotopes.dat) that the neutral atom leaves empty, one run per charge given with --charges. If such an orbital exists and no charge is given, the script stops and says so.
Option Table:
| Option | Defaults | Description |
|---|---|---|
| -q / –charges Q … | None | Charges of the ions used for the unoccupied orbitals; one run per orbital per charge. |
| -t / –targets ORB … | The unoccupied orbitals of the basis | Orbitals to produce, e.g. 3d 4s. |
| –recipe FILE … | None | Run these recipe files; give no SPEC. |
| –process NAME | fixed_ion | Sequence of optimization steps; see the table above. |
| –max-cycles N | 200 | Largest number of cycles in each optimization step. |
| –accuracy X | The process’s own (1e-10 for fixed_ion), else Grasp2K’s choice, the sixth power of the grid step | Largest orbital inconsistency Grasp2K accepts. Also tightens its energy test. |
| –inconsistency-limit X | 1e-4 | The script’s own test after Grasp2K finishes: a step converged only if no orbital exceeds this. |
| –grid RNT H HP POINTS | 2e-6 0.05 0 590 | Radial grid r(i) = RNT (exp((i-1) H) - 1), i = 1 to POINTS, in Bohr radii. POINTS may not exceed the limit compiled into Grasp2K. |
| -s / –summarize | Off | Print a table of what the selected runs reported; run nothing. |
| -b / –batch | Off | Write job files for a batch system instead of running. |
| -nc / –num-cores | 1 | Number of families of runs placed in each job file. Batch mode only. |
| –help | N/A | Print usage information and exit. |
The recipe file
A recipe file holds one table, [recipe]. Only element is required.
[recipe]
element = "Fe"
charge = 2
target = "4p"
name = "fe2_4p_by_hand" # the run directory; optional
parent = "q3_ground" # optional; see fixed_ion
nucleus = "fermi" # or "point"; optional
core = "1s 2s 2p 3s 3p" # core, peel and occupation are
peel = "3d 4p" # given together or not at all
occupation = "3d(5) 4p(1)"
process = "fixed_ion" # or a list of [[recipe.stage]]
[recipe.grid]
rnt = 2e-06
h = 0.05
hp = 0.0
points = 590
[[recipe.stage]] # one per optimization step
start = "parent" # thomas_fermi, screened_hydrogenic,
# previous, or parent
levels = "configuration_average" # or lowest_level
vary = ["4p-", "4p"] # "all" or a list of orbitals
spectroscopic = ["4p-", "4p"] # "all", "none" or a list
max_cycles = 200
inconsistency_limit = 0.0001
accuracy = 1e-10 # optional
guess = ["thomas_fermi", "screened_hydrogenic"]
# only with start = "parent"
The simplest way to write one is to copy a recipe.toml that the script produced and change it.
Output
Each run occupies <element>/<name>/ under the current directory. The name is q<charge>_ground for a run without a target and q<charge>_<target> for one with: Si/q0_ground/, Si/q1_4s/. Beside Grasp2K’s own files the directory holds:
| File | Contents |
|---|---|
recipe.toml | The recipe exactly as it was run. |
record.toml | What the run reported: for each step whether it converged, the cycles, each level’s energy, and each orbital’s energy, mean radius and remaining inconsistency. Energies in Hartree, radii in Bohr. |
<program>.answers | The lines given to each Grasp2K program. |
<program>.out | Everything that program printed. |
step<k>.w, step<k>.sum | The orbitals (binary) and Grasp2K’s summary of optimization step k. |
parent.w | With fixed_ion: a copy of the parent’s orbitals. |
step<k>_failed_<guess>/ | The files of an attempt that did not converge and was retried. |
rwfn.out | The final orbitals as text, for org_radwavefn. |
isodata | The nuclear model and the radial grid. |
The orbital energy Grasp2K prints, and --summarize shows, is a binding energy: positive for a bound orbital.
In batch mode the current directory gains SBATCHhead (the head of every job file, created with generic contents if absent; edit it to suit the cluster) and numbered JobGrasp-<n> files. Each line of a job file starts this script on a family of recipe files, a parent followed by the runs that need it, and writes driver.log in the first one’s directory.
The command line of every direct run is appended to the file command in the current directory.