def setUpModule(): global mol, mf, mc, sa, mol_N2, mf_N2, mc_N2 mol = gto.Mole() mol.verbose = lib.logger.DEBUG mol.output = '/dev/null' mol.atom = [ ['H', (5., -1., 1.)], ['H', (0., -5., -2.)], ['H', (4., -0.5, -3.)], ['H', (0., -4.5, -1.)], ['H', (3., -0.5, -0.)], ['H', (0., -3., -1.)], ['H', (2., -2.5, 0.)], ['H', (1., 1., 3.)], ] mol.basis = 'sto-3g' mol.build() b = 1.4 mol_N2 = gto.Mole() mol_N2.build(verbose=lib.logger.DEBUG, output='/dev/null', atom=[ ['N', (0.000000, 0.000000, -b / 2)], ['N', (0.000000, 0.000000, b / 2)], ], basis={ 'N': 'ccpvdz', }, symmetry=1) mf_N2 = scf.RHF(mol_N2).run() solver1 = fci.FCI(mol_N2) solver1.spin = 0 solver1.nroots = 2 solver2 = fci.FCI(mol_N2, singlet=False) solver2.spin = 2 mc_N2 = CASSCF(mf_N2, 4, 4) mc_N2 = addons.state_average_mix_(mc_N2, [solver1, solver2], (0.25, 0.25, 0.5)).newton() mc_N2.kernel() mf = scf.RHF(mol) mf.max_cycle = 3 mf.kernel() mc = newton_casscf.CASSCF(mf, 4, 4) mc.fcisolver = fci.direct_spin1.FCI(mol) mc.kernel() sa = CASSCF(mf, 4, 4) sa.fcisolver = fci.direct_spin1.FCI(mol) sa = sa.state_average([0.5, 0.5]).newton() sa.kernel()
def newton(mc): from pyscf.mcscf import newton_casscf mc1 = newton_casscf.CASSCF(mc._scf, mc.ncas, mc.nelecas) mc1.__dict__.update(mc.__dict__) mc1.max_cycle_micro = 10 return mc1
mol.atom = [ ['H', (5., -1., 1.)], ['H', (0., -5., -2.)], ['H', (4., -0.5, -3.)], ['H', (0., -4.5, -1.)], ['H', (3., -0.5, -0.)], ['H', (0., -3., -1.)], ['H', (2., -2.5, 0.)], ['H', (1., 1., 3.)], ] mol.basis = 'sto-3g' mol.build() mf = scf.RHF(mol).run(conv_tol=1e-14) numpy.random.seed(1) mf.mo_coeff = numpy.random.random(mf.mo_coeff.shape) mc = newton_casscf.CASSCF(mf, 4, 4) mc.fcisolver = fci.direct_spin1.FCI(mol) ci0 = numpy.random.random((6, 6)) ci0 /= numpy.linalg.norm(ci0) class KnowValues(unittest.TestCase): def test_gen_g_hop(self): mo = mc.mo_coeff gall, gop, hop, hdiag = newton_casscf.gen_g_hop( mc, mo, ci0, mc.ao2mo(mo)) self.assertAlmostEqual(lib.finger(gall), 21.288022525148595, 8) self.assertAlmostEqual(lib.finger(hdiag), -4.6864640132374618, 8) x = numpy.random.random(gall.size) u, ci1 = newton_casscf.extract_rotation(mc, x, 1, ci0) self.assertAlmostEqual(lib.finger(gop(u, ci1)), -412.9441873541524, 8)