This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/hf/scf

Hartree-Fock from a molecule, in one call

import basis.pople631g
from hf.mole import molecule
from hf.scf import rhf

mol = molecule("O 0 0 0; H 0 -0.757 0.587; H 0 0.757 0.587", "6-31g")
r = rhf(mol)
show r.energy

molecule(atoms, basis) (lib/hf/mole) takes the atoms as PySCF's atom= text or an XYZ file, in angstrom, and the basis set by PySCF's name for it (STO-3G, 6-31G, 6-31G, 6-31G*, cc-pVDZ, cc-pVTZ, def2-SVP and def2-TZVP, H through Ar). molecule_from(z, xyz, basis) (lib/hf/molecule) builds the same molecule from atomic numbers, an array of coordinates and one table of lib/basis. rhf, uhf and rohf run the whole pipeline with the production options and return an ScfResult (lib/hf/scf_loop):

| Field | What it holds | |---|---| | energy | the total energy, hartree | | converged, iterations | 1 when the energy and the commutator settled; how many iterations it took | | density | the total density matrix, [n, n] | | mo_coeff, mo_energy, mo_occ | the orbitals as AO coefficients (columns), their energies and occupations | | fock | the Fock matrix (UHF and ROHF: the average of the two spins') | | alpha, beta | each spin's mo_coeff, mo_energy, mo_occ, density and fock | | grad | the largest element of F D S - S D F | | s2 | <S^2> | | energy_check | the energy by a second formula, from J and K |

scf_with(mol, o) runs with options o (lib/hf/opts), changed from the defaults by a record update:

r = scf_with(mol, ScfOptions { method: SCF_UHF, guess: GS_CORE, ..scf_defaults() })

and the molecule's charge, spin or Cartesian functions the same way:

cation = rohf(Molecule { charge: 1, spin: 1, ..mol })

Each of them is two calls:

setup = integrals(mol, o)     the molecule's integrals (lib/hf/ao), its
                              electron counts, its nuclear repulsion and
                              the options, as an ScfSetup
r = scf(setup)                the SCF loop (lib/hf/scf_loop)

Every stage on that path is its production member, called by name. Below this layer every stage is reachable on its own: the integrals of a molecule (lib/hf/ao), the SCF loop from matrices (lib/hf/scf_loop), stability analysis (lib/hf/stab). The same pipeline with every integral member run and held to agree is lib/hf/hf (hf_setup(mol, scf_checked())), and the registries and sweeps are lib/hf/integrals; both are verification, and nothing here uses them.

Used with import hf.scf.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 61–163