Skip to content

geometry optimization with dispersion correction #1986

@LKFEIYI

Description

@LKFEIYI

Hi,
I tried to optimize a molecule with B3LYP-D3/D4 (Simple DFT-D3). But there are some errors.

from pyscf import gto, dft, scf
import dftd3.pyscf as disp
from pyscf.geomopt.geometric_solver import optimize

#no spin RHF
try:
    mol = gto.M(atom='O 0 0 0; O 0 0 1.8', unit='ANG', basis='631g*')
    mf = scf.RHF(mol)
    #mf.xc='b3lyp'
    grad=disp.energy(mf).nuc_grad_method().as_scanner()
    grad.optimizer().kernel()
    print("no spin RHF: OK")
except Exception as e:
    print(e)


#spin=1 hydroxides RHF
try:
    mol = gto.M(atom='H 0 0 0; O 0 0 1.8', unit='ANG', basis='631g*', spin=1)
    mf = scf.RHF(mol)
    #mf.xc='b3lyp'
    grad=disp.energy(mf).nuc_grad_method().as_scanner()
    grad.optimizer().kernel()
    print("spin=1 RHF: OK")
except Exception as e:
    print(e)

#spin=0 RKS
try:
    mol = gto.M(atom='O 0 0 0; O 0 0 1.8', unit='ANG', basis='631g*')
    mf = dft.RKS(mol)
    mf.xc='b3lyp'
    grad=disp.energy(mf).nuc_grad_method().as_scanner()
    grad.optimizer().kernel()
    print("spin=0 RKS: OK")
except Exception as e:
    print(e)

The above optimization works.

#spin=1 hydroxides RKS
try:
    mol = gto.M(atom='H 0 0 0; O 0 0 1.8', unit='ANG', basis='631g*', spin=1)
    mf = dft.RKS(mol)
    mf.xc='b3lyp'
    grad=disp.energy(mf).nuc_grad_method().as_scanner()
    grad.optimizer().kernel()
    print("spin=1 RKS: OK")
except Exception as e:
    print(e)

#spin=2  RKS
try:
    mol = gto.M(atom='O 0 0 0; O 0 0 1.8', unit='ANG', basis='631g*', spin=2)
    mf = dft.RKS(mol)
    mf.xc='b3lyp'
    grad=disp.energy(mf).nuc_grad_method().as_scanner()
    grad.optimizer().kernel()
    print("spin=2 RKS: OK")
except Exception as e:
    print(e)

When introducing spin to RKS, an error was raised: ''
mo_occ_a = (dm.mo_occ > 0).astype(numpy.double)
^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'list' and 'int'

When implementing UKS, it raised 'scf_grad must be an instance of Gradients'.

#spin=1 hydroxides UKS
try:
    mol = gto.M(atom='H 0 0 0; O 0 0 1.8', unit='ANG', basis='631g*', spin=1)
    mf = dft.UKS(mol)
    mf.xc='b3lyp'
    grad=disp.energy(mf).nuc_grad_method().as_scanner()
    grad.optimizer().kernel()
    print("spin UKS: OK")
except Exception as e:
    print(e)

So, it seems that 'spin' does not work for dft-d3 correction? And UKS is not supported?
I am not sure if these errors are rooted in pyscf or dftd3/d4 package. But they all work well without dftd3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions