def test_pyside_cubegen(): mol = psi4.geometry(""" O 0 0 0 H 0 0 1.795239827225189 H 1.693194615993441 0 -0.599043184453037 symmetry c1 units au """) psi4.core.be_quiet() psi4.set_options({ 'basis': "sto-3g", 'scf_type': 'pk', 'cubeprop_tasks': ['density', 'orbitals'] }) scf_e, wfn = psi4.energy('SCF', return_wfn=True, molecule=mol) psi4.cubeprop(wfn) cubegen = psi4.core.CubeProperties(wfn) Dtot = wfn.Da() Dtot.add(wfn.Db()) cubegen.compute_density(Dtot, "Dtot") alpha_orbitals = wfn.Ca_subset("AO", "OCC").np # select the three highest occupied orbitals occs = alpha_orbitals[:, -3:] occs_pm = psi4.core.Matrix.from_array(occs) cubegen.compute_orbitals(occs_pm, [0, 2], ["1", "3"], "orbital") assert compare_cubes("Dt.cube", "Dtot.cube") assert compare_cubes("Psi_a_5_5-A.cube", "orbital_3_3.cube") assert compare_cubes("Psi_a_3_3-A.cube", "orbital_1_1.cube")
def psi4_cubeprop(wfn, path='.', orbs=[], nocc=0, nvir=0, density=False, frontier_orbitals=False, load=False): """ Run a psi4 cubeprop computation to generate cube files from a given Wavefunction object By default this function plots from the H**O -2 to the LUMO + 2 Parameters ---------- wfn : psi4Wavefunction A psi4 Wavefunction object path : str The path of the directory that will contain the cube files orbs : list or string The list of orbitals to convert to cube files (one based). nocc : int The number of occupied orbitals nvir : int The number of virtual orbitals """ import os.path cubeprop_tasks = [] if isinstance(orbs, str): if (orbs == 'frontier_orbitals'): cubeprop_tasks.append('FRONTIER_ORBITALS') else: cubeprop_tasks.append('ORBITALS') if nocc + nvir > 0: na = wfn.nalpha() nmo = wfn.nmo() min_orb = max(1, na + 1 - nocc) max_orb = min(nmo, na + nvir) orbs = [k for k in range(min_orb, max_orb + 1)] print( f'Preparing cube files for orbitals: {", ".join([str(orb) for orb in orbs])}' ) if density: cubeprop_tasks.append('DENSITY') if not os.path.exists(path): os.makedirs(path) psi4.set_options({ 'CUBEPROP_TASKS': cubeprop_tasks, 'CUBEPROP_ORBITALS': orbs, 'CUBEPROP_FILEPATH': path }) psi4.cubeprop(wfn) if load: return load_cubes(path)
def __init__(self, wfn): psi4.set_options({"cubic_grid_spacing" : [0.2, 0.2, 0.2], "cubic_grid_overage" : [4.0, 4.0, 4.0]}) psi4.cubeprop(wfn) self.wfn = wfn self.geometry = self.wfn.molecule() self.spacing = psi4.core.get_global_option("CUBIC_GRID_SPACING") self.overage = psi4.core.get_global_option("CUBIC_GRID_OVERAGE") self.origin = self.get_origin() self.info = self.get_info() self.meta = None
def get_mo_view(mol, wfn): gridspace = 0 homo_idx = wfn.nalpha() lumo_idx = homo_idx + 1 self.psi4.set_options({ "cubeprop_tasks": ['ESP', 'FRONTIER_ORBITALS', 'Density', 'DUAL_DESCRIPTOR'], "cubic_grid_spacing": [gridspace, gridspace, gridspace], "cubeprop_filepath": self.tempdir }) Chem.MolToMolFile(mol, 'target.mol') psi4.cubeprop(wfn)
def plot_density(self, which_density, iso=0.020, slices=1, delete_cubefile=True): psi4.set_options({'cubeprop_tasks': ['density']}) energy, wfn = psi4.energy(self.method, molecule=self.geometry, return_wfn=True) psi4.cubeprop(wfn) if which_density == 'Da': D, D_info = read_cube('Da.cube') elif which_density == 'Db': D, D_info = read_cube('Db.cube') elif which_density == 'Ds': D, D_info = read_cube('Ds.cube') elif which_density == 'Dt': D, D_info = read_cube('Dt.cube') if delete_cubefile == True: os.remove('Da.cube') os.remove('Db.cube') os.remove('Ds.cube') os.remove('Dt.cube') fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(10, 10)) print(D.shape) # for i in range(0): # for j in range(0): ax.imshow(D[60, :, :], interpolation="nearest") for i in range(D.shape[1]): for j in range(D.shape[2]): if np.isclose(D[60, i, j], iso, 0.3e-1) == True: # if (i+j) % 0 == 0: ax.scatter(j, i, color="white") return D
print("Iter %10d od %10d" % (j, niter)) else: rtutil.progress_bar(j, niter) print("") print("") fo.close() end = time.time() cend = time.process_time() print("Time for %10d time iterations : (%.5f s, %.5f s)\n" % (niter + 1, end - start, cend - cstart)) t_point = np.linspace(0.0, niter * dt, niter + 1) dip_t = 2.00 * np.array(dip_list).real + Ndip_dir ene_t = np.array(ene_list).real + Nuc_rep imp_t = np.array(imp_list) print("Dumping output files") if (do_weighted == -2): wd_dip = 2.00 * np.array(weighted_dip).real np.savetxt(outfnames[3], np.c_[t_point,wd_dip], \ fmt='%.12e') np.savetxt(outfnames[0], np.c_[t_point, dip_t], fmt='%.12e') np.savetxt(outfnames[1], np.c_[t_point, imp_t], fmt='%.12e') np.savetxt(outfnames[2], np.c_[t_point, ene_t], fmt='%.12e') if not args.restart: wfn.Da().copy(psi4.core.Matrix.from_array(D_ti.real)) wfn.Db().copy(psi4.core.Matrix.from_array(D_ti.real)) psi4.cubeprop(wfn)
import numpy as np from cuhf import CUHFMolecule from uhf import UHFMolecule psi4.core.set_output_file('CUHF.dat', False) psi4.set_memory("3 GB") psi4.set_options({ "basis": "sto-3g", "scf_type": "pk", "reference": "cuhf", "cubeprop_tasks": "orbitals", "e_convergence": "1e-12" }) h2o = CUHFMolecule(""" H 0 0 0 H 0 0.86602540378 0.5 H 0 0 1 units angstrom""") h2o.setConvergence(1e-12) E, wfn_RHF = psi4.energy("scf", mol=h2o.id, return_wfn=True) F = h2o.iterator(mute=True, criterion="energy") Ca = h2o.getEigenStuff("alpha")[1] Cb = h2o.getEigenStuff("beta")[1] print(Ca) print(Cb) #Ca[:,0] = 0.1 #Cb[:,0] = 0.1 wfn_RHF.Ca().copy(psi4.core.Matrix.from_array(Ca)) wfn_RHF.Cb().copy(psi4.core.Matrix.from_array(Cb)) psi4.cubeprop(wfn_RHF)
#specify a different basis set for the frozen fragment psi4.set_options({'basis': args.obs, 'dft_radial_scheme' : 'becke', 'dft_radial_points': 75, 'dft_spherical_points' : 434}) #defaul = 302 print('CHECK : basis from options block (act sys) :%s\n' % (psi4.core.get_global_option('BASIS'))) #set the grid for the calculation of fragments #set the active molecule active=Molecule(geomA) active.append('symmetry c1' +'\n' + 'no_com' + '\n' + 'no_reorient' + '\n') active_mol=psi4.geometry(active.geometry) ene, active_wfn = psi4.energy(func, return_wfn=True) C_active=np.array(active_wfn.Ca_subset("AO","OCC")) psi4.cubeprop(active_wfn) os.rename("Da.cube","Da0.cube") os.rename("Db.cube","Db0.cube") os.rename("Dt.cube","Dt0.cube") os.rename("Ds.cube","Ds0.cube") psi4.core.clean() import psi4.core as p4c psi4_matrix = p4c.Matrix.from_array(points[:,:3]) enviro_epc = p4c.ESPPropCalc(enviro_wfn) elpot_enviro = np.array(enviro_epc.compute_esp_over_grid_in_memory( psi4_matrix )) psi4.core.clean() os.close(stdout_fileno) t.join()