API reference
These signatures and docstrings come from the installed FLODI package.
Use Your first fields for a first calculation, Representations and normalization for
representation conventions, and Working through the assignment to choose a topic.
An operator’s return type and normalization convention are part of its
contract; the assignment defines how those operations enter your model.
Grid constructors
-
class flodi.RadialGrid
Spherically symmetric physical fields with one radial index.
-
classmethod uniform(*, n_r=200, r_max=12.0)
Construct this grid class with uniformly spaced radial faces.
-
classmethod __new__(*args, **kwargs)
-
__init__(r_faces, r, weights, cell_volumes)
-
class flodi.SphericalGrid
Fields with explicit indices (r, theta, phi); phi is periodic.
-
classmethod uniform(*, n_r=12, n_theta=8, n_phi=12, r_max=8.0)
Construct this grid class with uniform steps in r, theta, and phi.
-
classmethod __new__(*args, **kwargs)
-
__init__(r, theta, phi, r_faces, theta_faces, phi_faces, cell_volumes)
-
class flodi.ProlateGrid
Axially symmetric fields with indices (xi, eta).
-
classmethod uniform(*, n_xi=20, n_eta=20, xi_max=5.0, distance=2.0)
Construct this grid class with uniform steps in xi and eta.
-
classmethod __new__(*args, **kwargs)
-
__init__(distance, xi_faces, eta_faces, xi, eta, weights, cell_volumes, r_a, r_b, rho, z)
Shared grid operations
-
class flodi.Grid
Common numerical language; geometry subclasses supply the coordinates.
Field axes follow the geometry. Geometry attributes and stored arrays
are read-only; the sparse Laplacian is built lazily and cached for reuse.
-
closed_shell(orbitals, *, sectors=None)
Build a closed-shell state from occupied physical orbital fields.
sectors optionally supplies one azimuthal integer per orbital on a
prolate grid. Each occupied spatial orbital represents two electrons.
-
sample(function_or_values, *, outer_boundary=None)
Sample a known function at cell centres and the outer face.
Scalars describe constant fields everywhere. Arrays supply only
centre values unless outer_boundary is given. An explicit outer
boundary may be a scalar, a face array, or a coordinate function.
-
integrate(*terms)
Integrate the product of the terms against physical cell volumes.
No conjugation is implicit: integrate(psi.conj(), psi) is a norm.
With no terms, return the volume of the truncated domain.
-
integrate_reduced(*terms)
Integrate a product against W, for separated angular factors.
Prolate: psi=f/sqrt(2*pi), with W containing the xi/eta measure.
Radial: psi=R/sqrt(4*pi), with W containing the radial r^2 measure.
Physical orbitals and densities use integrate(). With all angles
explicit, there is no reduced measure.
-
to_vector(field)
Convert a physical field to volume-weighted eigensolver entries.
y_i = sqrt(cell_volume_i) * psi_i, flattened in the grid’s order.
The ordinary vector inner product then equals the physical field
integral. This conversion does not normalize or change the field.
Outer-face values are not part of the vector.
-
from_vector(vector, *, outer_boundary=0)
Recover a physical field from volume-weighted vector entries.
Undo to_vector’s weighting and flattening without renormalizing.
The default zero outer boundary is appropriate for bound-orbital
eigenproblems, not for a Coulomb potential. Override it when needed.
-
linear_operator(action, *, dtype=<class 'float'>)
Adapt a linear field-to-field action to a SciPy LinearOperator.
Each application converts a weighted vector to a physical field
with zero outer values, calls action(field), and converts the
returned field back. No operator matrix is assembled here.
The caller must supply a linear action. It is suitable for eigsh
only if self-adjoint in the physical volume-weighted inner product;
this adapter preserves that property but does not enforce it for
arbitrary callbacks. Keep density-dependent potentials fixed during
an eigensolve. Use dtype=complex for a complex-valued action.
-
lowest_orbital(potential=None, *, initial=None, tol=1e-11, action=None, m=0, dtype=None)
Return (energy, physical orbital) for the lowest eigenpair.
Solve -0.5*laplacian + a real local potential with zero outer
orbital values. initial is an optional physical starting orbital.
tol controls the iterative solver; radial grids use a direct solve.
Alternatively, action= supplies the complete self-adjoint field
operation (including kinetic energy). m selects the azimuthal
sector for a local potential on a prolate grid.
-
lowest_orbitals(potential=None, k=1, *, initial=None, tol=1e-11, action=None, m=0, dtype=None)
Return ascending energies and a tuple of k physical orbital fields.
Orbitals are orthonormal under integrate() and have zero outer
values. Use a direct tridiagonal solve on radial grids and eigsh
otherwise. Requesting every state on an angular grid uses a dense
solve and requires quadratic storage. These are eigenstates of the
supplied fixed local potential, not necessarily HF virtual orbitals.
Use action= instead of potential for a complete self-adjoint field
action; it always uses the general eigensolver. dtype defaults to
float or the action’s dtype attribute. Complex actions can specify
dtype=complex. m applies only to the local-potential interface.
-
property laplacian_matrix
Cached CSR matrix acting on flattened cell-centre values.
-
laplacian(field, *, outer_boundary=None, m=0)
Return a Field containing the Laplacian at the cell centres.
Boundary values come from the input field or an explicit override.
The derivative’s own boundary is unknown: another differentiation
requires supplying it. Multiplication and integration need none.
On a prolate grid m selects the full Laplacian of the amplitude
times exp(i*m*phi); stored amplitudes still use integrate().
-
poisson(source, *, outer_boundary=None, m=0)
Return V satisfying -laplacian(V)=4*pi*source.
By default match the potential and flux to a source-free exterior
that decays at infinity. This preserves volume-weighted Coulomb
reciprocity, including on angular grids. The source is density
per volume; signed and complex sources are also supported. Choose
a domain large enough that its omitted source is negligible.
For verification, outer_boundary can supply a known potential
function or prescribed face values. A source field’s own boundary
describes the source and is never reused as the potential boundary.
Each boundary type’s sparse LU factorization is cached on this grid;
new sources and prescribed boundary values reuse it.
On prolate grids m selects the source’s azimuthal Fourier mode;
nonzero modes use their own decaying exterior and cached factors.
-
classmethod __new__(*args, **kwargs)
-
__init__()
Functions and fields
-
class flodi.GridFunction
Evaluate a vectorized function using explicitly named coordinates.
For example, GridFunction(profile, coordinates=(“r_a”,)) calls
profile(points.r_a). The same mapping applies at centres and outer faces.
Coordinate order determines positional argument order. The function must
return a scalar or an array with the shape of its coordinate arguments.
-
classmethod __new__(*args, **kwargs)
-
__init__(function, coordinates)
-
class flodi.Field
A field’s centre values, its grid, and optional outer-face values.
Create fields with grid.sample(). Arithmetic preserves boundary values
when all operands have them. Use .values to access the NumPy array.
-
classmethod __new__(*args, **kwargs)
-
__init__(grid, values, boundary=None)
Closed-shell states
-
class flodi.ClosedShell
A closed-shell occupied state, including its off-diagonal information.
Construct with grid.closed_shell(orbitals, sectors=[…]). Orbitals in
each angular sector must already be orthonormal. Different sectors are
angularly orthogonal even if their amplitude arrays coincide.
-
__init__(grid, orbitals, *, sectors=None)
-
property density
Total electron density, including both spins.
-
mix(output, alpha=0.3)
Return (1-alpha)*input + alpha*output as full density operators.
This retains the information required by exchange, preserves sector
occupations, and permits non-projector mixed SCF inputs.
-
difference(other)
Frobenius norm of the difference of the weighted spin densities.
-
exchange(orbital, *, m=0)
Apply the sum of occupied exchange operators in target sector m.
-
fock(potential, *, m=0)
Return a fixed, self-adjoint RHF action for use with action=.
potential is the nuclear/local external potential. This state adds
the full Hartree potential and subtracts occupied exchange once.
-
energy(potential, *, nuclear_repulsion=0)
Return RHF total energy, Tr[P(h+F)] plus nuclear repulsion.
-
classmethod __new__(*args, **kwargs)
Visualization
These helpers require the optional visualization dependencies when extracting,
exporting, or drawing meshes. Core numerical operations do not import them.
Signed orbital isosurfaces for prolate fields, using optional PyTessel.
Interpolation is for visualization only. It does not refine the SCF solution.
The real pi combinations are sqrt(2)*Re/Im[f*exp(i*m*phi)].
-
class flodi.visualization.Isosurface
One signed level, Cartesian vertices in bohr, and indexed triangles.
-
__init__(level, vertices, normals, triangles)
-
flodi.visualization.cartesian_orbital(grid, orbital, *, m=0, component='cos', extent=5.0, resolution=120)
Return a real orbital on an x-fastest Cartesian cube centred at zero.
For nonzero m, cos/sin select normalized real combinations of opposite
angular sectors. For m=0, use the real amplitude (component=’cos’).
Returns (values[z,y,x], cell); the cube covers [-extent, extent).
-
flodi.visualization.orbital_isosurfaces(grid, orbital, *, m=0, component='cos', fraction=0.08, level=None, extent=5.0, resolution=120)
Extract signed surfaces at a relative or absolute level using PyTessel.
A relative level makes differently sized orbitals visible; these pictures
are not comparisons at one common absolute orbital amplitude.
Supply level in a0^(-3/2) to override fraction for controlled comparisons.
-
flodi.visualization.save_isosurfaces(surfaces, path)
Write positive/negative PLY meshes, viewable in MeshLab or Blender.
-
flodi.visualization.draw_isosurfaces(ax, surfaces, *, nuclei=(), title='')
Draw the signed meshes with equal Cartesian scales on a 3D axes.