// Returns a checkpoint of this CFGIterator's progress. CFGIterator::checkpoint CFGIterator::getChkpt() { assert(initialized); CFGIterator::checkpoint chkpt(remainingNodes, visited); return chkpt; //return new CFGIterator::checkpoint::checkpoint(remainingNodes, visited); }
// Returns a checkpoint of this CFGIterator's progress. dataflowCFGIterator::checkpoint dataflowCFGIterator::getChkpt() { assert(initialized); dataflowCFGIterator::checkpoint chkpt(CFGIterator::getChkpt(), terminator); return chkpt; //return new dataflowCFGIterator::checkpoint::checkpoint(CFGIterator::getChkpt(), terminator); }
// Returns a checkpoint of this iterator's progress. dataflow::checkpoint dataflow::getChkpt() { ROSE_ASSERT(initialized); dataflow::checkpoint chkpt(iterator::getChkpt(), terminator); return chkpt; //return new dataflow::checkpoint::checkpoint(iterator::getChkpt(), terminator); }
// Returns a checkpoint of this iterator's progress. iterator::checkpoint iterator::getChkpt() { ROSE_ASSERT(initialized); iterator::checkpoint chkpt(remainingNodes, visited); return chkpt; //return new iterator::checkpoint::checkpoint(remainingNodes, visited); }
int xn_import(struct udf_type *t) { struct root_entry r; int res; size_t nblocks, nbytes; cap_t c; long db; int i, tid; xn_cnt_t n; da_t da; void *p; if((tid = sys__type_mount(t->type_name)) >= 0) { //printf("hit in cache for %s (tid %d, class %d)\n", t->type_name, tid, t->class); return tid; } else //printf("<%s> did not hit in cache\n", t->type_name); c = (cap_t)CAP_ROOT; /* Allocate space, place in root, import. */ if(sys__xn_mount(&r, t->type_name, c) == XN_SUCCESS) { xn_cnt_t cnt; ppn_t ppn; cnt = r.nelem; printf("reading %d\n", r.nelem); /* alloc storage. */ for(ppn = -1, i = 0; i < r.nelem; i++, ppn++) { ppn = sys__xn_bind(r.db+i, ppn, (cap_t)CAP_ROOT, XN_FORCE_READIN, 1); if(ppn < 0) { printf("ppn = %ld\n", ppn); fatal(Death); } } /* now need to load. */ if((res = sys__xn_readin(r.db, r.nelem, &cnt)) != XN_SUCCESS) { printf("res = %d\n", res); fatal(Death); } /* GROK -- not my code, but I think cnt should have been 1 */ /* going into the readin (rather than nelem), since each */ /* disk request gets notification (rather than each block */ /* read or written). */ wk_waitfor_value (&cnt, 0, 0); printf("hit in cache for %s\n", t->type_name); if((res = sys__type_mount(t->type_name)) < XN_SUCCESS) { printf("res = %d\n", res); fatal(SHould have hit); } return res; } chkpt("xn_mount"); nblocks = bytes_to_blocks(sizeof *t); db = 0; if(sys__install_mount(t->type_name, &db, nblocks, XN_DB, c) < 0) fatal(Mount failed); //printf("nblocks = %ld\n", (long)nblocks); /* Allocate pages, and copyin. */ for(i = 0; i < nblocks; i++) { if(sys__xn_bind(db+i, -1, c, XN_ZERO_FILL, 1) < 0) fatal(Could not bind); da = da_compose(db+i, 0); p = (char *)t + i * PAGESIZ; nbytes = (i == (nblocks - 1)) ? (sizeof *t % XN_BLOCK_SIZE) : PAGESIZ; if((res = sys__xn_writeb(da, p, nbytes, c)) < 0) { printf("res = %d\n", res); fatal(Could not write); } n = 1; if(sys__xn_writeback(db+i, 1, &n) < 0) fatal(Cannot write back); wk_waitfor_value (&n, 0, 0); } chkpt("type import.."); if((tid = sys__type_import(t->type_name)) < 0) fatal(Cannot import); return tid; }
int main(int argc, char **argv) { #ifdef _OPENMP printf("ERKALE - population from Hel, OpenMP version, running on %i cores.\n",omp_get_max_threads()); #else printf("ERKALE - population from Hel, serial version.\n"); #endif print_copyright(); print_license(); #ifdef SVNRELEASE printf("At svn revision %s.\n\n",SVNREVISION); #endif print_hostname(); if(argc!=2) { printf("Usage: %s runfile\n",argv[0]); return 1; } // Parse settings Settings set; set.add_string("LoadChk","Checkpoint file to load density from","erkale.chk"); set.add_bool("Bader", "Run Bader analysis?", false); set.add_bool("Becke", "Run Becke analysis?", false); set.add_bool("Mulliken", "Run Mulliken analysis?", false); set.add_bool("Lowdin", "Run Löwdin analysis?", false); set.add_bool("IAO", "Run Intrinsic Atomic Orbital analysis?", false); set.add_string("IAOBasis", "Minimal basis set for IAO analysis", "MINAO.gbs"); set.add_bool("Hirshfeld", "Run Hirshfeld analysis?", false); set.add_string("HirshfeldMethod", "Method to use for Hirshfeld(-I) analysis", "HF"); set.add_bool("IterativeHirshfeld", "Run iterative Hirshfeld analysis?", false); set.add_bool("Stockholder", "Run Stockholder analysis?", false); set.add_bool("Voronoi", "Run Voronoi analysis?", false); set.add_double("Tol", "Grid tolerance to use for the charges", 1e-5); set.add_bool("OrbThr", "Compute orbital density thresholds", false); set.add_bool("SICThr", "Compute SIC orbital density thresholds", false); set.add_bool("DensThr", "Compute total density thresholds", false); set.add_double("OrbThrVal", "Which density threshold to calculate", 0.85); set.add_double("OrbThrGrid", "Accuracy of orbital density threshold integration grid", 1e-3); // Parse settings set.parse(argv[1]); // Print settings set.print(); // Initialize libint init_libint_base(); // Load checkpoint Checkpoint chkpt(set.get_string("LoadChk"),false); // Load basis set BasisSet basis; chkpt.read(basis); // Restricted calculation? bool restr; chkpt.read("Restricted",restr); arma::mat P, Pa, Pb; chkpt.read("P",P); if(!restr) { chkpt.read("Pa",Pa); chkpt.read("Pb",Pb); } double tol=set.get_double("Tol"); if(set.get_bool("Bader")) { if(restr) bader_analysis(basis,P,tol); else bader_analysis(basis,Pa,Pb,tol); } if(set.get_bool("Becke")) { if(restr) becke_analysis(basis,P,tol); else becke_analysis(basis,Pa,Pb,tol); } std::string hmet=set.get_string("HirshfeldMethod"); if(set.get_bool("Hirshfeld")) { if(restr) hirshfeld_analysis(basis,P,hmet,tol); else hirshfeld_analysis(basis,Pa,Pb,hmet,tol); } if(set.get_bool("IterativeHirshfeld")) { if(restr) iterative_hirshfeld_analysis(basis,P,hmet,tol); else iterative_hirshfeld_analysis(basis,Pa,Pb,hmet,tol); } if(set.get_bool("IAO")) { std::string minbas=set.get_string("IAOBasis"); if(restr) { // Get amount of occupied orbitals int Nela; chkpt.read("Nel-a",Nela); // Get orbital coefficients arma::mat C; chkpt.read("C",C); // Do analysis IAO_analysis(basis,C.cols(0,Nela-1),P,minbas); } else { // Get amount of occupied orbitals int Nela, Nelb; chkpt.read("Nel-a",Nela); chkpt.read("Nel-b",Nelb); // Get orbital coefficients arma::mat Ca, Cb; chkpt.read("Ca",Ca); chkpt.read("Cb",Cb); // Do analysis IAO_analysis(basis,Ca.cols(0,Nela-1),Cb.cols(0,Nelb-1),Pa,Pb,minbas); } } if(set.get_bool("Lowdin")) { if(restr) lowdin_analysis(basis,P); else lowdin_analysis(basis,Pa,Pb); } if(set.get_bool("Mulliken")) { if(restr) mulliken_analysis(basis,P); else mulliken_analysis(basis,Pa,Pb); } if(set.get_bool("Stockholder")) { if(restr) stockholder_analysis(basis,P,tol); else stockholder_analysis(basis,Pa,Pb,tol); } if(set.get_bool("Voronoi")) { if(restr) voronoi_analysis(basis,P,tol); else voronoi_analysis(basis,Pa,Pb,tol); } if(set.get_bool("OrbThr")) { // Calculate orbital density thresholds // Integration grid DFTGrid intgrid(&basis,true); intgrid.construct_becke(set.get_double("OrbThrGrid")); // Threshold is double thr=set.get_double("OrbThrVal"); if(restr) { // Get amount of occupied orbitals int Nela; chkpt.read("Nel-a",Nela); // Get orbital coefficients arma::mat C; chkpt.read("C",C); printf("\n%4s %9s %8s\n","orb","thr","t (s)"); for(int io=0;io<Nela;io++) { Timer t; // Orbital density matrix is arma::mat Po=C.col(io)*arma::trans(C.col(io)); double val=compute_threshold(intgrid,Po,thr,false); // Print out orbital threshold printf("%4i %8.3e %8.3f\n", io+1, val, t.get()); fflush(stdout); } } else { // Get amount of occupied orbitals int Nela, Nelb; chkpt.read("Nel-a",Nela); chkpt.read("Nel-b",Nelb); // Get orbital coefficients arma::mat Ca, Cb; chkpt.read("Ca",Ca); chkpt.read("Cb",Cb); printf("\n%4s %9s %9s %8s\n","orb","thr-a","thr-b","t (s)"); for(int io=0;io<Nela;io++) { Timer t; // Orbital density matrix is arma::mat Po=Ca.col(io)*arma::trans(Ca.col(io)); double vala=compute_threshold(intgrid,Po,thr,false); if(io<Nelb) { Po=Cb.col(io)*arma::trans(Cb.col(io)); double valb=compute_threshold(intgrid,Po,thr,false); // Print out orbital threshold printf("%4i %8.3e %8.3e %8.3f\n", io+1, vala, valb, t.get()); fflush(stdout); } else { printf("%4i %8.3e %9s %8.3f\n", io+1, vala, "****", t.get()); fflush(stdout); } } } } if(set.get_bool("SICThr")) { // Calculate SIC orbital density thresholds // Integration grid DFTGrid intgrid(&basis,true); intgrid.construct_becke(set.get_double("OrbThrGrid")); // Threshold is double thr=set.get_double("OrbThrVal"); if(restr) { // Get orbital coefficients arma::cx_mat CW; chkpt.cread("CW",CW); printf("\n%4s %9s %8s\n","orb","thr","t (s)"); for(size_t io=0;io<CW.n_cols;io++) { Timer t; // Orbital density matrix is arma::mat Po=arma::real(CW.col(io)*arma::trans(CW.col(io))); double val=compute_threshold(intgrid,Po,thr,false); // Print out orbital threshold printf("%4i %8.3e %8.3f\n", (int) io+1, val, t.get()); fflush(stdout); } } else { // Get orbital coefficients arma::cx_mat CWa, CWb; chkpt.cread("CWa",CWa); chkpt.cread("CWb",CWb); printf("\n%4s %9s %9s %8s\n","orb","thr-a","thr-b","t (s)"); for(size_t io=0;io<CWa.n_cols;io++) { Timer t; // Orbital density matrix is arma::mat Po=arma::real(CWa.col(io)*arma::trans(CWa.col(io))); double vala=compute_threshold(intgrid,Po,thr,false); if(io<CWb.n_cols) { Po=arma::real(CWb.col(io)*arma::trans(CWb.col(io))); double valb=compute_threshold(intgrid,Po,thr,false); // Print out orbital threshold printf("%4i %8.3e %8.3e %8.3f\n", (int) io+1, vala, valb, t.get()); fflush(stdout); } else { printf("%4i %8.3e %9s %8.3f\n", (int) io+1, vala, "****", t.get()); fflush(stdout); } } } } if(set.get_bool("DensThr")) { // Calculate SIC orbital density thresholds // Integration grid DFTGrid intgrid(&basis,true); intgrid.construct_becke(set.get_double("OrbThrGrid")); // Threshold is double thr=set.get_double("OrbThrVal"); Timer t; printf("\n%10s %9s %8s\n","density","thr","t (s)"); if(!restr) { double aval=compute_threshold(intgrid,Pa,thr*arma::trace(P*basis.overlap()),true); printf("%10s %8.3e %8.3f\n", "alpha", aval, t.get()); fflush(stdout); t.set(); double bval=compute_threshold(intgrid,Pb,thr*arma::trace(P*basis.overlap()),true); printf("%10s %8.3e %8.3f\n", "beta", bval, t.get()); fflush(stdout); t.set(); } double val=compute_threshold(intgrid,P,thr*arma::trace(P*basis.overlap()),true); printf("%10s %8.3e %8.3f\n", "total", val, t.get()); fflush(stdout); } return 0; }
int main(int argc, char **argv) { #ifdef _OPENMP printf("ERKALE - Casida from Hel, OpenMP version, running on %i cores.\n",omp_get_max_threads()); #else printf("ERKALE - Casida from Hel, serial version.\n"); #endif print_copyright(); print_license(); #ifdef SVNRELEASE printf("At svn revision %s.\n\n",SVNREVISION); #endif print_hostname(); if(argc!=1 && argc!=2) { printf("Usage: $ %s (runfile)\n",argv[0]); return 0; } // Initialize libint init_libint_base(); Timer t; t.print_time(); // Parse settings Settings set; set.add_string("FittingBasis","Basis set to use for density fitting (Auto for automatic)","Auto"); set.add_string("CasidaX","Exchange functional for Casida","lda_x"); set.add_string("CasidaC","Correlation functional for Casida","lda_c_vwn"); set.add_bool("CasidaPol","Perform polarized Casida calculation (when using restricted wf)",false); set.add_int("CasidaCoupling","Coupling mode: 0 for IPA, 1 for RPA and 2 for TDLDA",2); set.add_double("CasidaTol","Tolerance for Casida grid",1e-4); set.add_string("CasidaStates","States to include in Casida calculation, eg ""1,3:7,10,13"" ",""); set.add_string("CasidaQval","Values of Q to compute spectrum for",""); set.add_string("LoadChk","Checkpoint to load","erkale.chk"); if(argc==2) set.parse(std::string(argv[1])); else printf("\nDefault settings used."); // Print settings set.print(); // Get functional strings int xfunc=find_func(set.get_string("CasidaX")); int cfunc=find_func(set.get_string("CasidaC")); if(is_correlation(xfunc)) throw std::runtime_error("Refusing to use a correlation functional as exchange.\n"); if(is_kinetic(xfunc)) throw std::runtime_error("Refusing to use a kinetic energy functional as exchange.\n"); if(is_exchange(cfunc)) throw std::runtime_error("Refusing to use an exchange functional as correlation.\n"); if(is_kinetic(cfunc)) throw std::runtime_error("Refusing to use a kinetic energy functional as correlation.\n"); set.add_int("CasidaXfunc","Internal variable",xfunc); set.add_int("CasidaCfunc","Internal variable",cfunc); // Print information about used functionals print_info(xfunc,cfunc); // Get values of q to compute spectrum for std::vector<double> qvals=parse_range_double(set.get_string("CasidaQval")); // Load checkpoint std::string fchk=set.get_string("LoadChk"); Checkpoint chkpt(fchk,false); // Check that calculation was converged bool conv; chkpt.read("Converged",conv); if(!conv) throw std::runtime_error("Refusing to run Casida calculation based on a non-converged SCF density!\n"); // Parse input states std::string states=set.get_string("CasidaStates"); std::string newstates=parse_states(chkpt,states); set.set_string("CasidaStates",newstates); if(states.compare(newstates)!=0) printf("CasidaStates has been parsed to \"%s\".\n",newstates.c_str()); // Load basis set BasisSet basis; chkpt.read(basis); Casida cas; bool restr; chkpt.read("Restricted",restr); if(restr) { // Load energy and orbitals arma::mat C, P; arma::vec E; std::vector<double> occs; chkpt.read("P",P); chkpt.read("C",C); chkpt.read("E",E); chkpt.read("occs",occs); // Check orthonormality check_orth(C,basis.overlap(),false); if(set.get_bool("CasidaPol")) { // Half occupancy (1.0 instead of 2.0) std::vector<double> hocc(occs); for(size_t i=0;i<hocc.size();i++) hocc[i]/=2.0; cas=Casida(set,basis,E,E,C,C,P/2.0,P/2.0,hocc,hocc); } else cas=Casida(set,basis,E,C,P,occs); } else { arma::mat Ca, Cb; arma::mat Pa, Pb; arma::vec Ea, Eb; std::vector<double> occa, occb; chkpt.read("Pa",Pa); chkpt.read("Pb",Pb); chkpt.read("Ca",Ca); chkpt.read("Cb",Cb); chkpt.read("Ea",Ea); chkpt.read("Eb",Eb); chkpt.read("occa",occa); chkpt.read("occb",occb); // Check orthonormality check_orth(Ca,basis.overlap(),false); check_orth(Cb,basis.overlap(),false); cas=Casida(set,basis,Ea,Eb,Ca,Cb,Pa,Pb,occa,occb); } // Dipole transition print_spectrum("casida.dat",cas.dipole_transition(basis)); // Q dependent stuff for(size_t iq=0;iq<qvals.size();iq++) { // File to save output char fname[80]; sprintf(fname,"casida-%.2f.dat",qvals[iq]); print_spectrum(fname,cas.transition(basis,qvals[iq])); } printf("\nRunning program took %s.\n",t.elapsed().c_str()); t.print_time(); return 0; }
enum calcd run_calc(const BasisSet & basis, Settings & set, bool force) { // Checkpoint file to load std::string loadname=set.get_string("LoadChk"); if(stricmp(loadname,"")==0) { // Nothing to load - run full calculation. calculate(basis,set,force); if(force) return FULLCALC; else return ECALC; } // Was the calculation converged? bool convd; BasisSet oldbas; { Checkpoint chkpt(loadname,false); chkpt.read("Converged",convd); chkpt.read(oldbas); } if(!convd) { // Old calculation was not converged - run full calculation set.set_string("LoadName",""); calculate(basis,set,force); if(force) return FULLCALC; else return ECALC; } // Copy the checkpoint if necessary std::string savename=set.get_string("SaveChk"); if(stricmp(savename,loadname)!=0) { // Copy the file std::ostringstream oss; oss << "cp " << loadname << " " << savename; int cp=system(oss.str().c_str()); if(cp) { ERROR_INFO(); throw std::runtime_error("Failed to copy checkpoint file.\n"); } } // Strict integrals? bool strictint(set.get_bool("StrictIntegrals")); // Check if the basis set is different if(!(basis==oldbas)) { // Basis set is different or calculation was not converged - need // to run calculation. Project Fock matrix to new basis and // diagonalize to get new orbitals { // Open in write mode, don't truncate Checkpoint chkpt(savename,true,false); // Save basis chkpt.write(basis); // Overlap matrix arma::mat S=basis.overlap(); chkpt.write("S",S); arma::mat Sinvh=BasOrth(S,set); chkpt.write("Sinvh",Sinvh); // Restricted or unrestricted run? bool restr; chkpt.read("Restricted",restr); chkpt.read(oldbas); if(restr) { rscf_t sol; std::vector<double> occs; chkpt.read("H",sol.H); chkpt.read("occs",occs); // Form new orbitals by diagonalizing H in new geometry diagonalize(S,Sinvh,sol); // Form new density sol.P=form_density(sol.C,occs); // Write basis set, orbitals and density chkpt.write("C",sol.C); chkpt.write("E",sol.E); chkpt.write("P",sol.P); } else { uscf_t sol; std::vector<double> occa, occb; chkpt.read("Ha",sol.Ha); chkpt.read("Hb",sol.Hb); chkpt.read("occa",occa); chkpt.read("occb",occb); // Form new orbitals by diagonalizing H in new geometry diagonalize(S,Sinvh,sol); // Form new density sol.Pa=form_density(sol.Ca,occa); sol.Pb=form_density(sol.Cb,occb); sol.P=sol.Pa+sol.Pb; // Write basis set, orbitals and density chkpt.write("Ca",sol.Ca); chkpt.write("Cb",sol.Cb); chkpt.write("Ea",sol.Ea); chkpt.write("Eb",sol.Eb); chkpt.write("Pa",sol.Pa); chkpt.write("Pb",sol.Pb); chkpt.write("P",sol.P); } // Calculation is now not converged bool conv=false; chkpt.write("Converged",conv); } // Now we can do the SCF calculation calculate(basis,set,force); if(force) return FULLCALC; else return ECALC; } // Because we are here, the basis set is the same. if(!force) // No force required, can just read energy from file. return NOCALC; // Have converged energy, compute force. // Open the checkpoint in write mode, don't truncate it Checkpoint chkpt(savename,true,false); // SCF structure SCF solver(basis,set,chkpt); // Do a plain Hartree-Fock calculation? bool hf= (stricmp(set.get_string("Method"),"HF")==0); bool rohf=(stricmp(set.get_string("Method"),"ROHF")==0); dft_t dft; if(!hf && !rohf) { // Get exchange and correlation functionals as well as grid settings dft=parse_dft(set,false); } // Force arma::vec f; double tol; chkpt.read("tol",tol); // Multiplicity int mult=set.get_int("Multiplicity"); // Amount of electrons int Nel=basis.Ztot()-set.get_int("Charge"); if(mult==1 && Nel%2==0 && !set.get_bool("ForcePol")) { rscf_t sol; chkpt.read("C",sol.C); chkpt.read("E",sol.E); chkpt.read("H",sol.H); chkpt.read("P",sol.P); std::vector<double> occs; chkpt.read("occs",occs); // Restricted case if(hf) { f=solver.force_RHF(sol,occs,FINETOL); } else { DFTGrid grid(&basis,set.get_bool("Verbose"),dft.lobatto); DFTGrid nlgrid(&basis,set.get_bool("Verbose"),dft.lobatto); // Fixed grid? if(dft.adaptive) grid.construct(sol.P,dft.gridtol,dft.x_func,dft.c_func); else { grid.construct(dft.nrad,dft.lmax,dft.x_func,dft.c_func,strictint); if(dft.nl) nlgrid.construct(dft.nlnrad,dft.nllmax,true,false,strictint,true); } f=solver.force_RDFT(sol,occs,dft,grid,nlgrid,FINETOL); } } else { uscf_t sol; chkpt.read("Ca",sol.Ca); chkpt.read("Ea",sol.Ea); chkpt.read("Ha",sol.Ha); chkpt.read("Pa",sol.Pa); chkpt.read("Cb",sol.Cb); chkpt.read("Eb",sol.Eb); chkpt.read("Hb",sol.Hb); chkpt.read("Pb",sol.Pb); chkpt.read("P",sol.P); std::vector<double> occa, occb; chkpt.read("occa",occa); chkpt.read("occb",occb); if(hf) { f=solver.force_UHF(sol,occa,occb,tol); } else if(rohf) { int Nela, Nelb; chkpt.read("Nel-a",Nela); chkpt.read("Nel-b",Nelb); throw std::runtime_error("Not implemented!\n"); // f=solver.force_ROHF(sol,Nela,Nelb,tol); } else { DFTGrid grid(&basis,set.get_bool("Verbose"),dft.lobatto); DFTGrid nlgrid(&basis,set.get_bool("Verbose"),dft.lobatto); // Fixed grid? if(dft.adaptive) grid.construct(sol.P,dft.gridtol,dft.x_func,dft.c_func); else { grid.construct(dft.nrad,dft.lmax,dft.x_func,dft.c_func,strictint); if(dft.nl) nlgrid.construct(dft.nlnrad,dft.nllmax,true,false,strictint,true); } f=solver.force_UDFT(sol,occa,occb,dft,grid,nlgrid,tol); } } chkpt.write("Force",f); chkpt.close(); return FORCECALC; }
int main(int argc, char **argv) { #ifdef _OPENMP printf("ERKALE - EMD from Hel, OpenMP version, running on %i cores.\n",omp_get_max_threads()); #else printf("ERKALE - EMD from Hel, serial version.\n"); #endif print_copyright(); print_license(); #ifdef SVNRELEASE printf("At svn revision %s.\n\n",SVNREVISION); #endif print_hostname(); if(argc!=1 && argc!=2) { printf("Usage: $ %s (runfile)\n",argv[0]); return 0; } Timer t; // Parse settings Settings set; set.add_string("LoadChk","Checkpoint file to load density from","erkale.chk"); set.add_bool("DoEMD", "Perform calculation of isotropic EMD (moments of EMD, Compton profile)", true); set.add_double("EMDTol", "Tolerance for the numerical integration of the radial EMD",1e-8); set.add_string("EMDlm", "Which projection of the radial EMD to compute",""); set.add_bool("EMDAdapt", "Use adaptive grid to compute EMD?", true); set.add_string("EMDCube", "Calculate EMD on a cube? e.g. -10:.3:10 -5:.2:4 -2:.1:3", ""); set.add_string("EMDOrbitals", "Compute EMD of given orbitals, e.g. 1,2,4:6",""); set.add_string("Similarity", "Compute similarity measure to checkpoint",""); set.add_string("SimilarityGrid", "Grid to use for computing similarity integrals","500 77"); set.add_bool("SimilarityLM", "Seminumerical computation of similarity integrals?", false); set.add_int("SimilarityLmax", "Maximum angular momentum for seminumerical computation", 6); if(argc==2) set.parse(argv[1]); else printf("Using default settings.\n"); set.print(); // Get the tolerance double tol=set.get_double("EMDTol"); // Load checkpoint Checkpoint chkpt(set.get_string("LoadChk"),false); // Load basis set BasisSet basis; chkpt.read(basis); // Load density matrix arma::cx_mat P; arma::mat Pr, Pi; chkpt.read("P",Pr); if(chkpt.exist("P_im")) { chkpt.read("P_im",Pi); P=Pr*COMPLEX1 + Pi*COMPLEXI; } else P=Pr*COMPLEX1; // The projection to calculate int l=0, m=0; std::string lmstr=set.get_string("EMDlm"); if(lmstr.size()) { // Get l and m values std::vector<std::string> lmval=splitline(lmstr); if(lmval.size()!=2) throw std::runtime_error("Invalid specification of l and m values.\n"); l=readint(lmval[0]); m=readint(lmval[1]); } bool adaptive=set.get_bool("EMDAdapt"); // Compute orbital EMDs? if(set.get_string("EMDOrbitals")!="") { // Get orbitals std::vector<std::string> orbs=splitline(set.get_string("EMDOrbitals")); // Polarized calculation? bool restr; chkpt.read("Restricted",restr); if(restr!= (orbs.size()==1)) throw std::runtime_error("Invalid occupancies for spin alpha and beta!\n"); if(l!=0) printf("\nComputing the (%i %+i) projection of the orbital EMD.\n",l,m); for(size_t ispin=0;ispin<orbs.size();ispin++) { // Indices of orbitals to include. std::vector<size_t> idx=parse_range(orbs[ispin]); // Change into C++ indexing for(size_t i=0;i<idx.size();i++) idx[i]--; // Read orbitals arma::mat C; if(restr) chkpt.read("C",C); else { if(ispin==0) chkpt.read("Ca",C); else chkpt.read("Cb",C); } for(size_t i=0;i<idx.size();i++) { // Names of output files char emdname[80]; char momname[80]; char Jname[80]; char Jintname[80]; char suffix[80]; if(l==0) sprintf(suffix,".txt"); else sprintf(suffix,"_%i_%i.txt",l,m); if(restr) { sprintf(emdname,"emd-%i%s",(int) idx[i]+1,suffix); sprintf(momname,"moments-%i%s",(int) idx[i]+1,suffix); sprintf(Jname,"compton-%i%s",(int) idx[i]+1,suffix); sprintf(Jintname,"compton-interp-%i%s",(int) idx[i]+1,suffix); } else { if(ispin==0) { sprintf(emdname,"emd-a-%i%s",(int) idx[i]+1,suffix); sprintf(momname,"moments-a-%i%s",(int) idx[i]+1,suffix); sprintf(Jname,"compton-a-%i%s",(int) idx[i]+1,suffix); sprintf(Jintname,"compton-interp-a-%i%s",(int) idx[i]+1,suffix); } else { sprintf(emdname,"emd-b-%i%s",(int) idx[i]+1,suffix); sprintf(momname,"moments-b-%i%s",(int) idx[i]+1,suffix); sprintf(Jname,"compton-b-%i%s",(int) idx[i]+1,suffix); sprintf(Jintname,"compton-interp-b-%i%s",(int) idx[i]+1,suffix); } } // Generate dummy density matrix arma::cx_mat Pdum=C.col(idx[i])*arma::trans(C.col(idx[i]))*COMPLEX1; Timer temd; GaussianEMDEvaluator *poseval=new GaussianEMDEvaluator(basis,Pdum,l,std::abs(m)); GaussianEMDEvaluator *negeval; if(m!=0) negeval=new GaussianEMDEvaluator(basis,Pdum,l,-std::abs(m)); else negeval=NULL; EMD emd(poseval, negeval, 1, l, m); if(adaptive) { emd.initial_fill(); if(l==0 && m==0) emd.find_electrons(); emd.optimize_moments(true,tol); } else emd.fixed_fill(); emd.save(emdname); emd.moments(momname); if(l==0 && m==0) { emd.compton_profile(Jname); emd.compton_profile_interp(Jintname); } delete poseval; if(m!=0) delete negeval; } } } if(set.get_bool("DoEMD")) { t.print_time(); printf("\nCalculating EMD properties.\n"); printf("Please read and cite the reference:\n%s\n%s\n%s\n", \ "J. Lehtola, M. Hakala, J. Vaara and K. Hämäläinen", \ "Calculation of isotropic Compton profiles with Gaussian basis sets", \ "Phys. Chem. Chem. Phys. 13 (2011), pp. 5630 - 5641."); if(l!=0) printf("\nComputing the (%i %+i) projection of the EMD.\n",l,m); else printf("\nComputing the isotropic projection of the EMD.\n"); // Amount of electrons is int Nel; chkpt.read("Nel",Nel); // Construct EMD evaluators Timer temd; GaussianEMDEvaluator *poseval=new GaussianEMDEvaluator(basis,P,l,std::abs(m)); GaussianEMDEvaluator *negeval; if(m!=0) negeval=new GaussianEMDEvaluator(basis,P,l,-std::abs(m)); else negeval=NULL; temd.set(); EMD emd(poseval, negeval, Nel, l, m); if(adaptive) { emd.initial_fill(); if(l==0 && m==0) emd.find_electrons(); emd.optimize_moments(true,tol); } else emd.fixed_fill(); if(l==0 && m==0) { emd.save("emd.txt"); emd.moments("moments.txt"); emd.compton_profile("compton.txt"); emd.compton_profile_interp("compton-interp.txt"); } else { char fname[80]; sprintf(fname,"emd_%i_%i.txt",l,m); emd.save(fname); sprintf(fname,"moments_%i_%i.txt",l,m); emd.moments(fname); } if(l==0 && m==0) printf("Calculating isotropic EMD properties took %s.\n",temd.elapsed().c_str()); else printf("Calculating projected EMD properties took %s.\n",temd.elapsed().c_str()); delete poseval; if(m!=0) delete negeval; } // Do EMD on a cube? if(stricmp(set.get_string("EMDCube"),"")!=0) { t.print_time(); Timer temd; // Form grid in p space. std::vector<double> px, py, pz; parse_cube(set.get_string("EMDCube"),px,py,pz); // Calculate EMD on cube emd_cube(basis,P,px,py,pz); printf("Calculating EMD on a cube took %s.\n",temd.elapsed().c_str()); } // Compute similarity? if(stricmp(set.get_string("Similarity"),"")!=0) { // Load checkpoint Checkpoint simchk(set.get_string("Similarity"),false); // Get grid size std::vector<std::string> gridsize=splitline(set.get_string("SimilarityGrid")); if(gridsize.size()!=2) { throw std::runtime_error("Invalid grid size!\n"); } int nrad=readint(gridsize[0]); int lmax=readint(gridsize[1]); int radlmax=set.get_int("SimilarityLmax"); // Load basis set BasisSet simbas; simchk.read(simbas); // Load density matrix arma::mat simPr, simPi; arma::cx_mat simP; simchk.read("P",simPr); if(simchk.exist("P_im")) { simchk.read("P_im",simPi); simP=simPr*COMPLEX1 + simPi*COMPLEXI; } else simP=simPr*COMPLEX1; // Compute momentum density overlap arma::cube ovl; if(set.get_bool("SimilarityLM")) ovl=emd_overlap_semi(basis,P,simbas,simP,nrad,radlmax); else ovl=emd_overlap(basis,P,simbas,simP,nrad,lmax); // Amount of electrons int Nela, Nelb; chkpt.read("Nel", Nela); simchk.read("Nel", Nelb); // Shape function overlap arma::cube sh=emd_similarity(ovl,Nela,Nelb); sh.slice(0).save("similarity.dat",arma::raw_ascii); sh.slice(1).save("similarity_avg.dat",arma::raw_ascii); for(int s=0;s<2;s++) { if(s) { printf("%2s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\n","k","S0(AA)","S0(BB)","S0(AB)","I0(AA)","I0(BB)","I0(AB)","D0(AB)"); for(int k=-1;k<3;k++) // Vandenbussche don't include p^2 in the spherical average printf("%2i\t%e\t%e\t%e\t%e\t%e\t%e\t%e\n", k+1, sh(k+1,0,s), sh(k+1,1,s), sh(k+1,2,s), sh(k+1,3,s), sh(k+1,4,s), sh(k+1,5,s), sh(k+1,6,s)); } else { printf("%2s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\n","k","S(AA)","S(BB)","S(AB)","I(AA)","I(BB)","I(AB)","D(AB)"); for(int k=-1;k<3;k++) printf("%2i\t%e\t%e\t%e\t%e\t%e\t%e\t%e\n", k, sh(k+1,0,s), sh(k+1,1,s), sh(k+1,2,s), sh(k+1,3,s), sh(k+1,4,s), sh(k+1,5,s), sh(k+1,6,s)); } printf("\n"); } } return 0; }