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/molecule

A molecule and its basis, built in Viv

A Hartree-Fock run starts from the nuclei (charges and positions) and a basis set (Gaussian shells on each atom). Molecule holds both, in the packs every integral routine of lib/hf reads, with the charge, the spin and the choice of Cartesian or spherical functions:

atoms    [natm, 4]  (Z, x, y, z) in bohr
shells   [nsh, 8]   (atom, l, nprim, p0, cart0, sph0, ncart, nsph)
prims    [nprim, 2] (exponent, coefficient)
charge   net charge
spin     alpha minus beta electrons, as PySCF's `Mole.spin`
cart     1 for Cartesian functions, 0 for spherical ones (PySCF's default)

molecule_from(z, xyz, basis) builds one from atomic numbers, coordinates in angstrom (PySCF's default unit) and a Basis record from lib/basis:

from basis.pople631g import basis_631g
from hf.molecule import molecule_from
mol = molecule_from([8, 1, 1], [[0, 0, 0], [0, -0.757, 0.587], [0, 0.757, 0.587]], basis_631g())

(lib/hf/mole's molecule("O 0 0 0; H 0 -0.757 0.587; H 0 0.757 0.587", "6-31g") builds the same molecule from text and a basis name.)

For each atom it copies that element's shells from the basis table, in the table's order, and numbers the atomic orbitals as it goes. Coordinates are converted with PySCF 2.5.0's bohr, 0.52917721092 angstrom, multiplying by its inverse as PySCF does, so the atoms pack is PySCF's to the last bit. The coefficients are the basis set's own; PySCF stores the same contraction rescaled to unit norm, and lib/hf normalizes every shell itself (bas_contract), so the integrals do not depend on the scale. Every molecule of the lock ladder built here (water in six basis sets, OH, O2, HF, NH3, CH4, N2, He and H) has PySCF's packs shell for shell, which scf/molecule_packs.viv checks against lib/hfref.

The charge is 0 and the spin is the electron count's parity (a doublet for an odd count; PySCF refuses an odd count with spin 0). Change them, or ask for Cartesian functions, with a record update:

cation = Molecule { charge: 1, spin: 1, ..mol }
mol6d = Molecule { cart: 1, ..mol }

molecule_packs(atoms, shells, prims) wraps packs made elsewhere, such as PySCF's in lib/hfref, which the lock ladder holds lib/hf against.

Used with import hf.molecule.

Look inside this program

  • Atlas

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

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

This program declares a record type (Molecule), and records run only in compiled C for now, so the Run buttons here are off. Open it in the workbench and use its C tab to compile it.

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 51–225