def test_mep(self): ftmp = tempfile.NamedTemporaryFile() mep = cubegen.mep(mol, ftmp.name, mf.make_rdm1(), nx=10, ny=10, nz=10) self.assertEqual(mep.shape, (10, 10, 10)) self.assertAlmostEqual(lib.finger(mep), -0.3198103636180436, 9) mep = cubegen.mep(mol, ftmp.name, mf.make_rdm1(), nx=10, ny=10, nz=10, resolution=0.5) self.assertEqual(mep.shape, (12, 18, 15)) self.assertAlmostEqual(lib.finger(mep), -4.653995909548524, 9)
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])
def get_esp_cube(mol, mf, cube_fn="esp.cub"): cubegen.mep(mol, cube_fn, mf.make_rdm1())
def test_cubegen(self): """ Compute the density and store into a cube file """ cubegen.density(mol, 'h2o_den.cube', mf.make_rdm1(), nx=20, ny=20, nz=20) cubegen.mep(mol, 'h2o_pot.cube', mf.make_rdm1(), nx=20, ny=20, nz=20) #slow
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])