Beispiel #1
0
 def test_as_pyscf_method(self):
     gs = scf.RHF(mol).nuc_grad_method().as_scanner()
     f = lambda mol: gs(mol)
     m = berny_solver.as_pyscf_method(mol, f)
     mol1 = berny_solver.optimize(m)
     self.assertAlmostEqual(lib.fp(mol1.atom_coords()), 2.20003359484436, 4)
     self.assertEqual(mol1.symmetry, 'C2v')
Beispiel #2
0
 def test_as_pyscf_method(self):
     mol = gto.M(atom='''
         O  0.   0.       0.
         H  0.   -0.757   0.587
         H  0.   0.757    0.587
                 ''', verbose=0)
     gs = scf.RHF(mol).nuc_grad_method().as_scanner()
     f = lambda mol: gs(mol)
     m = berny_solver.as_pyscf_method(mol, f)
     mol1 = berny_solver.optimize(m)
     self.assertAlmostEqual(lib.finger(mol1.atom_coords()),
                            2.2000335948443315, 5)
Beispiel #3
0
 def test_as_pyscf_method(self):
     mol = gto.M(atom='''
         O  0.   0.       0.
         H  0.   -0.757   0.587
         H  0.   0.757    0.587
                 ''',
                 verbose=0)
     gs = scf.RHF(mol).nuc_grad_method().as_scanner()
     f = lambda mol: gs(mol)
     m = berny_solver.as_pyscf_method(mol, f)
     mol1 = berny_solver.optimize(m)
     self.assertAlmostEqual(lib.finger(mol1.atom_coords()),
                            2.2000335948443315, 5)
Beispiel #4
0
 def test_as_pyscf_method(self):
     mol = gto.M(atom='''
         O  0.   0.       0.
         H  0.   -0.757   0.587
         H  0.   0.757    0.587
                 ''', symmetry=True, verbose=0)
     gs = scf.RHF(mol).nuc_grad_method().as_scanner()
     f = lambda mol: gs(mol)
     m = berny_solver.as_pyscf_method(mol, f)
     mol1 = berny_solver.optimize(m)
     self.assertAlmostEqual(lib.finger(mol1.atom_coords()),
                            3.039311839766823, 4)
     self.assertEqual(mol1.symmetry, 'C2v')
Beispiel #5
0
mf = scf.RHF(mol)

grad_scan = scf.RHF(mol).nuc_grad_method().as_scanner()


def f(mol):
    e, g = grad_scan(mol)
    r = mol.atom_coords()
    penalty = np.linalg.norm(r[0] - r[1])**2 * 0.1
    e += penalty
    g[0] += (r[0] - r[1]) * 2 * 0.1
    g[1] -= (r[0] - r[1]) * 2 * 0.1
    print('Customized |g|', np.linalg.norm(g))
    return e, g


#
# Function as_pyscf_method is a wrapper that convert the "energy-gradients"
# function to berny_solver.  The "energy-gradients" function takes the Mole
# object as geometry input, and returns the energy and gradients of that
# geometry.
#
fake_method = berny_solver.as_pyscf_method(mol, f)
new_mol = berny_solver.optimize(fake_method)

print('Old geometry (Bohr)')
print(mol.atom_coords())

print('New geometry (Bohr)')
print(new_mol.atom_coords())
Beispiel #6
0
cc_scan = cc.CCSD(mf).as_scanner()

def f(mol):
    # Compute CCSD(T) energy
    mf = scf.RHF(mol).run()
    mycc = cc.CCSD(mf).run()
    et_correction = mycc.ccsd_t()
    e_tot = mycc.e_tot + et_correction

    # Compute CCSD(T) gradients
    eris = mycc.ao2mo()
    t1, t2 = mycc.t1, mycc.t2
    conv, l1, l2 = ccsd_t_lambda.kernel(mycc, eris, t1, t2,
                                        verbose=mycc.verbose)
    g = ccsd_t_grad.kernel(mycc, t1, t2, l1, l2, eris=eris,
                           verbose=mycc.verbose)
    print('CCSD(T) nuclear gradients:')
    print(g)
    return e_tot, g

fake_method = berny_solver.as_pyscf_method(mol, f)

new_mol = berny_solver.optimize(fake_method)

print('Old geometry (Bohr)')
print(mol.atom_coords())

print('New geometry (Bohr)')
print(new_mol.atom_coords())

Beispiel #7
0
    lib.logger.info(mf_grad_scan, "* Disp Energy [au]: %12.8f" % edisp[0])
    lib.logger.info(mf_grad_scan, "* Disp Gradients [au]:")
    atmlst = range(mol.natm)
    for k, ia in enumerate(atmlst):
        symb = mol.atom_pure_symbol(ia)
        lib.logger.info(mf_grad_scan,"* %d %s %12.8f %12.8f %12.8f" \
        % (ia, symb, grad[k,0], grad[k,1], grad[k,2]))
    e_tot += edisp[0]
    g_rhf += grad
    lib.logger.info(mf_grad_scan, "* Total Energy [au]: %12.8f" % e_tot)
    lib.logger.info(mf_grad_scan, "* Total Gradients [au]:")
    atmlst = range(mol.natm)
    for k, ia in enumerate(atmlst):
        symb = mol.atom_pure_symbol(ia)
        lib.logger.info(mf_grad_scan,"* %d %s %12.8f %12.8f %12.8f" \
        % (ia, symb, g_rhf[k,0], g_rhf[k,1], g_rhf[k,2]))
    return e_tot, g_rhf


mf = berny_solver.as_pyscf_method(mol, mf_grad_with_dftd3)
mol = berny_solver.kernel(mf, maxsteps=50, assert_convergence=True)
xyzfile = name + '_opt.xyz'
fspt = open(xyzfile, 'w')
coords = mol.atom_coords() * lib.param.BOHR
fspt.write('%d \n' % mol.natm)
fspt.write('%d %d\n' % (mol.charge, (mol.spin + 1)))
for ia in range(mol.natm):
    symb = mol.atom_pure_symbol(ia)
    fspt.write('%s  %12.6f  %12.6f  %12.6f\n' % (symb, \
    coords[ia][0],coords[ia][1], coords[ia][2]))