def test_orb(self): ftmp = tempfile.NamedTemporaryFile() orb = cubegen.orbital(mol, ftmp.name, mf.mo_coeff[:, 0], nx=10, ny=10, nz=10) self.assertEqual(orb.shape, (10, 10, 10)) self.assertAlmostEqual(lib.finger(orb), -0.11804191128016768, 9) orb = cubegen.orbital(mol, ftmp.name, mf.mo_coeff[:, 0], nx=10, ny=10, nz=10, resolution=0.5) self.assertEqual(orb.shape, (12, 18, 15)) self.assertAlmostEqual(lib.finger(orb), -0.8591778390706646, 9) orb = cubegen.orbital(mol, ftmp.name, mf.mo_coeff[:, 0], nx=10, ny=1, nz=1) self.assertEqual(orb.shape, (10, 1, 1)) self.assertAlmostEqual(lib.finger(orb), 6.921008881822988e-09, 9)
def write_cube(mf, p): ''' write the localized orbitals as cube files ''' l_cube = [] # list of all cube file names for s in range(p.nspin): s_cube = [] occ = len(mf.mo_coeff[s][mf.mo_occ[s] == 1]) for i in range(occ): f_cube = '{}_orb_{}_spin{}.cube'.format(p.pycom_loc, i, s) s_cube.append(f_cube) orbital(mf.mol, f_cube, p.pycom_orb[s][:, i], nx=p.nx, ny=p.ny, nz=p.nz) l_cube.append(s_cube) p.l_cube = l_cube return p
def parse_nx(data): d = data.split() return int(d[0]), numpy.array([float(x) for x in d[1:]]) self.nx, self.xs = parse_nx(f.readline()) self.ny, self.ys = parse_nx(f.readline()) self.nz, self.zs = parse_nx(f.readline()) atoms = [] for ia in range(natm): d = f.readline().split() atoms.append([int(d[0]), [float(x) for x in d[2:]]]) self.mol = gto.M(atom=atoms, unit='Bohr') data = f.read() cube_data = numpy.array([float(x) for x in data.split()]) return cube_data.reshape([self.nx, self.ny, self.nz]) if __name__ == '__main__': from pyscf import gto, scf from pyscf.tools import cubegen mol = gto.M(atom='''O 0.00000000, 0.000000, 0.000000 H 0.761561, 0.478993, 0.00000000 H -0.761561, 0.478993, 0.00000000''', basis='6-31g*') mf = scf.RHF(mol).run() cubegen.density(mol, 'h2o_den.cube', mf.make_rdm1()) #makes total density cubegen.mep(mol, 'h2o_pot.cube', mf.make_rdm1()) cubegen.orbital(mol, 'h2o_mo1.cube', mf.mo_coeff[:, 0])
Write orbitals, electron density, molecular electrostatic potential in Gaussian cube file format. ''' from pyscf import gto, scf from pyscf.tools import cubegen mol = gto.M(atom=''' O 0.0000000, 0.000000, 0.00000000 H 0.761561 , 0.478993, 0.00000000 H -0.761561, 0.478993, 0.00000000''', basis='6-31g*') mf = scf.RHF(mol).run() # electron density cubegen.density(mol, 'h2o_den.cube', mf.make_rdm1()) # electron density slice cubegen.density(mol, 'h2o_den_slice.cube', mf.make_rdm1(), nx=1, ny=1, nz=80) # molecular electrostatic potential cubegen.mep(mol, 'h2o_pot.cube', mf.make_rdm1()) # molecular electrostatic potential slice cubegen.mep(mol, 'h2o_pot_slice.cube', mf.make_rdm1(), nx=1, ny=1, nz=80) # 1st MO cubegen.orbital(mol, 'h2o_mo1.cube', mf.mo_coeff[:,0]) # 1st MO orbital slice cubegen.orbital(mol, 'h2o_mo1_slice.cube', mf.mo_coeff[:,0], nx=1, ny=1, nz=80)
f.write('%12.6f%12.6f%12.6f\n' % tuple(self.boxorig.tolist())) f.write('%5d%12.6f%12.6f%12.6f\n' % (self.nx, self.xs[1], 0, 0)) f.write('%5d%12.6f%12.6f%12.6f\n' % (self.ny, 0, self.ys[1], 0)) f.write('%5d%12.6f%12.6f%12.6f\n' % (self.nz, 0, 0, self.zs[1])) for ia in range(mol.natm): chg = mol.atom_charge(ia) f.write('%5d%12.6f'% (chg, chg)) f.write('%12.6f%12.6f%12.6f\n' % tuple(coord[ia])) for ix in range(self.nx): for iy in range(self.ny): for iz0, iz1 in lib.prange(0, self.nz, 6): fmt = '%13.5E' * (iz1-iz0) + '\n' f.write(fmt % tuple(field[ix,iy,iz0:iz1].tolist())) def read(self, cube_file): raise NotImplementedError if __name__ == '__main__': from pyscf import gto, scf from pyscf.tools import cubegen mol = gto.M(atom='''O 0.00000000, 0.000000, 0.000000 H 0.761561, 0.478993, 0.00000000 H -0.761561, 0.478993, 0.00000000''', basis='6-31g*') mf = scf.RHF(mol).run() cubegen.density(mol, 'h2o_den.cube', mf.make_rdm1()) #makes total density cubegen.mep(mol, 'h2o_pot.cube', mf.make_rdm1()) cubegen.orbital(mol, 'h2o_mo1.cube', mf.mo_coeff[:,0])
ptss_list.append(ptss) fmt = "{0:2d} {1:12.8g} {2:9.3g} [{3:9.3g}, {4:9.3g}, {5:9.3g}]" fmt += " [{6:9.3g}, {7:9.3g}, {8:9.3g}]" fmt += " {9:12.8g} {10:12.8g}" print( state.kind[0], fmt.format(i, val, state.oscillator_strengths[i], *state.transition_dipole_moments[i], *state.state_dipole_moments[i], ptss, ptlr), ) # Dump LUNTO and HONTO u, s, v = np.linalg.svd(ρ_tdm_tot) # LUNTOs cubegen.orbital(mol=mol, coeff=u.T[0], outfile="nto_{}_LUNTO.cube".format(i)) # HONTOs cubegen.orbital(mol=mol, coeff=v[0], outfile="nto_{}_HONTO.cube".format(i)) # Print timings summary: print() print(state.timer.describe()) print("Number of orbitals:", state.reference_state.n_orbs) results = { "excitation_energies": state.excitation_energies.tolist(), "oscillator_strengths": state.oscillator_strengths.tolist(), "ptss": ptss_list, "ptlr": ptlr_list, }
Test pyscf dft calculations @author: Bing Gu """ from pyscf import gto, dft from pyscf.tools import cubegen import numpy as np from pprint import pprint #p 6-31g(d) 5d ub3lyp tda(nstates=60,full,alltransitiondensities) mol = gto.M(atom=''' H 0 0 0.00000000 H 0.00000000 -0.00000000 0.74 ''', basis='321g', charge=0, spin=0) mf = dft.RKS(mol) mf.xc = 'B3LYP' mf.kernel() # save mo coeffcients np.save('mo_coeff', mf.mo_coeff) j = 1 cubegen.orbital(mol, 'mo' + str(j) + '.cube', mf.mo_coeff[:, j])
from pyscf.tools import cubegen from pyscf.data.nist import BOHR import numpy as np ang2bohr = 1.0 / BOHR mol = gto.M(atom=''' O 0.0000000000000000 0.0000000000000000 0.000 H -0.26312631683261728 0.92177640310981912 0.000 H 0.9645910938303689 4.0006988432649347E-002 0.000 ''', basis='aug-cc-pVDZ') mm_crd = np.array( [[2.9125407227330018, 0.0000000000000000, 0.000], [3.3354011353264896, -0.41314678971687741, -0.75710308103585677], [3.3354011558614673, -0.41314667699843621, 0.75710313896414105]]) mm_crd *= ang2bohr mm_chgs = np.array([-0.68, 0.34, 0.34]) mf = qmmm.mm_charge(scf.RHF(mol), mm_crd, mm_chgs).run() # electron density cubegen.density(mol, 'h2o_den_qmmm.cube', mf.make_rdm1()) # molecular electrostatic potential cubegen.mep(mol, 'h2o_pot_qmmm.cube', mf.make_rdm1()) # 1st MO nhomo = mf.mol.nelec[0] cubegen.orbital(mol, 'h2o_homo_qmmm.cube', mf.mo_coeff[:, nhomo - 1])