def test_mo_cube_libnao(self): """ Computing of the atomic orbitals """ sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__))) cc = Cube(sv, nx=40, ny=40, nz=40) co2val = sv.comp_aos_den(cc.get_coords()) nocc_0t = int(sv.nelectron / 2) c2orb = np.dot(co2val, sv.wfsx.x[0,0,nocc_0t,:,0]).reshape((cc.nx, cc.ny, cc.nz)) cc.write(c2orb, "water_mo.cube", comment='H**O')
def MO(mol, C, orbital, outfile='orbital', nx=80, ny=80, nz=80, resolution=None, save=True): """Calculates electron density and write out in cube format. Args: mol : Mole Molecule to calculate the electron density for. outfile : str Name of Cube file to be written. dm : ndarray Density matrix of molecule. Kwargs: nx : int Number of grid point divisions in x direction. Note this is function of the molecule's size; a larger molecule will have a coarser representation than a smaller one for the same value. Conflicts to keyword resolution. ny : int Number of grid point divisions in y direction. nz : int Number of grid point divisions in z direction. resolution: float Resolution of the mesh grid in the cube box. If resolution is given in the input, the input nx/ny/nz have no effects. The value of nx/ny/nz will be determined by the resolution and the cube box size. """ cc = Cube(mol, nx, ny, nz, resolution) # Compute density on the .cube grid coords = cc.get_coords() ngrids = cc.get_ngrids() #blksize = min(8000, ngrids) blksize = ngrids rho = np.empty(ngrids) for ip0, ip1 in lib.prange(0, ngrids, blksize): ao = numint.eval_ao(mol, coords[ip0:ip1]) MO = np.array([i @ C[:, orbital] for i in ao]) MO = MO.reshape((nx, ny, nz)) if save: cc.write(MO, outfile, comment='Orbital ' + str(orbital) + ' in real space (e/Bohr^3)') x = (coords[:, 0].min(), coords[:, 0].max(), nx) y = (coords[:, 1].min(), coords[:, 1].max(), ny) z = (coords[:, 2].min(), coords[:, 2].max(), nz) return MO, np.array([y, x, z])
def test_mo_cube_libnao(self): """ Computing of the atomic orbitals """ sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__))) cc = Cube(sv, nx=40, ny=40, nz=40) co2val = sv.comp_aos_den(cc.get_coords()) nocc_0t = int(sv.nelectron / 2) c2orb = np.dot(co2val, sv.wfsx.x[0, 0, nocc_0t, :, 0]).reshape( (cc.nx, cc.ny, cc.nz)) cc.write(c2orb, "water_mo.cube", comment='H**O')
def test_mo_cube_libnao(self): """ Computing of the atomic orbitals """ from pyscf.nao import system_vars_c from pyscf.tools.cubegen import Cube sv = system_vars_c().init_siesta_xml(label='water', cd=os.path.dirname(os.path.abspath(__file__))) cc = Cube(sv, nx=40, ny=40, nz=40) co2val = sv.comp_aos_den(cc.get_coords()) nocc_0t = int(sv.nelectron / 2) c2orb = np.dot(co2val, sv.wfsx.x[0,0,nocc_0t,:,0]).reshape((cc.nx, cc.ny, cc.nz)) cc.write(c2orb, "water_mo.cube", comment='H**O')
def test_cube_sv(self): """ Compute the density and store into a cube file """ from pyscf.tools.cubegen import Cube sv = nao_mf(label='water', cd=os.path.dirname(os.path.abspath(__file__))) cc = Cube(sv, nx=50, ny=50, nz=50) dens = sv.dens_elec(cc.get_coords(), sv.make_rdm1()) dens = dens[:,0].reshape(cc.nx,cc.ny,cc.nz) cc.write(dens, "water.cube", comment='Valence electron density in real space (e/Bohr^3)') self.assertEqual(len(cc.xs), cc.nx) self.assertEqual(len(cc.ys), cc.ny) self.assertEqual(len(cc.zs), cc.nz) self.assertAlmostEqual(dens.sum()*cc.get_volume_element(), 8.0, 1)
def test_cube_c(self): """ Compute the density and store into a cube file """ # Initialize the class cube_c cc = Cube(mol, nx=20, ny=20, nz=20) # Compute density on the .cube grid coords = cc.get_coords() ngrids = cc.get_ngrids() blksize = min(8000, ngrids) rho = np.empty(ngrids) ao = None dm = mf.make_rdm1() for ip0, ip1 in gen_grid.prange(0, ngrids, blksize): ao = numint.eval_ao(mol, coords[ip0:ip1], out=ao) rho[ip0:ip1] = numint.eval_rho(mol, ao, dm) rho = rho.reshape(cc.nx,cc.ny,cc.nz) # Write out density to the .cube file cc.write(rho, "h2o_den_cube_c.cube", comment='Electron density in real space (e/Bohr^3)')