1#!/usr/bin/env python 2# Copyright 2014-2019 The PySCF Developers. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16# Author: Qiming Sun <osirpt.sun@gmail.com> 17# 18 19''' 20Non-relativistic restricted open-shell Kohn-Sham 21''' 22 23import numpy 24from pyscf import lib 25from pyscf.scf import rohf 26from pyscf.dft.uks import energy_elec 27from pyscf.dft import rks 28from pyscf.dft import uks 29 30 31@lib.with_doc(uks.get_veff.__doc__) 32def get_veff(ks, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1): 33 if getattr(dm, 'mo_coeff', None) is not None: 34 mo_coeff = dm.mo_coeff 35 mo_occ_a = (dm.mo_occ > 0).astype(numpy.double) 36 mo_occ_b = (dm.mo_occ ==2).astype(numpy.double) 37 dm = lib.tag_array(dm, mo_coeff=(mo_coeff,mo_coeff), 38 mo_occ=(mo_occ_a,mo_occ_b)) 39 return uks.get_veff(ks, mol, dm, dm_last, vhf_last, hermi) 40 41 42class ROKS(rks.KohnShamDFT, rohf.ROHF): 43 '''Restricted open-shell Kohn-Sham 44 See pyscf/dft/rks.py RKS class for the usage of the attributes''' 45 def __init__(self, mol, xc='LDA,VWN'): 46 rohf.ROHF.__init__(self, mol) 47 rks.KohnShamDFT.__init__(self, xc) 48 49 def dump_flags(self, verbose=None): 50 rohf.ROHF.dump_flags(self, verbose) 51 rks.KohnShamDFT.dump_flags(self, verbose) 52 return self 53 54 get_veff = get_veff 55 get_vsap = rks.get_vsap 56 energy_elec = energy_elec 57 58 init_guess_by_vsap = rks.init_guess_by_vsap 59 60 def nuc_grad_method(self): 61 from pyscf.grad import roks 62 return roks.Gradients(self) 63 64 65if __name__ == '__main__': 66 from pyscf import gto 67 from pyscf.dft import xcfun 68 mol = gto.Mole() 69 mol.verbose = 7 70 mol.output = '/dev/null'#'out_rks' 71 72 mol.atom.extend([['He', (0.,0.,0.)], ]) 73 mol.basis = { 'He': 'cc-pvdz'} 74 #mol.grids = { 'He': (10, 14),} 75 mol.build() 76 77 m = ROKS(mol).run() 78 m.xc = 'b88,lyp' 79 print(m.scf()) # -2.8978518405 80 81 m = ROKS(mol) 82 m._numint.libxc = xcfun 83 m.xc = 'b88,lyp' 84 print(m.scf()) # -2.8978518405 85 86