def int_beta(self): logger.info(self, '* Go with inside betasphere') xcoor = numpy.zeros(3) coords = numpy.empty((self.bnpang, 3)) nrad = self.bnrad iqudr = self.biqudr mapr = self.bmapr r0 = 0 rfar = self.brad rad = self.rad t0 = time.clock() rmesh, rwei, dvol, dvoln = grids.rquad(nrad, r0, rfar, rad, iqudr, mapr) coordsang = grids.lebgrid(self.bnpang) rprops = 0.0 for n in range(nrad): r = rmesh[n] for j in range(self.bnpang): # j-loop can be changed to map cost = coordsang[j, 0] sintcosp = coordsang[j, 1] * coordsang[j, 2] sintsinp = coordsang[j, 1] * coordsang[j, 3] xcoor[0] = r * sintcosp xcoor[1] = r * sintsinp xcoor[2] = r * cost p = self.xnuc + xcoor coords[j] = p val = numint.eval_rho(self, coords) props = numpy.einsum('i,i->', val, coordsang[:, 4]) rprops += props * dvol[n] * rwei[n] logger.info(self, '*--> Electron density inside bsphere %8.5f ', rprops) logger.timer(self, 'Bsphere build', t0) return rprops
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Read info logger.info(self, 'Reading HDF5 file') with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value self.nshells = f['basis/nshells'].value # Dump info if self.verbose > logger.NOTE: self.dump_input() logger.info(self, 'Finish with HDF5 file') logger.timer(self, 'Info readed', t0) logger.info(self, '') return self
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Read info with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.symbols = f['molecule/symbols'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value # 2) Build cube data coords = self.coords margin = self.margin resolution = self.resolution self.box = numpy.max(coords, axis=0) - numpy.min(coords, axis=0) + margin * 2 self.boxorig = numpy.min(coords, axis=0) - margin nx = self.nx ny = self.ny nz = self.nz if resolution is not None: nx, ny, nz = numpy.ceil(self.box / resolution).astype(int) self.nx = nx self.ny = ny self.nz = nz # .../(nx-1) to get symmetric mesh # see also the discussion on https://github.com/sunqm/pyscf/issues/154 self.xs = numpy.arange(nx) * (self.box[0] / (nx - 1)) self.ys = numpy.arange(ny) * (self.box[1] / (ny - 1)) self.zs = numpy.arange(nz) * (self.box[2] / (nz - 1)) # Dump info if self.verbose > logger.NOTE: self.dump_input() density(self) logger.timer(self, 'Cube done', t0) logger.info(self, '') return self
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Build grid self.grids.verbose = self.verbose self.grids.stdout = self.stdout self.grids.max_memory = self.max_memory self.grids.scratch = self.scratch self.grids.build() # 2) Read info with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.symbols = f['molecule/symbols'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value # Dump info if self.verbose > logger.NOTE: self.dump_input() # 3) Qualitie of grid out = numint.eval_rho_gradmod(self,self.grids.coords) rhoval = numpy.einsum('i,i->',out[:,0],self.grids.weights) logger.info(self,'Integral of rho %.6f' % rhoval) # 4) Dispersion energy, TODO: prune rho points f_vv10(self,out[:,0],out[:,1]) logger.timer(self,'VV10 integration done', t0) logger.info(self,'') return self
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Read info with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.symbols = f['molecule/symbols'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value # Dump info if self.verbose > logger.NOTE: self.dump_input() # 2) Test logger.info(self, 'Testing orthogonality of orbitals') s = gto.eval_overlap(self) s = numpy.dot(s, self.mo_coeff) s = numpy.dot(self.mo_coeff.T, s) tools.dump_tri(self.stdout, s) logger.info(self, '') logger.timer(self, 'Integrals done', t0) logger.info(self, '') return self
def out_beta(self): logger.info(self, '* Go outside betasphere') xcoor = numpy.zeros(3) nrad = self.nrad iqudr = self.iqudr mapr = self.mapr r0 = self.brad rfar = self.rmax rad = self.rad t0 = time.clock() rmesh, rwei, dvol, dvoln = grids.rquad(nrad, r0, rfar, rad, iqudr, mapr) coordsang = self.agrids rprops = 0.0 for n in range(nrad): r = rmesh[n] coords = [] weigths = [] for j in range(self.npang): inside = True inside = inbasin(self, r, j) if (inside == True): cost = coordsang[j, 0] sintcosp = coordsang[j, 1] * coordsang[j, 2] sintsinp = coordsang[j, 1] * coordsang[j, 3] xcoor[0] = r * sintcosp xcoor[1] = r * sintsinp xcoor[2] = r * cost p = self.xyzrho + xcoor coords.append(p) weigths.append(coordsang[j, 4]) coords = numpy.array(coords) weigths = numpy.array(weigths) val = numint.eval_rho(self, coords) props = numpy.einsum('i,i->', val, weigths) rprops += props * dvol[n] * rwei[n] logger.info(self, '*--> Electron density outside bsphere %8.5f ', rprops) logger.timer(self, 'Out Bsphere build', t0) return rprops
def build(self, **kwargs): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Read info logger.info(self,'Reading HDF5 file') with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.xyz = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.symbols = f['molecule/symbols'].value # 2) Dump info if self.verbose > logger.NOTE: self.dump_flags() # 3) Gen grids atom_grids_tab = gen_atomic_grids(self,self.atom_grid, self.radi_method, self.level, self.prune, **kwargs) self.coords, self.weights = \ gen_partition(self,atom_grids_tab, self.radii_adjust, self.atomic_radii, self.becke_scheme) # 4) Save logger.info(self,'Finish with grids') logger.info(self,'Tot grids %d', len(self.weights)) logger.info(self,'Write HDF5 grid file') grid_dic = {'coords':self.coords, 'weights':self.weights} chkfile.save(self.chkfile, 'becke', grid_dic) logger.info(self,'Grid saved') logger.timer(self,'Becke grid build', t0) logger.info(self,'') return self
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Read info with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value # 2) Setup basis info and grids if (self.ntrial % 2 == 0): self.ntrial += 1 geofac = numpy.power(((self.rmaxsurf - 0.1) / self.rprimer), (1.0 / (self.ntrial - 1.0))) self.rpru = numpy.zeros((self.ntrial)) for i in range(self.ntrial): self.rpru[i] = self.rprimer * numpy.power(geofac, (i + 1) - 1) self.rsurf = numpy.zeros((self.npang, self.ntrial)) self.nlimsurf = numpy.zeros((self.npang), dtype=numpy.int32) self.grids = grids.lebgrid(self.npang) # Dump info if self.verbose > logger.NOTE: self.dump_input() # 3) Check rho nuclear atractors t = time.time() step = self.step self.xyzrho = numpy.zeros((self.natm, 3)) for i in range(self.natm): coords = self.coords[i] self.xyzrho[i], gradmod = gradrho(self, coords, step) if (gradmod > 1e-4): if (self.charges[i] > 2.0): logger.info(self, 'Good rho position %.6f %.6f %.6f', *self.xyzrho[i]) else: raise RuntimeError('Failed finding nucleus:', *self.xyzrho[i]) else: logger.info(self, 'Check rho position %.6f %.6f %.6f', *self.xyzrho[i]) logger.info(self, 'Setting xyrho for atom to imput coords') self.xyzrho[i] = self.coords[i] self.xnuc = numpy.asarray(self.xyzrho[self.inuc]) logger.info(self, 'Time finding nucleus %.3f (sec)' % (time.time() - t)) t = time.time() backend = 1 ct_ = numpy.asarray(self.grids[:, 0], order='C') st_ = numpy.asarray(self.grids[:, 1], order='C') cp_ = numpy.asarray(self.grids[:, 2], order='C') sp_ = numpy.asarray(self.grids[:, 3], order='C') angw_ = numpy.asarray(self.grids[:, 4], order='C') # 4) Compute surface feval = 'gsurf_driver' drv = getattr(libgsurf, feval) drv(ctypes.c_int(self.nmo), ctypes.c_int(self.nprims), self.ityp.ctypes.data_as(ctypes.c_void_p), self.oexp.ctypes.data_as(ctypes.c_void_p), self.ngroup.ctypes.data_as(ctypes.c_void_p), self.nzexp.ctypes.data_as(ctypes.c_void_p), self.nuexp.ctypes.data_as(ctypes.c_void_p), self.rcutte.ctypes.data_as(ctypes.c_void_p), self.mo_coeff.ctypes.data_as(ctypes.c_void_p), self.mo_occ.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(self.natm), self.coords.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(self.npang), ctypes.c_int((self.inuc)), self.xyzrho.ctypes.data_as(ctypes.c_void_p), ct_.ctypes.data_as(ctypes.c_void_p), st_.ctypes.data_as(ctypes.c_void_p), cp_.ctypes.data_as(ctypes.c_void_p), sp_.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(backend), ctypes.c_int(self.ntrial), ctypes.c_double(self.epsiscp), ctypes.c_double(self.epsroot), ctypes.c_double(self.rmaxsurf), ctypes.c_double(self.epsilon), self.rpru.ctypes.data_as(ctypes.c_void_p), ctypes.c_double(self.step), ctypes.c_int(self.mstep), self.nlimsurf.ctypes.data_as(ctypes.c_void_p), self.rsurf.ctypes.data_as(ctypes.c_void_p)) logger.info(self, 'Time finding surface %.3f (sec)' % (time.time() - t)) self.rmin = 1000.0 self.rmax = 0.0 for i in range(self.npang): nsurf = self.nlimsurf[i] self.rmin = numpy.minimum(self.rmin, self.rsurf[i, 0]) self.rmax = numpy.maximum(self.rmax, self.rsurf[i, nsurf - 1]) logger.info(self, 'Rmin for surface %.6f', self.rmin) logger.info(self, 'Rmax for surface %.6f', self.rmax) # 5) Safe surface logger.info(self, 'Finish with surface') logger.info(self, 'Write HDF5 surface file') atom_dic = { 'inuc': self.inuc, 'xnuc': self.xnuc, 'xyzrho': self.xyzrho, 'coords': self.grids, 'npang': self.npang, 'ntrial': self.ntrial, 'rmin': self.rmin, 'rmax': self.rmax, 'nlimsurf': self.nlimsurf, 'rsurf': self.rsurf } chkfile.save(self.chkfile, 'atom' + str(self.inuc), atom_dic) logger.info(self, 'Surface of atom %d saved', self.inuc) logger.timer(self, 'BaderSurf build', t0) logger.info(self, '') return self
logger.info(self, '') return self kernel = build if __name__ == '__main__': name = 'h2o.wfn.h5' becke = Becke(name) becke.verbose = 4 becke.grids.atom_grid = {'H': (510, 5810), 'O': (510, 5810)} becke.grids.prune = None becke.kernel() from pyscf import lib, dft from pyscf.dft import numint t0 = time.clock() logger.TIMER_LEVEL = 3 chkname = 'h2o.chk' mol = lib.chkfile.load_mol(chkname) mf_mo_coeff = lib.chkfile.load(chkname, 'scf/mo_coeff') mf_mo_occ = lib.chkfile.load(chkname, 'scf/mo_occ') coords = numpy.reshape(becke.grids.coords, (-1, 3)) ao = dft.numint.eval_ao(mol, coords, deriv=1) rho = dft.numint.eval_rho2(mol, ao, mf_mo_coeff, mf_mo_occ, xctype='GGA') rho = numpy.einsum('i,i->', rho[0], becke.grids.weights) logger.info(mol, 'Integral of rho %.6f' % rho) logger.timer(mol, 'CPU integration done', t0)
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Build info idx = 'atom' + str(self.inuc) with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.symbols = f['molecule/symbols'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value self.inuc = f[idx + '/inuc'].value self.xnuc = f[idx + '/xnuc'].value self.xyzrho = f[idx + '/xyzrho'].value self.agrids = f[idx + '/coords'].value self.npang = f[idx + '/npang'].value self.ntrial = f[idx + '/ntrial'].value self.rmin = f[idx + '/rmin'].value self.rmax = f[idx + '/rmax'].value self.nlimsurf = f[idx + '/nlimsurf'].value self.rsurf = f[idx + '/rsurf'].value if self.charges[self.inuc] == 1: self.rad = grids.BRAGG[self.charges[self.inuc]] else: self.rad = grids.BRAGG[self.charges[self.inuc]] * 0.5 self.brad = self.rmin * self.betafac if (self.iqudr == 'legendre'): self.iqudr = 1 if (self.biqudr == 'legendre'): self.biqudr = 1 if (self.mapr == 'becke'): self.mapr = 1 elif (self.mapr == 'exp'): self.mapr = 2 elif (self.mapr == 'none'): self.mapr = 0 if (self.bmapr == 'becke'): self.bmapr = 1 elif (self.bmapr == 'exp'): self.bmapr = 2 elif (self.bmapr == 'none'): self.bmapr = 0 # Dump info if self.verbose > logger.NOTE: self.dump_input() # 2) Compute integrals brprops = int_beta(self) rprops = out_beta(self) #logger.info(self,'Write info to HDF5 file') #atom_dic = {'inprops':brprops, # 'outprops':rprops, # 'totprops':(brprops+rprops)} #chkfile.save(self.surfile, 'atom_props'+str(self.inuc), atom_dic) logger.info(self, '*-> Total density density %8.5f ', (rprops + brprops)) logger.info(self, '') logger.info(self, 'Basim properties of atom %d done', self.inuc) logger.timer(self, 'Basin build', t0) logger.info(self, '') return self
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 # 1) Build grid self.grids.verbose = self.verbose self.grids.stdout = self.stdout self.grids.max_memory = self.max_memory self.grids.scratch = self.scratch self.grids.build() # 2) Read info with h5py.File(self.chkfile) as f: self.natm = f['molecule/natm'].value self.coords = f['molecule/coords'].value self.charges = f['molecule/charges'].value self.symbols = f['molecule/symbols'].value self.nmo = f['basis/nmo'].value self.nprims = f['basis/nprims'].value self.icen = f['basis/icen'].value self.ityp = f['basis/ityp'].value self.oexp = f['basis/oexp'].value self.mo_coeff = f['basis/mo_coeff'].value self.mo_occ = f['basis/mo_occ'].value self.ngroup = f['basis/ngroup'].value self.nzexp = f['basis/nzexp'].value self.nuexp = f['basis/nuexp'].value self.rcutte = f['basis/rcutte'].value # Dump info if self.verbose > logger.NOTE: self.dump_input() # 3) Qualitie of grid rho = numint.eval_rho(self, self.grids.coords) rhoval = numpy.einsum('i,i->', rho, self.grids.weights) logger.info(self, 'Integral of rho %.6f' % rhoval) # 4) Promolecular density and weights logger.info(self, 'Getting atomic data from tabulated densities') npoints = len(self.grids.weights) output = numpy.zeros(npoints) promol = numpy.zeros(npoints) ftmp = misc.H5TmpFile() rhoat = 0.0 for i in range(self.natm): libfapi.atomic(ctypes.c_int(npoints), ctypes.c_int(self.charges[i]), self.coords[i].ctypes.data_as(ctypes.c_void_p), self.grids.coords.ctypes.data_as(ctypes.c_void_p), output.ctypes.data_as(ctypes.c_void_p)) h5dat = ftmp.create_dataset('atom' + str(i), (npoints, ), 'f8') h5dat[:] = output[:] rhoa = numpy.einsum('i,i->', output, self.grids.weights) rhoat += rhoa promol += output logger.info(self, 'Integral of rho for atom %d %.6f' % (i, rhoa)) logger.info(self, 'Integral of rho promolecular %.6f' % rhoat) for i in range(self.natm): h5dat = ftmp.create_dataset('weight' + str(i), (npoints, ), 'f8') h5dat[:] = ftmp['atom' + str(i)][:] / (promol + param.HMINIMAL) # 5) Atomic partition atomq = numpy.zeros(self.natm) hirshfeld = numpy.zeros(npoints) for i in range(self.natm): hirshfeld[:] = ftmp['weight' + str(i)] atomq[i] = numpy.einsum('i,i->', rho, self.grids.weights * hirshfeld) logger.info(self, 'Charge of atom %d %.6f' % (i, atomq[i])) logger.timer(self, 'Becke integration done', t0) logger.info(self, '') return self
def build(self): t0 = time.clock() logger.TIMER_LEVEL = 3 title, symbols, numbers, coords, icen, ityp, oexp, \ mo_count, mo_occ, mo_energy, mo_coeff = wfn.load_wfn(self.wfnfile) nprims, nmo = mo_coeff.shape self.natm = coords.shape[0] self.nelectrons = mo_occ.sum() self.symbols = symbols self.coords = coords self.charges = numbers self.nmo = nmo self.icen = icen self.ityp = ityp self.oexp = oexp self.mo_occ = mo_occ self.mo_coeff = mo_coeff self.nprims = nprims self.lang = numpy.empty(self.nprims, dtype=numpy.int32) self.npc = numpy.zeros(self.natm, dtype=numpy.int32) # 1) Purge repeated primitives purge_prims(self) # 2) Classifie basis set get_shells(self) # 3) Get cutdistances for each shell get_shells_eps(self) # 4) In case for correlated build natural orbitals if (self.corr): get_nat_orbs(self) # Dump info if self.verbose > logger.NOTE: self.dump_input() # 5) Write info to file logger.info(self, 'Write HDF5 file') mol_dic = { 'natm': self.natm, 'symbols': self.symbols, 'corr': self.corr, 'coords': self.coords, 'charges': self.charges, 'nelectrons': self.nelectrons } chkfile.save(self.chkfile, 'molecule', mol_dic) bas_dic = { 'cuttz': self.cuttz, 'nmo': self.nmo, 'nprims': self.nprims, 'icen': self.icen, 'ityp': self.ityp, 'oexp': self.oexp, 'lang': self.lang, 'lmax': self.lmax, 'npc': self.npc, 'mo_coeff': self.mo_coeff, 'mo_occ': self.mo_occ, 'ngroup': self.ngroup, 'nzexp': self.nzexp, 'nuexp': self.nuexp, 'rcutte': self.rcutte, 'nshells': self.nshells } chkfile.save(self.chkfile, 'basis', bas_dic) logger.timer(self, 'Basis info build', t0) logger.info(self, '') return self