def test_init(self): from pyscf import dft from pyscf import x2c mol_r = mol mol_u = gto.M(atom='Li', spin=1, verbose=0) mol_r1 = gto.M(atom='H', spin=1, verbose=0) sym_mol_r = molsym sym_mol_u = gto.M(atom='Li', spin=1, symmetry=1, verbose=0) sym_mol_r1 = gto.M(atom='H', spin=1, symmetry=1, verbose=0) self.assertTrue(isinstance(scf.RKS(mol_r), dft.rks.RKS)) self.assertTrue(isinstance(scf.RKS(mol_u), dft.roks.ROKS)) self.assertTrue(isinstance(scf.UKS(mol_r), dft.uks.UKS)) self.assertTrue(isinstance(scf.ROKS(mol_r), dft.roks.ROKS)) self.assertTrue(isinstance(scf.GKS(mol_r), dft.gks.GKS)) self.assertTrue(isinstance(scf.KS(mol_r), dft.rks.RKS)) self.assertTrue(isinstance(scf.KS(mol_u), dft.uks.UKS)) self.assertTrue(isinstance(scf.RHF(mol_r), scf.hf.RHF)) self.assertTrue(isinstance(scf.RHF(mol_u), scf.rohf.ROHF)) self.assertTrue(isinstance(scf.RHF(mol_r1), scf.rohf.ROHF)) self.assertTrue(isinstance(scf.UHF(mol_r), scf.uhf.UHF)) self.assertTrue(isinstance(scf.UHF(mol_u), scf.uhf.UHF)) self.assertTrue(isinstance(scf.UHF(mol_r1), scf.uhf.UHF)) self.assertTrue(isinstance(scf.ROHF(mol_r), scf.rohf.ROHF)) self.assertTrue(isinstance(scf.ROHF(mol_u), scf.rohf.ROHF)) self.assertTrue(isinstance(scf.ROHF(mol_r1), scf.rohf.ROHF)) self.assertTrue(isinstance(scf.HF(mol_r), scf.hf.RHF)) self.assertTrue(isinstance(scf.HF(mol_u), scf.uhf.UHF)) self.assertTrue(isinstance(scf.HF(mol_r1), scf.rohf.ROHF)) self.assertTrue(isinstance(scf.GHF(mol_r), scf.ghf.GHF)) self.assertTrue(isinstance(scf.GHF(mol_u), scf.ghf.GHF)) self.assertTrue(isinstance(scf.GHF(mol_r1), scf.ghf.GHF)) self.assertTrue(not isinstance(scf.DHF(mol_r), scf.dhf.RHF)) self.assertTrue(isinstance(scf.DHF(mol_u), scf.dhf.UHF)) self.assertTrue(isinstance(scf.DHF(mol_r1), scf.dhf.HF1e)) self.assertTrue(isinstance(scf.RHF(sym_mol_r), scf.hf_symm.RHF)) self.assertTrue(isinstance(scf.RHF(sym_mol_u), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.RHF(sym_mol_r1), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.UHF(sym_mol_r), scf.uhf_symm.UHF)) self.assertTrue(isinstance(scf.UHF(sym_mol_u), scf.uhf_symm.UHF)) self.assertTrue(isinstance(scf.UHF(sym_mol_r1), scf.uhf_symm.UHF)) self.assertTrue(isinstance(scf.ROHF(sym_mol_r), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.ROHF(sym_mol_u), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.ROHF(sym_mol_r1), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.HF(sym_mol_r), scf.hf_symm.RHF)) self.assertTrue(isinstance(scf.HF(sym_mol_u), scf.uhf_symm.UHF)) self.assertTrue(isinstance(scf.HF(sym_mol_r1), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.GHF(sym_mol_r), scf.ghf_symm.GHF)) self.assertTrue(isinstance(scf.GHF(sym_mol_u), scf.ghf_symm.GHF)) self.assertTrue(isinstance(scf.GHF(sym_mol_r1), scf.ghf_symm.GHF)) self.assertTrue(isinstance(scf.X2C(mol_r), x2c.x2c.UHF)) self.assertTrue(isinstance(scf.sfx2c1e(scf.HF(mol_r)), scf.rhf.RHF)) self.assertTrue(isinstance(scf.sfx2c1e(scf.HF(mol_u)), scf.uhf.UHF)) self.assertTrue(isinstance(scf.sfx2c1e(scf.HF(mol_r1)), scf.rohf.ROHF)) self.assertTrue( isinstance(scf.sfx2c1e(scf.HF(sym_mol_r)), scf.rhf_symm.RHF)) self.assertTrue( isinstance(scf.sfx2c1e(scf.HF(sym_mol_u)), scf.uhf_symm.UHF)) self.assertTrue( isinstance(scf.sfx2c1e(scf.HF(sym_mol_r1)), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.density_fit(scf.HF(mol_r)), scf.rhf.RHF)) self.assertTrue(isinstance(scf.density_fit(scf.HF(mol_u)), scf.uhf.UHF)) self.assertTrue( isinstance(scf.density_fit(scf.HF(mol_r1)), scf.rohf.ROHF)) self.assertTrue( isinstance(scf.density_fit(scf.HF(sym_mol_r)), scf.rhf_symm.RHF)) self.assertTrue( isinstance(scf.density_fit(scf.HF(sym_mol_u)), scf.uhf_symm.UHF)) self.assertTrue( isinstance(scf.density_fit(scf.HF(sym_mol_r1)), scf.hf_symm.ROHF)) self.assertTrue(isinstance(scf.newton(scf.HF(mol_r)), scf.rhf.RHF)) self.assertTrue(isinstance(scf.newton(scf.HF(mol_u)), scf.uhf.UHF)) self.assertTrue(isinstance(scf.newton(scf.HF(mol_r1)), scf.rohf.ROHF)) self.assertTrue( isinstance(scf.newton(scf.HF(sym_mol_r)), scf.rhf_symm.RHF)) self.assertTrue( isinstance(scf.newton(scf.HF(sym_mol_u)), scf.uhf_symm.UHF)) self.assertTrue( isinstance(scf.newton(scf.HF(sym_mol_r1)), scf.hf_symm.ROHF))
mol = gto.Mole() mol.atom = ''' O 0.00000000 0.00000000 -0.11081188 H -0.00000000 -0.84695236 0.59109389 H -0.00000000 0.89830571 0.52404783 ''' mol.basis = '3-21g' #cc-pvdz' mol.build() cm = DDCOSMO(mol) cm.verbose = 4 mf = ddcosmo_for_scf(scf.RHF(mol), cm)#.newton() mf.verbose = 4 print(mf.kernel() - -75.570364368059) cm.verbose = 3 e = ddcosmo_for_casci(mcscf.CASCI(mf, 4, 4)).kernel()[0] print(e - -75.5743583693215) cc_cosmo = ddcosmo_for_post_scf(cc.CCSD(mf)).run() print(cc_cosmo.e_tot - -75.70961637250134) mol = gto.Mole() mol.atom = ''' Fe 0.00000000 0.00000000 -0.11081188 H -0.00000000 -0.84695236 0.59109389 H -0.00000000 0.89830571 0.52404783 ''' mol.basis = '3-21g' #cc-pvdz' mol.build() cm = DDCOSMO(mol) cm.eps = -1 cm.verbose = 4 mf = ddcosmo_for_scf(scf.ROHF(mol), cm).newton() mf.verbose=4 mf.kernel()
#bohr = 0.529177249 N2sep = 1.09 O2sep = 1.21 mol = gto.Mole() mol.verbose = 1 mol.atom = 'O 0 0 0; O 0 0 ' + str(O2sep) mol.basis = 'sto-3g' mol.spin = 0 mol.build() Enuc = mol.energy_nuc() mf = scf.ROHF(mol) mf.kernel() print mf.e_tot h1 = mf.mo_coeff.T.dot(mf.get_hcore()).dot(mf.mo_coeff) eri = ao2mo.kernel(mol, mf.mo_coeff) cisolver = fci.FCI(mol, mf.mo_coeff) CSF = UGA.gen_CSF(0, 0, 10, [3, 3, 3, 3, 3, 3, 3, 1, 2, 0]) print(CSF) print(cisolver.energy(h1, eri, CSF, 10, (8, 8)) + Enuc) print(fci.spin_square(CSF, 10, (8, 8))) CSF = UGA.gen_CSF(0, 0, 10, [3, 3, 3, 3, 3, 3, 0, 3, 0, 0])
'''Non-relativistic ROHF gradients ''' def __init__(self, mf): uhf_grad.Gradients.__init__(self, addons.convert_to_uhf(mf)) Grad = Gradients if __name__ == '__main__': from pyscf import gto from pyscf import scf mol = gto.Mole() mol.atom = [['He', (0.,0.,0.)], ] mol.basis = {'He': 'ccpvdz'} mol.build() mf = scf.ROHF(mol) mf.scf() g = Gradients(mf) print(g.grad()) mol = gto.Mole() mol.atom = [ ['O' , (0. , 0. , 0.)], [1 , (0. , -0.757 , 0.587)], [1 , (0. , 0.757 , 0.587)] ] mol.basis = '631g' mol.build() rhf = scf.ROHF(mol) rhf.conv_tol = 1e-14 e0 = rhf.scf() g = Gradients(rhf)
def _calculate_integrals(mol, hf_method="rhf", conv_tol=1e-9, max_cycle=50, init_guess="minao"): """Function to calculate the one and two electron terms. Perform a Hartree-Fock calculation in the given basis. Args: mol (gto.Mole) : A PySCF gto.Mole object. hf_method (str): rhf, uhf, rohf conv_tol (float): Convergence tolerance max_cycle (int): Max convergence cycles init_guess (str): Initial guess for SCF Returns: QMolecule: QMolecule populated with driver integrals etc Raises: QiskitNatureError: Invalid hf method type """ enuke = gto.mole.energy_nuc(mol) if hf_method == "rhf": m_f = scf.RHF(mol) elif hf_method == "rohf": m_f = scf.ROHF(mol) elif hf_method == "uhf": m_f = scf.UHF(mol) else: raise QiskitNatureError("Invalid hf_method type: {}".format(hf_method)) m_f.conv_tol = conv_tol m_f.max_cycle = max_cycle m_f.init_guess = init_guess ehf = m_f.kernel() logger.info("PySCF kernel() converged: %s, e(hf): %s", m_f.converged, m_f.e_tot) if isinstance(m_f.mo_coeff, tuple): mo_coeff = m_f.mo_coeff[0] mo_coeff_b = m_f.mo_coeff[1] mo_occ = m_f.mo_occ[0] mo_occ_b = m_f.mo_occ[1] else: # With PySCF 1.6.2, instead of a tuple of 2 dimensional arrays, its a 3 dimensional # array with the first dimension indexing to the coeff arrays for alpha and beta if len(m_f.mo_coeff.shape) > 2: mo_coeff = m_f.mo_coeff[0] mo_coeff_b = m_f.mo_coeff[1] mo_occ = m_f.mo_occ[0] mo_occ_b = m_f.mo_occ[1] else: mo_coeff = m_f.mo_coeff mo_coeff_b = None mo_occ = m_f.mo_occ mo_occ_b = None norbs = mo_coeff.shape[0] if isinstance(m_f.mo_energy, tuple): orbs_energy = m_f.mo_energy[0] orbs_energy_b = m_f.mo_energy[1] else: # See PYSCF 1.6.2 comment above - this was similarly changed if len(m_f.mo_energy.shape) > 1: orbs_energy = m_f.mo_energy[0] orbs_energy_b = m_f.mo_energy[1] else: orbs_energy = m_f.mo_energy orbs_energy_b = None if logger.isEnabledFor(logging.DEBUG): # Add some more to PySCF output... # First analyze() which prints extra information about MO energy and occupation mol.stdout.write("\n") m_f.analyze() # Now labelled orbitals for contributions to the MOs for s,p,d etc of each atom mol.stdout.write("\n\n--- Alpha Molecular Orbitals ---\n\n") dump_mat.dump_mo(mol, mo_coeff, digits=7, start=1) if mo_coeff_b is not None: mol.stdout.write("\n--- Beta Molecular Orbitals ---\n\n") dump_mat.dump_mo(mol, mo_coeff_b, digits=7, start=1) mol.stdout.flush() hij = m_f.get_hcore() mohij = np.dot(np.dot(mo_coeff.T, hij), mo_coeff) mohij_b = None if mo_coeff_b is not None: mohij_b = np.dot(np.dot(mo_coeff_b.T, hij), mo_coeff_b) eri = mol.intor("int2e", aosym=1) mo_eri = ao2mo.incore.full(m_f._eri, mo_coeff, compact=False) mohijkl = mo_eri.reshape(norbs, norbs, norbs, norbs) mohijkl_bb = None mohijkl_ba = None if mo_coeff_b is not None: mo_eri_b = ao2mo.incore.full(m_f._eri, mo_coeff_b, compact=False) mohijkl_bb = mo_eri_b.reshape(norbs, norbs, norbs, norbs) mo_eri_ba = ao2mo.incore.general( m_f._eri, (mo_coeff_b, mo_coeff_b, mo_coeff, mo_coeff), compact=False ) mohijkl_ba = mo_eri_ba.reshape(norbs, norbs, norbs, norbs) # dipole integrals mol.set_common_orig((0, 0, 0)) ao_dip = mol.intor_symmetric("int1e_r", comp=3) x_dip_ints = ao_dip[0] y_dip_ints = ao_dip[1] z_dip_ints = ao_dip[2] d_m = m_f.make_rdm1(m_f.mo_coeff, m_f.mo_occ) if not (isinstance(d_m, np.ndarray) and d_m.ndim == 2): d_m = d_m[0] + d_m[1] elec_dip = np.negative(np.einsum("xij,ji->x", ao_dip, d_m).real) elec_dip = np.round(elec_dip, decimals=8) nucl_dip = np.einsum("i,ix->x", mol.atom_charges(), mol.atom_coords()) nucl_dip = np.round(nucl_dip, decimals=8) logger.info("HF Electronic dipole moment: %s", elec_dip) logger.info("Nuclear dipole moment: %s", nucl_dip) logger.info("Total dipole moment: %s", nucl_dip + elec_dip) # Create driver level molecule object and populate _q_ = QMolecule() _q_.origin_driver_version = pyscf_version # Energies and orbits _q_.hf_energy = ehf _q_.nuclear_repulsion_energy = enuke _q_.num_molecular_orbitals = norbs _q_.num_alpha = mol.nelec[0] _q_.num_beta = mol.nelec[1] _q_.mo_coeff = mo_coeff _q_.mo_coeff_b = mo_coeff_b _q_.orbital_energies = orbs_energy _q_.orbital_energies_b = orbs_energy_b _q_.mo_occ = mo_occ _q_.mo_occ_b = mo_occ_b # Molecule geometry _q_.molecular_charge = mol.charge _q_.multiplicity = mol.spin + 1 _q_.num_atoms = mol.natm _q_.atom_symbol = [] _q_.atom_xyz = np.empty([mol.natm, 3]) _ = mol.atom_coords() for n_i in range(0, _q_.num_atoms): xyz = mol.atom_coord(n_i) _q_.atom_symbol.append(mol.atom_pure_symbol(n_i)) _q_.atom_xyz[n_i][0] = xyz[0] _q_.atom_xyz[n_i][1] = xyz[1] _q_.atom_xyz[n_i][2] = xyz[2] # 1 and 2 electron integrals AO and MO _q_.hcore = hij _q_.hcore_b = None _q_.kinetic = mol.intor_symmetric("int1e_kin") _q_.overlap = m_f.get_ovlp() _q_.eri = eri _q_.mo_onee_ints = mohij _q_.mo_onee_ints_b = mohij_b _q_.mo_eri_ints = mohijkl _q_.mo_eri_ints_bb = mohijkl_bb _q_.mo_eri_ints_ba = mohijkl_ba # dipole integrals AO and MO _q_.x_dip_ints = x_dip_ints _q_.y_dip_ints = y_dip_ints _q_.z_dip_ints = z_dip_ints _q_.x_dip_mo_ints = QMolecule.oneeints2mo(x_dip_ints, mo_coeff) _q_.x_dip_mo_ints_b = None _q_.y_dip_mo_ints = QMolecule.oneeints2mo(y_dip_ints, mo_coeff) _q_.y_dip_mo_ints_b = None _q_.z_dip_mo_ints = QMolecule.oneeints2mo(z_dip_ints, mo_coeff) _q_.z_dip_mo_ints_b = None if mo_coeff_b is not None: _q_.x_dip_mo_ints_b = QMolecule.oneeints2mo(x_dip_ints, mo_coeff_b) _q_.y_dip_mo_ints_b = QMolecule.oneeints2mo(y_dip_ints, mo_coeff_b) _q_.z_dip_mo_ints_b = QMolecule.oneeints2mo(z_dip_ints, mo_coeff_b) # dipole moment _q_.nuclear_dipole_moment = nucl_dip _q_.reverse_dipole_sign = True return _q_
def _calculate_integrals(mol, hf_method='rhf', conv_tol=1e-9, max_cycle=50, init_guess='minao',outfile=None): """Function to calculate the one and two electron terms. Perform a Hartree-Fock calculation in the given basis. Args: mol (gto.Mole) : A PySCF gto.Mole object. hf_method (str): rhf, uhf, rohf conv_tol (float): Convergence tolerance max_cycle (int): Max convergence cycles init_guess (str): Initial guess for SCF Returns: QMolecule: QMolecule populated with driver integrals etc Raises: QiskitChemistryError: Invalid hf method type """ enuke = gto.mole.energy_nuc(mol) if hf_method == 'rhf': m_f = scf.RHF(mol) elif hf_method == 'rohf': m_f = scf.ROHF(mol) elif hf_method == 'uhf': m_f = scf.UHF(mol) else: raise QiskitChemistryError('Invalid hf_method type: {}'.format(hf_method)) m_f.conv_tol = conv_tol m_f.max_cycle = max_cycle m_f.init_guess = init_guess ehf = m_f.kernel() from pyscf import tools from prettytable import PrettyTable C = m_f.mo_coeff irr = get_irreps(mol,C) table_ancillary_info = [[str(round(m_f.mo_energy[i],4)),irr[i],str(int(m_f.mo_occ[i]))] for i in range(mol.nao_nr())] outfile.write("SCF orbitals\n") t = PrettyTable(['MO']+mol.ao_labels()+['E','irr','occ']) for i in range(C.shape[1]): if(C[np.argmax(np.abs(C[:,i])),i]<0): C[:,i] *= -1 t.add_row([str(i)]+[str(round(x,4)) for x in C[:,i]]+table_ancillary_info[i]) outfile.write(str(t)) filename = 'mos' for i in range(m_f.mo_coeff.shape[1]): moldenfile = filename+'-'+str(i)+'.molden' tools.molden.from_mo(mol,moldenfile,m_f.mo_coeff) jmol_script = filename+'-'+str(i)+'.spt' fspt = open(jmol_script,'w') fspt.write(''' initialize; set background [xffffff]; set frank off set autoBond true; set bondRadiusMilliAngstroms 66; set bondTolerance 0.5; set forceAutoBond false; load %s ''' % moldenfile) fspt.write(''' zoom 130; rotate -20 z rotate -60 x axes MO COLOR [xff0020] [x0060ff]; MO COLOR translucent 0.25; MO fill noDots noMesh; MO titleformat ""; ''') fspt.write('MO %d cutoff 0.02;\n' % (i+1)) fspt.write('write IMAGE 400 400 PNG 180 "%s-%02d.png";\n' % (filename,i+1)) fspt.close() logger.info('PySCF kernel() converged: %s, e(hf): %s', m_f.converged, m_f.e_tot) if isinstance(m_f.mo_coeff, tuple): mo_coeff = m_f.mo_coeff[0] mo_coeff_b = m_f.mo_coeff[1] # mo_occ = m_f.mo_occ[0] # mo_occ_b = m_f.mo_occ[1] else: # With PySCF 1.6.2, instead of a tuple of 2 dimensional arrays, its a 3 dimensional # array with the first dimension indexing to the coeff arrays for alpha and beta if len(m_f.mo_coeff.shape) > 2: mo_coeff = m_f.mo_coeff[0] mo_coeff_b = m_f.mo_coeff[1] # mo_occ = m_f.mo_occ[0] # mo_occ_b = m_f.mo_occ[1] else: mo_coeff = m_f.mo_coeff mo_coeff_b = None # mo_occ = mf.mo_occ # mo_occ_b = None norbs = mo_coeff.shape[0] if isinstance(m_f.mo_energy, tuple): orbs_energy = m_f.mo_energy[0] orbs_energy_b = m_f.mo_energy[1] else: # See PYSCF 1.6.2 comment above - this was similarly changed if len(m_f.mo_energy.shape) > 1: orbs_energy = m_f.mo_energy[0] orbs_energy_b = m_f.mo_energy[1] else: orbs_energy = m_f.mo_energy orbs_energy_b = None if logger.isEnabledFor(logging.DEBUG): # Add some more to PySCF output... # First analyze() which prints extra information about MO energy and occupation mol.stdout.write('\n') m_f.analyze() # Now labelled orbitals for contributions to the MOs for s,p,d etc of each atom mol.stdout.write('\n\n--- Alpha Molecular Orbitals ---\n\n') dump_mat.dump_mo(mol, mo_coeff, digits=7, start=1) if mo_coeff_b is not None: mol.stdout.write('\n--- Beta Molecular Orbitals ---\n\n') dump_mat.dump_mo(mol, mo_coeff_b, digits=7, start=1) mol.stdout.flush() hij = m_f.get_hcore() mohij = np.dot(np.dot(mo_coeff.T, hij), mo_coeff) mohij_b = None if mo_coeff_b is not None: mohij_b = np.dot(np.dot(mo_coeff_b.T, hij), mo_coeff_b) eri = mol.intor('int2e', aosym=1) mo_eri = ao2mo.incore.full(m_f._eri, mo_coeff, compact=False) mohijkl = mo_eri.reshape(norbs, norbs, norbs, norbs) mohijkl_bb = None mohijkl_ba = None if mo_coeff_b is not None: mo_eri_b = ao2mo.incore.full(m_f._eri, mo_coeff_b, compact=False) mohijkl_bb = mo_eri_b.reshape(norbs, norbs, norbs, norbs) mo_eri_ba = ao2mo.incore.general(m_f._eri, (mo_coeff_b, mo_coeff_b, mo_coeff, mo_coeff), compact=False) mohijkl_ba = mo_eri_ba.reshape(norbs, norbs, norbs, norbs) # dipole integrals mol.set_common_orig((0, 0, 0)) ao_dip = mol.intor_symmetric('int1e_r', comp=3) x_dip_ints = ao_dip[0] y_dip_ints = ao_dip[1] z_dip_ints = ao_dip[2] d_m = m_f.make_rdm1(m_f.mo_coeff, m_f.mo_occ) if hf_method in ('rohf', 'uhf'): d_m = d_m[0] elec_dip = np.negative(np.einsum('xij,ji->x', ao_dip, d_m).real) elec_dip = np.round(elec_dip, decimals=8) nucl_dip = np.einsum('i,ix->x', mol.atom_charges(), mol.atom_coords()) nucl_dip = np.round(nucl_dip, decimals=8) logger.info("HF Electronic dipole moment: %s", elec_dip) logger.info("Nuclear dipole moment: %s", nucl_dip) logger.info("Total dipole moment: %s", nucl_dip+elec_dip) # Create driver level molecule object and populate _q_ = QMolecule() _q_.origin_driver_version = pyscf_version # Energies and orbits _q_.hf_energy = ehf _q_.nuclear_repulsion_energy = enuke _q_.num_orbitals = norbs _q_.num_alpha = mol.nelec[0] _q_.num_beta = mol.nelec[1] _q_.mo_coeff = mo_coeff _q_.mo_coeff_b = mo_coeff_b _q_.orbital_energies = orbs_energy _q_.orbital_energies_b = orbs_energy_b # Molecule geometry _q_.molecular_charge = mol.charge _q_.multiplicity = mol.spin + 1 _q_.num_atoms = mol.natm _q_.atom_symbol = [] _q_.atom_xyz = np.empty([mol.natm, 3]) _ = mol.atom_coords() for n_i in range(0, _q_.num_atoms): xyz = mol.atom_coord(n_i) _q_.atom_symbol.append(mol.atom_pure_symbol(n_i)) _q_.atom_xyz[n_i][0] = xyz[0] _q_.atom_xyz[n_i][1] = xyz[1] _q_.atom_xyz[n_i][2] = xyz[2] # 1 and 2 electron integrals AO and MO _q_.hcore = hij _q_.hcore_b = None _q_.kinetic = mol.intor_symmetric('int1e_kin') _q_.overlap = m_f.get_ovlp() _q_.eri = eri _q_.mo_onee_ints = mohij _q_.mo_onee_ints_b = mohij_b _q_.mo_eri_ints = mohijkl _q_.mo_eri_ints_bb = mohijkl_bb _q_.mo_eri_ints_ba = mohijkl_ba # dipole integrals AO and MO _q_.x_dip_ints = x_dip_ints _q_.y_dip_ints = y_dip_ints _q_.z_dip_ints = z_dip_ints _q_.x_dip_mo_ints = QMolecule.oneeints2mo(x_dip_ints, mo_coeff) _q_.x_dip_mo_ints_b = None _q_.y_dip_mo_ints = QMolecule.oneeints2mo(y_dip_ints, mo_coeff) _q_.y_dip_mo_ints_b = None _q_.z_dip_mo_ints = QMolecule.oneeints2mo(z_dip_ints, mo_coeff) _q_.z_dip_mo_ints_b = None if mo_coeff_b is not None: _q_.x_dip_mo_ints_b = QMolecule.oneeints2mo(x_dip_ints, mo_coeff_b) _q_.y_dip_mo_ints_b = QMolecule.oneeints2mo(y_dip_ints, mo_coeff_b) _q_.z_dip_mo_ints_b = QMolecule.oneeints2mo(z_dip_ints, mo_coeff_b) # dipole moment _q_.nuclear_dipole_moment = nucl_dip _q_.reverse_dipole_sign = True return _q_
# # Setup and run HCISCF # mol = gto.M( atom=""" C 0.0000 0.0000 0.0000 H -0.9869 0.3895 0.2153 H 0.8191 0.6798 -0.1969 H 0.1676 -1.0693 -0.0190 """, spin=1, ) ncas, nelecas = (7, 7) mf = scf.ROHF(mol).run() mc = shci.SHCISCF(mf, ncas, nelecas) mc.kernel() # # Get our spin 1-RDMs # dm1 = mc.fcisolver.make_rdm1(0, ncas, nelecas) dm_ab = mc.fcisolver.make_rdm1s() # in MOs dm1_check = np.linalg.norm(dm1 - np.sum(dm_ab, axis=0)) print(f"RDM1 Check = {dm1_check}\n") # # Use UHF tools for Spin Density Analysis #
def test_rohf_dip_moment(self): mf = scf.ROHF(mol).run() dip = mf.dip_moment(unit='au') self.assertTrue(numpy.allclose(dip, [0.00000, 0.00000, 0.80985]))
def test_nr_rohf(self): mf = scf.ROHF(h2o_n) mf.conv_tol = 1e-14 mf.kernel() g = grad.ROHF(mf) self.assertAlmostEqual(lib.finger(g.grad_elec()), 4.1499791106739679, 6)
def overwrite_molecule(filename, m): import numpy as np from pyscf import scf, gto, ao2mo, cc #============================================# # input file, must contain # # nbasis,nup,ndown # # E0 # # i,j,h[i,j] # # p,r,q,s h[p,r,q,s] in Chemist's notation # # in an orthonormal basis # #============================================# linf = open(filename, 'r').read().split('\n') linf = [x.split(',') for x in linf] n, na, nb = linf[0] Enuc = linf[1][0] n, na, nb = int(n), int(na), int(nb) Enuc = float(Enuc) s1 = np.zeros((n, n)) h1 = np.zeros((n, n)) h2 = np.zeros((n, n, n, n)) count = 2 for mu in range(n**2): II, JJ = linf[count][0], linf[count][1] II, JJ = int(II), int(JJ) hij = linf[count][2] hij = float(hij) if (II == JJ): s1[II, JJ] = 1 else: s1[II, JJ] = 0 h1[II, JJ] = hij count += 1 for mu in range(n**4): PP, RR, QQ, SS = linf[count][0], linf[count][1], linf[count][2], linf[ count][3] PP, RR, QQ, SS = int(PP), int(RR), int(QQ), int(SS) vprqs = linf[count][4] vprqs = float(vprqs) h2[PP, RR, QQ, SS] = vprqs count += 1 mol = gto.M(verbose=2) mol.charge = 0 mol.nelectron = na + nb mol.spin = na - nb mol.incore_anyway = True if (mol.spin == 0): mf = scf.RHF(mol) if (mol.spin == 1): mf = scf.ROHF(mol) mf.get_hcore = lambda *args: h1 mf.get_ovlp = lambda *args: s1 mf._eri = ao2mo.restore(8, h2, n) mf.init_guess = '1e' E0 = mf.kernel() if (not mf.converged): mf = scf.newton(mf) E0 = mf.kernel() if (n < 11): from pyscf import mcscf mycas = mcscf.CASSCF(mf, ncas=n, nelecas=mol.nelectron) E1 = mycas.kernel()[0] print("PySCF energies: SCF, FCI %f %f \n " % (E0 + Enuc, E1 + Enuc)) else: print("PySCF energy: SCF %f " % (E0 + Enuc)) m.origin_driver_name = 'user-defined' m.origin_driver_version = None m.origin_driver_config = None m.hf_energy = E0 + Enuc m.nuclear_repulsion_energy = Enuc m.num_orbitals = n m.num_alpha = na m.num_beta = nb m.mo_coeff = mf.mo_coeff m.mo_coeff_B = None m.orbital_energies = mf.mo_energy m.orbital_energies_B = None m.molecular_charge = None m.multiplicity = None m.num_atoms = None m.atom_symbol = None m.atom_xyz = None m.hcore = h1 m.hcore_B = None m.kinetic = np.zeros((n, n)) m.overlap = np.eye(n) m.eri = h2 m.mo_onee_ints = h1 m.mo_onee_ints_B = None m.mo_eri_ints = h2 m.mo_eri_ints_BB = None m.mo_eri_ints_BA = None m.mo_onee_ints = np.einsum('pi,pr->ir', m.mo_coeff, m.mo_onee_ints) m.mo_onee_ints = np.einsum('ra,ir->ia', m.mo_coeff, m.mo_onee_ints) m.mo_eri_ints = np.einsum('pi,prqs->irqs', m.mo_coeff, m.mo_eri_ints) m.mo_eri_ints = np.einsum('ra,irqs->iaqs', m.mo_coeff, m.mo_eri_ints) m.mo_eri_ints = np.einsum('qj,iaqs->iajs', m.mo_coeff, m.mo_eri_ints) m.mo_eri_ints = np.einsum('sb,iajs->iajb', m.mo_coeff, m.mo_eri_ints) m.x_dip_ints = None m.y_dip_ints = None m.z_dip_ints = None m.x_dip_mo_ints = None m.x_dip_mo_ints_B = None m.y_dip_mo_ints = None m.y_dip_mo_ints_B = None m.z_dip_mo_ints = None m.z_dip_mo_ints_B = None m.nuclear_dipole_moment = None m.reverse_dipole_sign = None
C -0.713500 -0.982049 1.648000 C -1.154467 0.375109 1.648000 C -0.000000 1.213879 1.648000 C 1.154467 0.375109 1.648000 C 0.713500 -0.982049 1.648000 H -1.347694 -1.854942 1.638208 H -2.180615 0.708525 1.638208 H 0.000000 2.292835 1.638208 H 2.180615 0.708525 1.638208 H 1.347694 -1.854942 1.638208 ''' mol.basis = 'cc-pvtz-dk' mol.spin = 0 mol.build() mf = scf.sfx2c1e(scf.ROHF(mol)) mf.kernel() # # The active space can be generated by pyscf.mcscf.avas.avas function # from pyscf.mcscf import avas norb, ne_act, orbs = avas.avas(mf, ['Fe 3d', 'C 2pz'], canonicalize=False) # # The followings are the step-by-step solution to construct the active space # based on the formulas provided by the paper. # #====================================================================