1#!/usr/bin/env python
2#
3# Author: Qiming Sun <osirpt.sun@gmail.com>
4#
5
6'''Density functional calculations can be run with either the default
7backend library, libxc, or an alternative library, xcfun. See also
8example 32-xcfun_as_default.py for how to set xcfun as the default XC
9functional library.
10
11'''
12
13from pyscf import gto, dft
14from pyscf.hessian import uks as uks_hess
15from pyscf import tdscf
16
17mol = gto.M(atom="H; F 1 1.", basis='631g')
18
19# Calculation using libxc
20mf = dft.UKS(mol)
21mf.xc = 'CAMB3LYP'
22mf.kernel()
23mf.nuc_grad_method().kernel()
24
25# We can also evaluate the geometric hessian
26hess = uks_hess.Hessian(mf).kernel()
27print(hess.reshape(2,3,2,3))
28
29# or TDDFT gradients
30tdks = tdscf.TDA(mf)
31tdks.nstates = 3
32tdks.kernel()
33tdks.nuc_grad_method().kernel()
34
35# Switch to the xcfun library on the fly
36mf._numint.libxc = dft.xcfun
37# Repeat the geometric hessian
38hess = uks_hess.Hessian(mf).kernel()
39print(hess.reshape(2,3,2,3))
40# and the TDDFT gradient calculation
41tdks = tdscf.TDA(mf)
42tdks.nstates = 3
43tdks.kernel()
44tdks.nuc_grad_method().kernel()
45