Common use cases#
In this section, we’ll provide a quick reference to some common use cases. Be sure to check out the gqcpy example notebooks as well!
Hartree-Fock calculations#
RHF#
In this use case, we will calculate the restricted HF energy for H2 in an STO-3G basis set.
Molecular setup#
The first step consists of generating the Molecule
object from which we can obtain properties. The simplest way to do so is to provide an xyz
file.
molecule = gqcpy.Molecule.ReadXYZ("h2.xyz")
N = molecule.numberOfElectrons()
const auto molecule = GQCP::Molecule::ReadXYZ("data/h2.xyz");
const auto N = molecule.numberOfElectrons();
Before we go over to the calculation of integrals, an orbital basis must be constructed. The RHF method uses a restricted spin-orbital basis. We can immediately use this object to find the overlap integrals.
spinor_basis = gqcpy.RSpinOrbitalBasis(molecule, "STO-3G")
S = spinor_basis.quantize(gqcpy.OverlapOperator()).parameters()
const auto spinor_basis = GQCP::RSpinOrbitalBasis::ReadXYZ(molecule, "STO-3G";
const auto S = spinor_basis.overlap().parameters();
This spinor basis is used to construct a Hamiltonian operator in second quantization (SQ).
sq_hamiltonian = spinor_basis.quantize(gqcpy.FQMolecularHamiltonian(molecule)) # in an AO basis
const auto sq_hamiltonian = spinor_basis.quantize(GQCP::FQMolecularHamiltonian(molecule)); // in an AO basis
Plain RHF SCF#
To solve the RHF SCF equations, we will need to set up a Solver
and its associated Environment
. The environment will provide all necessary intermediates for the solver to use.
rhf_environment = gqcpy.RHFSCFEnvironment.WithCoreGuess(N, sq_hamiltonian, S)
plain_rhf_scf_solver = gqcpy.RHFSCFSolver.Plain()
gqcpy.RHF.optimize(solver, environment).groundStateParameters() # nog niet af!!!!
auto rhf_environment = GQCP::RHFSCFEnvironment<double>::WithCoreGuess(N, sq_hamiltonian, spinor_basis.overlap().parameters());
auto plain_rhf_scf_solver = GQCP::RHFSCFSolver<double>::Plain();
In order to really confirm that the electronic structure model’s parameter are ‘optimal’, in our case a diagonal Fock matrix, we must define an objective.
objective = gqcpy.DiagonalRHFFockMatrixObjective(sq_hamiltonian) # use the default threshold of 1.0e-08
const GQCP::DiagonalRHFFockMatrixObjective<double> objective {sq_hamiltonian};
The objective, solver and environment are combined into the optimize method of the RHF QCMethod, which returns a QCStructure
containing the optimized RHF parameters that satisfy the objective.
rhf_parameters = gqcpy.RHF.optimize(objective, plain_rhf_scf_solver, rhf_environment).groundStateParameters()
const auto rhf_parameters = GQCP::QCMethod::RHF<double>().optimize(objective, plain_rhf_scf_solver, rhf_environment).groundStateParameters();
These optimized RHF parameters can be obtained through the QCStructure
object. Examples are the coefficient matrix, with every spatial orbital as a column, and orbital energies.
C = rhf_parameters.expansion()
energies = rhf_parameters.orbitalEnergies()
const auto C = rhf_parameters.expansion();
const auto E = rhf_parameters.orbitalEnergies();
UHF#
We can start off UHF SCF calculation in the same way as we did with RHF SCF calculations.
Molecular setup#
The first step consists of generating the Molecule
object from which we can obtain properties. The simplest way to do so is to provide an xyz
file.
molecule = gqcpy.Molecule.ReadXYZ("h2.xyz")
N = molecule.numberOfElectrons()
N_alpha = N//2
N_beta = N//2
const auto molecule = GQCP::Molecule::ReadXYZ("data/h2.xyz");
const auto N = molecule.numberOfElectrons();
const auto N_alpha = N/2;
const auto N_beta = N/2;
Before we go over to the calculation of integrals, an orbital basis must be constructed. The RHF method uses an AO basis. We can immediately use this object to find the overlap integrals.
spinor_basis = gqcpy.RSpinOrbitalBasis(molecule, "STO-3G")
S = spinor_basis.quantize(gqcpy.OverlapOperator()).parameters()
const auto spinor_basis = GQCP::RSpinOrbitalBasis::ReadXYZ(molecule, "STO-3G";
const auto S = spinor_basis.overlap().parameters();
This spinor basis is used to construct a Hamiltonian operator in second quantization (sq).
sq_hamiltonian = spinor_basis.quantize(gqcpy.FQMolecularHamiltonian(molecule)) # in an AO basis
const auto sq_hamiltonian = spinor_basis.quantize(GQCP::FQMolecularHamiltonian(molecule)); // in an AO basis
Plain UHF SCF#
To solve the UHF SCF equations, we will need to set up a Solver
and its associated Environment
. The environment will provide all necessary intermediates for the solver to use.
uhf_environment = gqcpy.UHFSCFEnvironment.WithCoreGuess(N_alpha, N_beta, sq_hamiltonian, S)
plain_uhf_scf_solver = gqcpy.UHFSCFSolver.Plain()
auto uhf_environment = GQCP::UHFSCFEnvironment<double>::WithCoreGuess(N_alpha, N_beta,, sq_hamiltonian, spinor_basis.overlap().parameters());
auto plain_uhf_scf_solver = GQCP::UHFSCFSolver<double>::Plain();