Available XC functionals#
A number of exchange–correlation (XC) functionals are available in VeloxChem.
We will calculate the electronic energy of helium using the Hartree–Fock and second-order Møller–Plesset methods as well as Kohn–Sham density functional theory using the available XC functionals.
import matplotlib.pyplot as plt
import veloxchem as vlx
* Warning * Environment variable OMP_NUM_THREADS not set.
* Warning * Setting OMP_NUM_THREADS to 4.
molecule = vlx.Molecule.read_molecule_string("He 0.000 0.000 0.000")
basis = vlx.MolecularBasis.read(molecule, "cc-pvtz")
Show code cell output
* Info * Reading basis set from file: /home/thomas/miniconda3/envs/echem/lib/python3.10/site-packages/veloxchem/basis/CC-PVTZ
Molecular Basis (Atomic Basis)
================================
Basis: CC-PVTZ
Atom Contracted GTOs Primitive GTOs
He (3S,2P,1D) (6S,2P,1D)
Contracted Basis Functions : 14
Primitive Basis Functions : 17
Hartree–Fock#
scf_drv = vlx.ScfRestrictedDriver()
scf_results = scf_drv.compute(molecule, basis)
scf_energies = {}
scf_energies["HF"] = scf_drv.get_scf_energy()
Show code cell output
Self Consistent Field Driver Setup
====================================
Wave Function Model : Spin-Restricted Hartree-Fock
Initial Guess Model : Superposition of Atomic Densities
Convergence Accelerator : Two Level Direct Inversion of Iterative Subspace
Max. Number of Iterations : 50
Max. Number of Error Vectors : 10
Convergence Threshold : 1.0e-06
ERI Screening Scheme : Cauchy Schwarz + Density
ERI Screening Mode : Dynamic
ERI Screening Threshold : 1.0e-12
Linear Dependence Threshold : 1.0e-06
* Info * Nuclear repulsion energy: 0.0000000000 a.u.
* Info * Overlap matrix computed in 0.00 sec.
* Info * Kinetic energy matrix computed in 0.00 sec.
* Info * Nuclear potential matrix computed in 0.00 sec.
* Info * Orthogonalization matrix computed in 0.00 sec.
* Info * SAD initial guess computed in 0.00 sec.
* Info * Starting Reduced Basis SCF calculation...
* Info * ...done. SCF energy in reduced basis set: -2.861153332069 a.u. Time: 0.01 sec.
* Info * Overlap matrix computed in 0.00 sec.
* Info * Kinetic energy matrix computed in 0.00 sec.
* Info * Nuclear potential matrix computed in 0.00 sec.
* Info * Orthogonalization matrix computed in 0.00 sec.
Iter. | Hartree-Fock Energy | Energy Change | Gradient Norm | Max. Gradient | Density Change
--------------------------------------------------------------------------------------------
1 -2.861153344417 0.0000000000 0.00005116 0.00001711 0.00000000
2 -2.861153344784 -0.0000000004 0.00000074 0.00000026 0.00002494
*** SCF converged in 2 iterations. Time: 0.34 sec.
Spin-Restricted Hartree-Fock:
-----------------------------
Total Energy : -2.8611533448 a.u.
Electronic Energy : -2.8611533448 a.u.
Nuclear Repulsion Energy : 0.0000000000 a.u.
------------------------------------
Gradient Norm : 0.0000007371 a.u.
Ground State Information
------------------------
Charge of Molecule : 0.0
Multiplicity (2S+1) : 1.0
Magnetic Quantum Number (M_S) : 0.0
Spin Restricted Orbitals
------------------------
Molecular Orbital No. 1:
--------------------------
Occupation: 2.000 Energy: -0.91763 a.u.
( 1 He 1s : -0.35) ( 1 He 2s : -0.48) ( 1 He 3s : -0.31)
Molecular Orbital No. 2:
--------------------------
Occupation: 0.000 Energy: 0.63664 a.u.
( 1 He 1s : -0.16) ( 1 He 2s : -1.16) ( 1 He 3s : 1.53)
Molecular Orbital No. 3:
--------------------------
Occupation: 0.000 Energy: 1.50051 a.u.
( 1 He 2p+1: -1.02) ( 1 He 2p-1: -0.19)
Molecular Orbital No. 4:
--------------------------
Occupation: 0.000 Energy: 1.50051 a.u.
( 1 He 2p+1: -0.19) ( 1 He 2p-1: 1.01)
Molecular Orbital No. 5:
--------------------------
Occupation: 0.000 Energy: 1.50051 a.u.
( 1 He 2p0 : -1.03)
Molecular Orbital No. 6:
--------------------------
Occupation: 0.000 Energy: 4.60856 a.u.
( 1 He 1s : -1.49) ( 1 He 2s : 1.95) ( 1 He 3s : -0.85)
MP2#
mp2_drv = vlx.Mp2Driver()
mp2_results = mp2_drv.compute(molecule, basis, scf_drv.mol_orbs)
scf_energies["MP2"] = mp2_results["mp2_energy"] + scf_energies["HF"]
Show code cell output
MP2 Driver Setup
==================
Number of Fock Matrices : 1
Size of Fock Matrices Batch : 100
Number of Subcommunicators : 1
ERI Screening Scheme : Cauchy Schwarz + Density
ERI Screening Threshold : 1.0e-12
Monitoring calculation on master node.
1 Fock matrices will be processed on master node.
1 / 1 Fock matrices processed. Time: 0.06 sec
*** MP2 correlation energy: -0.033137563408 a.u.
DFT#
for xcfun in vlx.available_functionals():
scf_drv.xcfun = xcfun
scf_drv.ostream.mute()
scf_drv.compute(molecule, basis)
scf_energies[xcfun] = scf_drv.get_scf_energy()
for method in scf_energies:
if method not in ["HF", "MP2"]:
print(f' {method:<12s}: {scf_energies[method]:16.8f} a.u.')
SLATER : -2.72271178 a.u.
SLDA : -2.87143717 a.u.
B88X : -2.86247050 a.u.
BLYP : -2.90621759 a.u.
B3LYP : -2.91450655 a.u.
BHANDH : -2.83473781 a.u.
BHANDHLYP : -2.90514866 a.u.
PBE : -2.89213590 a.u.
PBE0 : -2.89451563 a.u.
REVPBE : -2.90710482 a.u.
BP86 : -2.90557480 a.u.
PW91 : -2.89919908 a.u.
MPW1K : -2.90521521 a.u.
OLYP : -2.90644600 a.u.
O3LYP : -2.90951647 a.u.
X3LYP : -2.90759000 a.u.
B97 : -2.90931588 a.u.
B97-1 : -2.90639481 a.u.
B97-2 : -2.90940855 a.u.
B97-3 : -2.91133188 a.u.
TPSS : -2.90886838 a.u.
TPSSH : -2.90836089 a.u.
REVTPSS : -2.91132827 a.u.
PKZB : -2.90387499 a.u.
SCAN : -2.90431544 a.u.
RSCAN : -2.90431544 a.u.
R2SCAN : -2.90431544 a.u.
M05 : -2.90471113 a.u.
M05-2X : -2.90804370 a.u.
M06 : -2.90925996 a.u.
M06-2X : -2.90399052 a.u.
M06-HF : -2.90187434 a.u.
M06-L : -2.91319059 a.u.
M11-L : -2.91833797 a.u.
MPW1B95 : -2.90141905 a.u.
MPWB1K : -2.90163660 a.u.
PW6B95 : -2.91673962 a.u.
PWB6K : -2.90888490 a.u.
Plotting the energies#
fig, ax = plt.subplots(figsize=(10, 6))
for i, method in enumerate(scf_energies.keys()):
ax.plot(i, scf_energies[method], "o")
ax.set_xticks(range(len(scf_energies)), scf_energies.keys())
plt.xticks(rotation=90)
ax.set_ylim(-2.93, -2.82)
plt.ylabel("Electronic energy (a.u.)")
plt.grid(True)
plt.show()
