From b5571ec807e10822468b5c386e484af3d699ce32 Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Thu, 30 Sep 2021 13:46:49 -0400 Subject: [PATCH] Revert clang-format related changes --- src/QMCTools/ppconvert/src/NLPPClass.cc | 2565 ++++++++--------- src/QMCTools/ppconvert/src/XMLWriterClass2.cc | 129 +- .../ppconvert/src/common/CubicSplineCommon.h | 8 +- src/QMCTools/ppconvert/src/common/DFTAtom.cc | 168 +- .../ppconvert/src/common/GeneralPot.cc | 42 +- src/QMCTools/ppconvert/src/common/Grid.h | 2 +- src/QMCTools/ppconvert/src/common/NLPP.cc | 390 +-- src/QMCTools/ppconvert/src/common/RadialWF.cc | 426 +-- .../ppconvert/src/common/SplinePot.cc | 43 +- 9 files changed, 1851 insertions(+), 1922 deletions(-) diff --git a/src/QMCTools/ppconvert/src/NLPPClass.cc b/src/QMCTools/ppconvert/src/NLPPClass.cc index 1504f22856..4dec3f5c4e 100644 --- a/src/QMCTools/ppconvert/src/NLPPClass.cc +++ b/src/QMCTools/ppconvert/src/NLPPClass.cc @@ -11,6 +11,9 @@ ////////////////////////////////////////////////////////////////////////////////////// + + + #include "NLPPClass.h" #include "XMLWriterClass2.h" #include "ParserClass.h" @@ -20,15 +23,17 @@ #include #include -void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl) +void +ChannelPotentialClass::WriteChannelLog (XMLWriterClass &writer, + bool writeVl) { std::string channels[] = {"s", "p", "d", "f", "g", "h", "i", "j"}; // Use a logarithmic grid: // r(i) = a*(exp(b*i) - 1) const int numPoints = 2001; - double end = Vl.grid.End(); - double step = 0.00625; - double scale = end / (expm1(step * (numPoints - 1))); + double end = Vl.grid.End(); + double step = 0.00625; + double scale = end/(expm1(step*(numPoints-1))); if (writeVl) writer.StartElement("vps"); else @@ -36,8 +41,7 @@ void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl writer.WriteAttribute("principal-n", n_principal); writer.WriteAttribute("l", channels[l]); writer.WriteAttribute("spin", -1); - if (writeVl) - { + if (writeVl) { writer.WriteAttribute("cutoff", Cutoff); writer.WriteAttribute("occupation", Occupation); } @@ -50,17 +54,14 @@ void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl writer.WriteAttribute("npts", numPoints); writer.EndElement(); // "grid" std::vector data; - for (int i = 0; i < numPoints; i++) - { - double r = scale * (expm1(step * i)); - if (writeVl) - { - double rmin = std::min(r, Vl.grid.End()); + for (int i=0; i data; - for (int i = 0; i < numPoints; i++) - { - double r = dr * (double)i; - if (writeVl) - { - r = std::min(r, ul.grid.End()); + for (int i=0; i vl(numPoints); - for (int ir = 0; ir < numPoints; ir++) - { - double r = (double)ir * dr; - vl[ir] = (ir == 0) ? pot.Vl(0.0) : pot.Vlr(r) / r; + for (int ir=0; ir ul(numPoints); - for (int ir = 0; ir < numPoints; ir++) - { - double r = (ir == 0) ? 1.0e-8 : (double)ir * dr; - ul[ir] = pot.ul(r) / r; + for (int ir=0; ir input/default value)\n0 0\n"); - fprintf(fout, "Number of grid points\n%d\n", numPoints); - fprintf(fout, "R(i) in atomic units\n"); - for (int i = 0; i < numPoints; i++) - { - double r = (double)i / (double)(numPoints - 1) * rMax; - fprintf(fout, " %22.16e\n", r); + fprintf (fout, "Pseudopotential in real space for %s\n", + ZToSymbolMap[AtomicNumber].c_str()); + fprintf (fout, "Atomic number and pseudo-charge\n%d %1.2f\n", + AtomicNumber, PseudoCharge); + fprintf (fout, "Energy units (rydberg/hartree/ev):\nrydberg\n"); + fprintf (fout, "Angular momentum of local component (0=s,1=p,2=d..)\n%d\n", + LocalChannel); + fprintf (fout, "NLRULE override (1) VMC/DMC (2) config gen " + "(0 ==> input/default value)\n0 0\n"); + fprintf (fout, "Number of grid points\n%d\n", + numPoints); + fprintf (fout, "R(i) in atomic units\n"); + for (int i=0; i& data, int indent) +void +PseudoClass::Write4Block (FILE *fout, std::vector& data, int indent) { int N = data.size(); - for (int i = 0; i < N / 4; i++) - { - for (int j = 0; j < indent; j++) - fprintf(fout, " "); - fprintf(fout, "%17.11e %1.17e %1.17e %1.17e\n", data[4 * i + 0], data[4 * i + 1], data[4 * i + 2], data[4 * i + 3]); + for (int i=0; i\n"); - fprintf(fout, "Generated using ppconvert\n"); + fprintf (fout, "\n"); + fprintf (fout, "Generated using ppconvert\n"); // Get date - time_t now = time(NULL); - struct tm& ltime = *(localtime(&now)); + time_t now = time(NULL); + struct tm <ime = *(localtime (&now)); std::stringstream date; int year = ltime.tm_year % 100; int mon = ltime.tm_mon + 1; int day = ltime.tm_mday; - date << ((mon < 10) ? "0" : "") << mon << "/"; - date << ((day < 10) ? "0" : "") << day << "/"; - date << ((year < 10) ? "0" : "") << year; - fprintf(fout, "Author: Kenneth P. Esler Generation date: %s\n", date.str().c_str()); + date << ((mon<10) ? "0" : "") << mon << "/"; + date << ((day<10) ? "0" : "") << day << "/"; + date << ((year<10) ? "0" : "") << year; + fprintf (fout, "Author: Kenneth P. Esler Generation date: %s\n", + date.str().c_str()); - fprintf(fout, "\n"); + fprintf (fout, "\n"); // Write PP_HEADER section - fprintf(fout, "\n"); - fprintf(fout, " 0 Version Number\n"); - fprintf(fout, " %2s Element\n", ZToSymbolMap[AtomicNumber].c_str()); - fprintf(fout, " NC Norm - Conserving pseudopotential\n"); - fprintf(fout, " F Nonlinear Core Correction\n"); + fprintf (fout, "\n"); + fprintf (fout, " 0 Version Number\n"); + fprintf (fout, " %2s Element\n", + ZToSymbolMap[AtomicNumber].c_str()); + fprintf (fout, " NC Norm - Conserving pseudopotential\n"); + fprintf (fout, " F Nonlinear Core Correction\n"); std::string F_EX, F_CORR, F_XC_GRAD, F_CORR_GRAD; - F_EX = "SLA"; - F_CORR = "PW"; - F_XC_GRAD = "PBE"; + F_EX = "SLA"; + F_CORR = "PW"; + F_XC_GRAD = "PBE"; F_CORR_GRAD = "PBE"; - fprintf(fout, " %4s %4s %4s %4s Exchange-Corelation functional\n", F_EX.c_str(), F_CORR.c_str(), F_XC_GRAD.c_str(), - F_CORR_GRAD.c_str()); - fprintf(fout, " %1.10f Z valence\n", PseudoCharge); - fprintf(fout, " %1.10f Total energy\n", TotalEnergy); - fprintf(fout, " %3.6f %3.6f Suggested cutoff for wfc and rho\n", 0.0, 0.0); - fprintf(fout, " %ld Max angular momentum component\n", ChannelPotentials.size() - 1); - fprintf(fout, " %4d Number of points in mesh\n", N); - fprintf(fout, " %ld %ld Number of Wavefunctions, Number of Projectors\n", ChannelPotentials.size(), - ChannelPotentials.size() - 1); - fprintf(fout, " WaveFunctions nl l occ \n"); - for (int l = 0; l < ChannelPotentials.size(); l++) - fprintf(fout, " %d%s %d %1.4f\n", ChannelPotentials[l].n_principal, ChannelMap[l].c_str(), - ChannelPotentials[l].l, ChannelPotentials[l].Occupation); - - fprintf(fout, "\n"); + fprintf (fout, " %4s %4s %4s %4s Exchange-Corelation functional\n", + F_EX.c_str(), F_CORR.c_str(), F_XC_GRAD.c_str(), F_CORR_GRAD.c_str()); + fprintf (fout, " %1.10f Z valence\n", + PseudoCharge); + fprintf (fout, " %1.10f Total energy\n", TotalEnergy); + fprintf (fout, " %3.6f %3.6f Suggested cutoff for wfc and rho\n", + 0.0, 0.0); + fprintf (fout, " %ld Max angular momentum component\n", + ChannelPotentials.size()-1); + fprintf (fout, " %4d Number of points in mesh\n", + N); + fprintf (fout, " %ld %ld Number of Wavefunctions, Number of Projectors\n", ChannelPotentials.size(), ChannelPotentials.size()-1); + fprintf (fout, " WaveFunctions nl l occ \n"); + for (int l=0; l\n"); // Write PP_MESH section - fprintf(fout, "\n"); - fprintf(fout, " \n"); - Write4Block(fout, PotentialGrid.Points()); - fprintf(fout, " \n"); - fprintf(fout, " \n"); + fprintf (fout, "\n"); + fprintf (fout, " \n"); + Write4Block (fout, PotentialGrid.Points()); + fprintf (fout, " \n"); + fprintf (fout, " \n"); std::vector dr(N); - for (int i = 1; i < (N - 1); i++) - dr[i] = 0.5 * (PotentialGrid[i + 1] - PotentialGrid[i - 1]); - dr[0] = 2.0 * dr[1] - dr[2]; - dr[N - 1] = 2.0 * dr[N - 2] - dr[N - 3]; + for (int i=1; i<(N-1); i++) + dr[i] = 0.5*(PotentialGrid[i+1]-PotentialGrid[i-1]); + dr[0] = 2.0*dr[ 1 ]-dr[ 2 ]; + dr[N-1] = 2.0*dr[N-2]-dr[N-3]; - Write4Block(fout, dr); - fprintf(fout, " \n"); - fprintf(fout, "\n"); + Write4Block (fout, dr); + fprintf (fout, " \n"); + fprintf (fout, "\n"); // Write PP_LOCAL section - fprintf(fout, "\n"); + fprintf (fout, "\n"); std::vector vloc(N); - for (int i = 0; i < N; i++) - vloc[i] = 2.0 * ChannelPotentials[LocalChannel].Vl(i); // /PotentialGrid[i]; + for (int i=0; i\n"); + Write4Block (fout, vloc); + fprintf (fout, "\n"); // Write the nonlocal section - fprintf(fout, "\n"); + fprintf (fout, "\n"); int betaNum = 1; - for (int l = 0; l < ChannelPotentials.size(); l++) - if (l != LocalChannel) - { + for (int l=0; l beta(N); - for (int i = 0; i < N; i++) - { - double Vloc = ChannelPotentials[LocalChannel].Vlr(i); - double Vl = ChannelPotentials[l].Vlr(i); - double ul = ChannelPotentials[l].ul(i); - double r = PotentialGrid[i]; - beta[i] = 2.0 * ul * (Vl - Vloc) / r; - //beta[i] = 2.0*ul*(Vl - Vloc); - //beta[i] = 2.0*r*ul*(Vl - Vloc); + for (int i=0; i\n"); - fprintf(fout, " %d %d Beta L\n", betaNum, l); - fprintf(fout, " %d \n", N); - Write4Block(fout, beta, 4); - fprintf(fout, " \n"); + beta[0] = 2.0*ChannelPotentials[l].ul(0.0)* + (ChannelPotentials[l].Vlr(1.0e-7)-ChannelPotentials[LocalChannel].Vlr(1.0e-7))/1.0e-7; +// beta[0] = 2.0*ChannelPotentials[l].ul(0.0)* +// (ChannelPotentials[l].Vl(1.0e-7)-ChannelPotentials[LocalChannel].Vl(1.0e-7)); + fprintf (fout, " \n"); + fprintf (fout, " %d %d Beta L\n", betaNum, l); + fprintf (fout, " %d \n", N); + Write4Block (fout, beta, 4); + fprintf (fout, " \n"); betaNum++; } // Write D_ij matrix - fprintf(fout, " \n"); - fprintf(fout, " %ld Number of nonzero Dij\n", ChannelPotentials.size() - 1); + fprintf (fout, " \n"); + fprintf (fout, " %ld Number of nonzero Dij\n", + ChannelPotentials.size()-1); betaNum = 1; // Compute D_ij matrix. In our case, with single projectors, D_ij // is diagonal. The elements are // D_ll = 1.0/ // We will numerically integrate with Simpson's rule - for (int l = 0; l < ChannelPotentials.size(); l++) - if (l != LocalChannel) - { - const int M = 100000; + for (int l=0; l\n"); - fprintf(fout, "\n"); + fprintf (fout, " \n"); + fprintf (fout, "\n"); // Write PP_PSWFC section - fprintf(fout, "\n"); - for (int l = 0; l < ChannelPotentials.size(); l++) - { - ChannelPotentialClass& pot = ChannelPotentials[l]; - fprintf(fout, "%d%s %d %6.4f Wavefunction\n", pot.n_principal, ChannelMap[l].c_str(), l, - pot.Occupation); + fprintf (fout, "\n"); + for (int l=0; l u(N); - for (int i = 0; i < N; i++) + for (int i=0; i\n"); + fprintf (fout, "\n"); // Write PP_RHOATOM section - fprintf(fout, "\n"); + fprintf (fout, "\n"); std::vector rho_at(N); - for (int i = 0; i < N; i++) - { + for (int i=0; i\n"); + fprintf (fout, "\n"); // Close the file - fclose(fout); + fclose (fout); } -void PseudoClass::WriteFHI(std::string fileName) +void +PseudoClass::WriteFHI (std::string fileName) { - const double amesh = 1.013084867359809; + const double amesh = 1.013084867359809; const int numPoints = 1118; - FILE* fout = fopen(fileName.c_str(), "w"); - assert(fout != NULL); + FILE *fout = fopen (fileName.c_str(), "w"); + assert (fout != NULL); // Write ABINIT header - fprintf(fout, "Written by ppconvert: %s psuedopotential\n", ZToSymbolMap[AtomicNumber].c_str()); - time_t now = time(NULL); - struct tm& ltime = *(localtime(&now)); + fprintf (fout, "Written by ppconvert: %s psuedopotential\n", + ZToSymbolMap[AtomicNumber].c_str()); + time_t now = time(NULL); + struct tm <ime = *(localtime (&now)); std::stringstream date; int year = ltime.tm_year % 100; int mon = ltime.tm_mon + 1; int day = ltime.tm_mday; - date << ((year < 10) ? "0" : "") << year; - date << ((mon < 10) ? "0" : "") << mon; - date << ((day < 10) ? "0" : "") << day; - - fprintf(fout, - "%9.5f %9.5f %s" - " zatom, zion, pspdat\n", - (double)AtomicNumber, PseudoCharge, date.str().c_str()); - - fprintf(fout, - " 6 7 %ld %d %d 0.0000 " - "pspcod,pspxc,lmax,lloc,mmax,r2well\n", - ChannelPotentials.size() - 1, LocalChannel, numPoints); - fprintf(fout, - " 0.00000 0.00000 0.00000 " - "rchrg,fchrg,qchrg\n"); - fprintf(fout, - "5 --- reserved for future features\n" - "6 --- reserved for future features\n" - "7 --- Here follows the cpi file in the fhi98pp format -\n"); + date << ((year<10) ? "0" : "") << year; + date << ((mon<10) ? "0" : "") << mon; + date << ((day<10) ? "0" : "") << day; + + fprintf (fout, "%9.5f %9.5f %s" + " zatom, zion, pspdat\n", (double)AtomicNumber, + PseudoCharge, date.str().c_str()); + + fprintf (fout, " 6 7 %ld %d %d 0.0000 " + "pspcod,pspxc,lmax,lloc,mmax,r2well\n", + ChannelPotentials.size()-1, LocalChannel, numPoints); + fprintf (fout, " 0.00000 0.00000 0.00000 " + "rchrg,fchrg,qchrg\n"); + fprintf (fout, "5 --- reserved for future features\n" + "6 --- reserved for future features\n" + "7 --- Here follows the cpi file in the fhi98pp format -\n"); // Write FHI file proper - fprintf(fout, "%d %ld\n", (int)round(PseudoCharge), ChannelPotentials.size()); - for (int i = 0; i < 10; i++) - fprintf(fout, "0.0 0.0 0.0\n"); - - for (int l = 0; l < ChannelPotentials.size(); l++) - { - fprintf(fout, "%d %1.18f\n", numPoints, amesh); - double r = 5.848035476425733e-05; + fprintf (fout, "%d %ld\n", (int)round(PseudoCharge), + ChannelPotentials.size()); + for (int i=0; i<10; i++) + fprintf (fout, "0.0 0.0 0.0\n"); + + for (int l=0; l= ChannelPotentials[l].Vl.grid.End()) - Vl = -1.0 * PseudoCharge / r; + Vl = -1.0*PseudoCharge/r; else - Vl = ChannelPotentials[l].Vl(r); // /r; + Vl = ChannelPotentials[l].Vl(r); // /r; double Vlold = Vl; - Vl = ChannelPotentials[l].Vlr(r) / r; + Vl = ChannelPotentials[l].Vlr(r)/r; if (i == 0) - Vl = ChannelPotentials[l].Vl(0.0); + Vl = ChannelPotentials[l].Vl(0.0); // fprintf (stderr, "r = %1.10f Interp diff = %1.8e\n", r, Vl-Vlold); - fprintf(fout, "%23.16e ", Vl); - if ((i % 3) == 2) - fprintf(fout, "\n"); + fprintf (fout, "%23.16e ", Vl); + if ((i%3)==2) + fprintf (fout, "\n"); } } // Now write out radial wave functions - for (int l = 0; l < ChannelPotentials.size(); l++) - { - fprintf(fout, "%d = l for CASINO wave function\n", l); - for (int i = 0; i < mmax; i++) - { - double x = (double)i / (double)(mmax - 1); - x += 0.01; - double r = 100.0 * x * x * x * x * x - 1.0e-8; - double ul; - double rend = ChannelPotentials[l].ul.grid.End(); - if (r >= rend) - { - int i = ChannelPotentials[l].ul.grid.NumPoints(); - while (fabs(ChannelPotentials[l].ul(i)) == 0.0) - i--; - double r2 = ChannelPotentials[l].ul.grid[i]; - double r1 = ChannelPotentials[l].ul.grid[i - 10]; - double u2 = ChannelPotentials[l].ul(i); - double u1 = ChannelPotentials[l].ul(i - 10); - double alpha = log(u1 / u2) / (r2 - r1); - // rend = min (rend, 60.0); - // double uend = ChannelPotentials[l].ul(rend); - // double alpha = log (ChannelPotentials[l].ul(rend-1.0)/uend); - //cerr << "alpha = " << alpha << " rend = " << r2 << " u2 = " << u2 << endl; - // ul = uend * exp(-alpha*(r-rend)); - ul = u2 * exp(-alpha * (r - r2)); + for (int l=0; l= rend) { + int i=ChannelPotentials[l].ul.grid.NumPoints(); + while (fabs(ChannelPotentials[l].ul(i)) == 0.0) i--; + double r2 = ChannelPotentials[l].ul.grid[i]; + double r1 = ChannelPotentials[l].ul.grid[i-10]; + double u2 = ChannelPotentials[l].ul(i); + double u1 = ChannelPotentials[l].ul(i-10); + double alpha = log(u1/u2)/(r2-r1); + // rend = min (rend, 60.0); + // double uend = ChannelPotentials[l].ul(rend); + // double alpha = log (ChannelPotentials[l].ul(rend-1.0)/uend); + //cerr << "alpha = " << alpha << " rend = " << r2 << " u2 = " << u2 << endl; + // ul = uend * exp(-alpha*(r-rend)); + ul = u2 * exp(-alpha*(r - r2)); + } + else + ul= ChannelPotentials[l].ul(r); + fprintf (fout, "%23.16e ", ul); + if ((i%3)==2) + fprintf (fout, "\n"); } - else - ul = ChannelPotentials[l].ul(r); - fprintf(fout, "%23.16e ", ul); - if ((i % 3) == 2) - fprintf(fout, "\n"); - } } - fclose(fout); + fclose (fout); } -void PseudoClass::WriteASCII() +void +PseudoClass::WriteASCII() { - FILE* fout = fopen("pp.dat", "w"); - for (int i = 1; i < PotentialGrid.NumPoints(); i++) - { - double r = PotentialGrid[i]; - fprintf(fout, "%24.16e ", r); - for (int l = 0; l < ChannelPotentials.size(); l++) - fprintf(fout, "%24.16e ", ChannelPotentials[l].Vl(r)); // /r); - fprintf(fout, "\n"); + FILE *fout = fopen ("pp.dat", "w"); + for (int i=1; i gridPoints, Vlocal, Vlocalr; - FILE* fout = fopen("Vlocal.dat", "w"); - for (double r = 1.0e-8; r < 150.0; r += 0.01) - { - gridPoints.push_back(r); - double Vloc = (c0 / r) * (expm1(-exp0 * r * r)) + c1 * r * exp(-exp1 * r * r) + c2 * exp(-exp2 * r * r); - double Vlocr = (c0) * (expm1(-exp0 * r * r)) + c1 * r * r * exp(-exp1 * r * r) + c2 * r * exp(-exp2 * r * r); + FILE *fout = fopen ("Vlocal.dat", "w"); + for (double r=1.0e-8; r<150.0; r+=0.01) { + gridPoints.push_back (r); + double Vloc = (c0/r)*(expm1(-exp0*r*r)) + + c1*r*exp(-exp1*r*r) + + c2*exp(-exp2*r*r); + double Vlocr = (c0)*(expm1(-exp0*r*r)) + + c1*r*r*exp(-exp1*r*r) + + c2*r*exp(-exp2*r*r); Vlocal.push_back(Vloc); Vlocalr.push_back(Vlocr); - fprintf(fout, "%1.16e %1.16e %1.16e\n", r, Vloc, Vlocr); + fprintf (fout, "%1.16e %1.16e %1.16e\n", r, Vloc, Vlocr); } - fclose(fout); + fclose (fout); int local = numProjectors; - if (LocalChannel < 0) - LocalChannel = local; - PotentialGrid.Init(gridPoints); + if (LocalChannel<0) LocalChannel = local; + PotentialGrid.Init (gridPoints); ChannelPotentials[local].Vl.Init(PotentialGrid, Vlocal); ChannelPotentials[local].Vlr.Init(PotentialGrid, Vlocalr); ChannelPotentials[local].l = local; // Now read nonlocal component - assert(parser.FindToken("Non-local component:")); - assert(parser.FindToken("Proj.")); - for (int l = 0; l < numProjectors; l++) - { + assert (parser.FindToken ("Non-local component:")); + assert (parser.FindToken ("Proj.")); + for (int l=0; l Vl(gridPoints.size()), Vlr(gridPoints.size()); - for (int i = 0; i < gridPoints.size(); i++) - { + for (int i=0; i 1.0e-10) - { + assert (parser.ReadDouble(chrg)); + if(fabs(chrg-PseudoCharge) > 1.0e-10) { std::cerr << "PseudoCharge = " << PseudoCharge << std::endl; std::cerr << "chrg = " << chrg << std::endl; } // Read number of channels and resize int numChannels; - assert(parser.ReadInt(numChannels)); + assert (parser.ReadInt(numChannels)); ChannelPotentials.resize(numChannels); // Skip the next 10 lines - for (int i = 0; i < 11; i++) - assert(parser.FindToken("\n")); + for (int i=0; i<11; i++) + assert (parser.FindToken("\n")); // Read the number of grid points - for (int l = 0; l < numChannels; l++) - { + for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), Vlr(numPoints); - for (int m = 0; m < numPoints; m++) - { + assert (parser.ReadInt(numPoints)); + assert (parser.ReadDouble(a_ratio)); + std::vector points(numPoints), ul(numPoints), Vl(numPoints), + Vlr(numPoints); + for (int m=0; m 0) && !diff) - { + int n = PotentialGrid.NumPoints()-1; + bool diff = false; + while ((n>0) && !diff) { double r = PotentialGrid[n]; - rmax = r; - for (int l1 = 0; l1 < numChannels; l1++) - { + rmax = r; + for (int l1=0; l1 1.0e-5) - diff = true; + for (int l2=l1+1; l2 1.0e-5) + diff = true; } } n--; } - for (int l = 0; l < ChannelPotentials.size(); l++) + for (int l=0; l beta, u, V; KBprojector() {} - KBprojector(int l_, std::vector beta_) : l(l_), beta(beta_) {} + KBprojector(int l_, std::vector beta_) : + l(l_), beta(beta_) {} }; -bool PseudoClass::ReadUPF_PP(std::string fileName) +bool +PseudoClass::ReadUPF_PP (std::string fileName) { MemParserClass parser; - if (!parser.OpenFile(fileName)) - { + if (!parser.OpenFile (fileName)) { std::cerr << "Could not open file \"" << fileName << "\". Exitting.\n"; exit(-1); } std::string temp; - assert(parser.FindToken("")); - assert(parser.NextLine()); + assert(parser.FindToken("")); assert(parser.NextLine()); // Skip version number assert(parser.NextLine()); std::string element, ppType, coreCorrection; - assert(parser.ReadWord(element)); - assert(parser.NextLine()); + assert(parser.ReadWord(element)); assert(parser.NextLine()); assert(SymbolToZMap.find(element) != SymbolToZMap.end()); AtomicNumber = SymbolToZMap[element]; // cerr << "Element = \"" << element << "\"\n"; assert(parser.ReadWord(ppType)); - if (ppType != "NC") - { - std::cerr << "Psuedopotential type \"" << ppType << "\" is not norm-conserving.\n"; + if (ppType != "NC") { + std::cerr << "Psuedopotential type \"" << ppType + << "\" is not norm-conserving.\n"; abort(); } - assert(parser.NextLine()); - assert(parser.ReadWord(coreCorrection)); - assert(parser.NextLine()); - if (coreCorrection != "F" && coreCorrection != "f" && coreCorrection != "false" && coreCorrection != "False" && - coreCorrection != ".F." && coreCorrection != ".f" && coreCorrection != "FALSE") - { + assert (parser.NextLine()); + assert (parser.ReadWord(coreCorrection)); assert(parser.NextLine()); + if (coreCorrection != "F" && coreCorrection != "f" && + coreCorrection != "false" && coreCorrection != "False" && + coreCorrection != ".F." && coreCorrection != ".f" && + coreCorrection != "FALSE") { std::cerr << "It appears that a nonlinear core correction was used. Cannot convert PP.\n"; abort(); } @@ -1309,45 +1230,42 @@ bool PseudoClass::ReadUPF_PP(std::string fileName) assert(parser.NextLine()); int numPoints; - assert(parser.ReadInt(numPoints)); - assert(parser.NextLine()); + assert(parser.ReadInt(numPoints)); assert(parser.NextLine()); int numWF, numProj; - assert(parser.ReadInt(numWF)); - assert(parser.ReadInt(numProj)); - int numChannels = numProj + 1; + assert (parser.ReadInt(numWF)); assert(parser.ReadInt(numProj)); + int numChannels = numProj+1; ChannelPotentials.resize(numChannels); assert(parser.FindToken("Wavefunctions")); - // for (int i=0; i")); assert(parser.FindToken("")); assert(parser.FindToken("")); std::vector r(numPoints), dr(numPoints); - for (int i = 0; i < numPoints; i++) + for (int i=0; i")); PotentialGrid.Init(r); assert(parser.FindToken("")); - for (int i = 0; i < numPoints; i++) + for (int i=0; i")); assert(parser.FindToken("")); assert(parser.FindToken("")); std::vector Vlocal(numPoints); - for (int i = 0; i < numPoints; i++) - { + for (int i=0; i lmap; + std::map lmap; std::vector projectors; - for (int proj = 0; proj < numProj; proj++) - { - assert(parser.FindToken("")); + for (int proj=0; proj")); int Beta; - assert(parser.ReadInt(Beta)); - assert(Beta == (proj + 1)); + assert (parser.ReadInt(Beta)); + assert(Beta == (proj+1)); int l; - assert(parser.ReadInt(l)); - parser.NextLine(); + assert (parser.ReadInt(l)); parser.NextLine(); lmap[l] = proj; // fprintf (stderr, "Found a projector for l=%d\n", l); int npt; - assert(parser.ReadInt(npt)); + assert (parser.ReadInt(npt)); std::vector beta(numPoints); - for (int ir = 0; ir < numPoints; ir++) + for (int ir=0; ir")); + assert (parser.FindToken("")); projectors.push_back(KBprojector(l, beta)); } assert(parser.FindToken("")); - int llocal = 0; - while (lmap.find(llocal) != lmap.end()) - llocal++; + int llocal=0; + while (lmap.find(llocal) != lmap.end()) llocal++; LocalChannel = llocal; // fprintf (stderr, "First channel without a projector=%d\n", llocal); ChannelPotentials[llocal].Vl.Init(PotentialGrid, Vlocal); std::vector Vlocal_r(numPoints); - for (int ir = 0; ir < numPoints; ir++) - Vlocal_r[ir] = r[ir] * Vlocal[ir]; + for (int ir=0; ir wf(numPoints); - for (int ir = 0; ir < numPoints; ir++) - assert(parser.ReadDouble(wf[ir])); + for (int ir=0; ir Vl(numPoints), Vlr(numPoints); - for (int ir = 0; ir < numPoints; ir++) - { - Vl[ir] = Vlocal[ir]; - if (wf[ir] != 0.0) - Vl[ir] += proj.beta[ir] / (2.0 * wf[ir]); - Vlr[ir] = r[ir] * Vl[ir]; - } - Vl[0] = 2.0 * Vl[1] - Vl[2]; - Vlr[0] = r[0] * Vl[0]; - - // for (int ir=0; ir Vl(numPoints), Vlr(numPoints); + for (int ir=0; ir 0) && !diff) - { + int n = PotentialGrid.NumPoints()-1; + bool diff = false; + while ((n>0) && !diff) { double r = PotentialGrid[n]; - rmax = r; - for (int l1 = 0; l1 < numChannels; l1++) - { + rmax = r; + for (int l1=0; l1 1.0e-5) - diff = true; + for (int l2=l1+1; l2 1.0e-5) + diff = true; } } n--; } - fprintf(stderr, "rmax = %1.5f numChannels = %d\n", rmax, numChannels); - for (int l = 0; l < ChannelPotentials.size(); l++) + fprintf (stderr, "rmax = %1.5f numChannels = %d\n", rmax, numChannels); + for (int l=0; l 1.0e-10) { - // cerr << "PseudoCharge = " << PseudoCharge << endl; - // cerr << "chrg = " << chrg << endl; - // } - - // // Read number of channels and resize - // int numChannels; - // assert (parser.ReadInt(numChannels)); - // ChannelPotentials.resize(numChannels); - - // // Skip the next 10 lines - // for (int i=0; i<11; i++) - // assert (parser.FindToken("\n")); - - // // Read the number of grid points - // for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), - // Vlr(numPoints); - // for (int m=0; m0) && !diff) { - // double r = PotentialGrid[n]; - // rmax = r; - // for (int l1=0; l1 1.0e-5) - // diff = true; - // } - // } - // n--; - // } - // for (int l=0; l 1.0e-10) { +// cerr << "PseudoCharge = " << PseudoCharge << endl; +// cerr << "chrg = " << chrg << endl; +// } + +// // Read number of channels and resize +// int numChannels; +// assert (parser.ReadInt(numChannels)); +// ChannelPotentials.resize(numChannels); + +// // Skip the next 10 lines +// for (int i=0; i<11; i++) +// assert (parser.FindToken("\n")); + +// // Read the number of grid points +// for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), +// Vlr(numPoints); +// for (int m=0; m0) && !diff) { +// double r = PotentialGrid[n]; +// rmax = r; +// for (int l1=0; l1 1.0e-5) +// diff = true; +// } +// } +// n--; +// } +// for (int l=0; l rPoints; - if (WriteLogGrid) - { + if (WriteLogGrid) { const int numPoints = 2001; - double end = 150.0; - double step = 0.00625; - double scale = end / (expm1(step * (numPoints - 1))); - for (int i = 1; i < numPoints; i++) - rPoints.push_back(scale * (expm1(step * i))); + double end = 150.0; + double step = 0.00625; + double scale = end/(expm1(step*(numPoints-1))); + for (int i=1; i coefs(ngpot), exponents(ngpot); std::vector powers(ngpot); // The local channel is given first - for (int i = 0; i < ngpot; i++) - { - assert(parser.ReadDouble(coefs[i])); - assert(parser.ReadInt(powers[i])); - assert(parser.ReadDouble(exponents[i])); - assert(parser.FindToken("\n")); + for (int i=0; i 1) - { - while (ir > 0 && !done) - { + bool done=false; + int ir = rPoints.size()-1; + if (ChannelPotentials.size() > 1) { + while (ir > 0 && !done) { double vlocal = ChannelPotentials[LocalChannel].Vl(ir); - for (int l = 0; l < ChannelPotentials.size(); l++) - if (ChannelPotentials[l].l != LocalChannel) - if (fabs(ChannelPotentials[l].Vl(ir) - vlocal) > 1.0e-5) - done = true; + for (int l=0; l 1.0e-5) + done = true; ir--; } } - else - { - while (ir > 0 && !done) - { + else { + while (ir > 0 && !done) { double vlocal = ChannelPotentials[LocalChannel].Vl(ir); - double r = rPoints[ir]; - done = fabs(vlocal + PseudoCharge / r) > 1.0e-5; + double r = rPoints[ir]; + done = fabs (vlocal + PseudoCharge/r) > 1.0e-5; ir--; } } - for (int l = 0; l < ChannelPotentials.size(); l++) + for (int l=0; l= '0' && s[pos] <= '9') sint.push_back(s[pos++]); - s.erase(0, pos); - n = atoi(sint.c_str()); + s.erase(0,pos); + n = atoi (sint.c_str()); return true; } -bool ReadDouble(std::string& s, double& x) +bool +ReadDouble (std::string &s, double &x) { - int pos = 0; + int pos=0; std::string sd; - while ((s[pos] >= '0' && s[pos] <= '9') || s[pos] == '.') + while ((s[pos] >= '0' && s[pos] <= '9') || s[pos]=='.') sd.push_back(s[pos++]); - s.erase(0, pos); + s.erase(0,pos); x = strtod(sd.c_str(), (char**)NULL); return true; } @@ -1718,169 +1617,161 @@ Config::Config(std::string s) ChannelRevMap['d'] = 2; ChannelRevMap['f'] = 3; ChannelRevMap['g'] = 4; - while (s.size() > 0) - { + while (s.size() > 0) { int n, l; double occ; - ReadInt(s, n); + ReadInt (s, n); l = ChannelRevMap[s[0]]; - s.erase(0, 1); - assert(s[0] == '('); - s.erase(0, 1); - ReadDouble(s, occ); - assert(s[0] == ')'); - s.erase(0, 1); - States.push_back(State(n, l, occ)); + s.erase(0,1); + assert (s[0] == '('); + s.erase(0,1); + ReadDouble (s, occ); + assert (s[0] == ')'); + s.erase(0,1); + States.push_back (State(n,l,occ)); } } -bool PseudoClass::ReadCASINO_PP(std::string fileName) + +bool +PseudoClass::ReadCASINO_PP (std::string fileName) { MemParserClass parser; - parser.OpenFile(fileName); - - assert(parser.FindToken("pseudo-charge")); - assert(parser.ReadInt(AtomicNumber)); - assert(parser.ReadDouble(PseudoCharge)); - assert(parser.FindToken("(rydberg/hartree/ev)")); - assert(parser.FindToken("\n")); - assert(parser.ReadWord(EnergyUnit)); + parser.OpenFile (fileName); + + assert (parser.FindToken("pseudo-charge")); + assert (parser.ReadInt (AtomicNumber)); + assert (parser.ReadDouble (PseudoCharge)); + assert (parser.FindToken("(rydberg/hartree/ev)")); + assert (parser.FindToken("\n")); + assert (parser.ReadWord(EnergyUnit)); std::cerr << "EnergyUnit = " << EnergyUnit << std::endl; - assert(parser.FindToken("(0=s,1=p,2=d..)")); - assert(parser.ReadInt(LocalChannel)); - assert(parser.FindToken("grid points")); + assert (parser.FindToken("(0=s,1=p,2=d..)")); + assert (parser.ReadInt (LocalChannel)); + assert (parser.FindToken("grid points")); int numGridPoints; - assert(parser.ReadInt(numGridPoints)); - std::vector gridPoints(numGridPoints), Vl(numGridPoints), Vlr(numGridPoints); - assert(parser.FindToken("in")); - assert(parser.ReadWord(LengthUnit)); + assert (parser.ReadInt(numGridPoints)); + std::vector gridPoints(numGridPoints), Vl(numGridPoints), + Vlr(numGridPoints); + assert (parser.FindToken ("in")); + assert (parser.ReadWord(LengthUnit)); std::cerr << "LengthUnit = " << LengthUnit << std::endl; - assert(parser.FindToken("\n")); + assert (parser.FindToken("\n")); // assert (parser.FindToken("atomic units")); - for (int i = 0; i < numGridPoints; i++) - { - assert(parser.ReadDouble(gridPoints[i])); - gridPoints[i] *= UnitToBohrMap[LengthUnit]; + for (int i=0; i ul(numPoints); - for (int i = 0; i < numPoints; i++) - assert(parser.ReadDouble(ul[i])); + for (int i=0; i argList; // input formats - argList.push_back(ParamClass("fhi_pot", true)); + argList.push_back(ParamClass("fhi_pot", true)); argList.push_back(ParamClass("casino_pot", true)); - argList.push_back(ParamClass("bfd_pot", true)); + argList.push_back(ParamClass("bfd_pot", true)); argList.push_back(ParamClass("gamess_pot", true)); argList.push_back(ParamClass("upf_pot", true)); // Projector parameters - argList.push_back(ParamClass("casino_us", true)); - argList.push_back(ParamClass("casino_up", true)); - argList.push_back(ParamClass("casino_ud", true)); - argList.push_back(ParamClass("casino_uf", true)); - argList.push_back(ParamClass("s_ref", true)); - argList.push_back(ParamClass("p_ref", true)); - argList.push_back(ParamClass("d_ref", true)); - argList.push_back(ParamClass("f_ref", true)); - argList.push_back(ParamClass("g_ref", true)); - argList.push_back(ParamClass("xml", true)); - argList.push_back(ParamClass("tm", true)); - argList.push_back(ParamClass("upf", true)); - argList.push_back(ParamClass("fhi", true)); - argList.push_back(ParamClass("fpmd", true)); + argList.push_back(ParamClass("casino_us", true)); + argList.push_back(ParamClass("casino_up", true)); + argList.push_back(ParamClass("casino_ud", true)); + argList.push_back(ParamClass("casino_uf", true)); + argList.push_back(ParamClass("s_ref", true)); + argList.push_back(ParamClass("p_ref", true)); + argList.push_back(ParamClass("d_ref", true)); + argList.push_back(ParamClass("f_ref", true)); + argList.push_back(ParamClass("g_ref", true)); + argList.push_back(ParamClass("xml", true)); + argList.push_back(ParamClass("tm", true)); + argList.push_back(ParamClass("upf", true)); + argList.push_back(ParamClass("fhi", true)); + argList.push_back(ParamClass("fpmd", true)); argList.push_back(ParamClass("casino", true)); argList.push_back(ParamClass("log_grid", false)); argList.push_back(ParamClass("local_channel", true)); @@ -1993,38 +1884,37 @@ int main(int argc, char** argv) CommandLineParserClass parser(argList); bool success = parser.Parse(argc, argv); - if (!success || parser.NumFiles() != 0) - { + if (!success || parser.NumFiles()!=0) { std::cerr << "Usage: ppconvert options\n" - << " Options include: \n" - << " Input formats: \n" - << " --casino_pot fname \n" - << " --fhi_pot fname \n" - << " --upf_pot fname \n" - << " --bfd_pot fname \n" - << " --gamess_pot fname \n" - << " Output formats: \n" - << " --xml fname.xml \n" - << " --tm fname.tm \n" - << " --upf fname.upf \n" - << " --fhi fname.fhi \n" - << " --fpmd fname.xml \n" - << " --casino fname.xml \n" - << " Reference states:\n" - << " --casino_us fname \n" - << " --casino_up fname \n" - << " --casino_ud fname \n" - << " --casino_uf fname \n" - << " --casino_ug fname \n" - << " --s_ref state \n" - << " --p_ref state \n" - << " --d_ref state \n" - << " --f_ref state \n" - << " --g_ref state \n" - << " Other options: \n" - << " --log_grid \n" - << " --local_channel l (l=0(s),1(p),2(d),3(f),..., default largest possible) \n" - << " --density_mix beta (0 <= beta < 1.0, default 0.75) \n"; + << " Options include: \n" + << " Input formats: \n" + << " --casino_pot fname \n" + << " --fhi_pot fname \n" + << " --upf_pot fname \n" + << " --bfd_pot fname \n" + << " --gamess_pot fname \n" + << " Output formats: \n" + << " --xml fname.xml \n" + << " --tm fname.tm \n" + << " --upf fname.upf \n" + << " --fhi fname.fhi \n" + << " --fpmd fname.xml \n" + << " --casino fname.xml \n" + << " Reference states:\n" + << " --casino_us fname \n" + << " --casino_up fname \n" + << " --casino_ud fname \n" + << " --casino_uf fname \n" + << " --casino_ug fname \n" + << " --s_ref state \n" + << " --p_ref state \n" + << " --d_ref state \n" + << " --f_ref state \n" + << " --g_ref state \n" + << " Other options: \n" + << " --log_grid \n" + << " --local_channel l (l=0(s),1(p),2(d),3(f),..., default largest possible) \n" + << " --density_mix beta (0 <= beta < 1.0, default 0.75) \n"; exit(1); } @@ -2044,88 +1934,76 @@ int main(int argc, char** argv) if (parser.Found("casino_pot")) nlpp.ReadCASINO_PP(parser.GetArg("casino_pot")); - else if (parser.Found("bfd_pot")) - nlpp.ReadBFD_PP(parser.GetArg("bfd_pot")); - else if (parser.Found("fhi_pot")) - nlpp.ReadFHI_PP(parser.GetArg("fhi_pot")); - else if (parser.Found("upf_pot")) - nlpp.ReadUPF_PP(parser.GetArg("upf_pot")); - else if (parser.Found("gamess_pot")) - nlpp.ReadGAMESS_PP(parser.GetArg("gamess_pot")); - else - { + else if (parser.Found ("bfd_pot")) + nlpp.ReadBFD_PP (parser.GetArg ("bfd_pot")); + else if (parser.Found ("fhi_pot")) + nlpp.ReadFHI_PP (parser.GetArg ("fhi_pot")); + else if (parser.Found ("upf_pot")) + nlpp.ReadUPF_PP (parser.GetArg ("upf_pot")); + else if (parser.Found ("gamess_pot")) + nlpp.ReadGAMESS_PP (parser.GetArg("gamess_pot")); + else { std::cerr << "Need to specify a potential file with --casino_pot " - << "or --bfd_pot or --fhi_pot or --upf_pot or --gamess_pot.\n"; + << "or --bfd_pot or --fhi_pot or --upf_pot or --gamess_pot.\n"; exit(1); } // Now check how the projectors are specified - if (!nlpp.HaveProjectors()) - { + if (!nlpp.HaveProjectors()) { int numChannels = nlpp.GetNumChannels(); - if (numChannels > 0) - { - if (parser.Found("s_ref")) - nlpp.CalcProjector(parser.GetArg("s_ref"), 0); + if (numChannels > 0) { + if (parser.Found ("s_ref")) + nlpp.CalcProjector (parser.GetArg("s_ref"), 0); else if (parser.Found("casino_us")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_us"), 0); - else - { - std::cerr << "Please specify the s-channel projector with either " - << " --s_ref or --casino_us.\n"; - // exit(-1); + nlpp.ReadCASINO_WF(parser.GetArg("casino_us"), 0); + else { + std::cerr << "Please specify the s-channel projector with either " + << " --s_ref or --casino_us.\n"; + // exit(-1); } } - if (numChannels > 1) - { - if (parser.Found("p_ref")) - nlpp.CalcProjector(parser.GetArg("p_ref"), 1); + if (numChannels > 1) { + if (parser.Found ("p_ref")) + nlpp.CalcProjector (parser.GetArg("p_ref"), 1); else if (parser.Found("casino_up")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_up"), 1); - else - { - std::cerr << "Please specify the p-channel projector with either " - << " --p_ref or --casino_up.\n"; - // exit(-1); + nlpp.ReadCASINO_WF(parser.GetArg("casino_up"), 1); + else { + std::cerr << "Please specify the p-channel projector with either " + << " --p_ref or --casino_up.\n"; + // exit(-1); } } - if (numChannels > 2) - { - if (parser.Found("d_ref")) - nlpp.CalcProjector(parser.GetArg("d_ref"), 2); - else if (parser.Found("casino_ud")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_ud"), 2); - else - { - std::cerr << "Please specify the d-channel projector with either " - << " --d_ref or --casino_ud.\n"; - // exit(-1); + if (numChannels > 2) { + if (parser.Found ("d_ref")) + nlpp.CalcProjector (parser.GetArg("d_ref"), 2); + else if(parser.Found("casino_ud")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_ud"), 2); + else { + std::cerr << "Please specify the d-channel projector with either " + << " --d_ref or --casino_ud.\n"; + // exit(-1); } } - if (numChannels > 3) - { - if (parser.Found("f_ref")) - nlpp.CalcProjector(parser.GetArg("f_ref"), 3); - else if (parser.Found("casino_uf")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_uf"), 3); - else - { - std::cerr << "Please specify the f-channel projector with either " - << " --f_ref or --casino_uf.\n"; - // exit(-1); + if (numChannels > 3) { + if (parser.Found ("f_ref")) + nlpp.CalcProjector (parser.GetArg("f_ref"), 3); + else if(parser.Found("casino_uf")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_uf"), 3); + else { + std::cerr << "Please specify the f-channel projector with either " + << " --f_ref or --casino_uf.\n"; + // exit(-1); } } - if (numChannels > 4) - { - if (parser.Found("g_ref")) - nlpp.CalcProjector(parser.GetArg("g_ref"), 4); - else if (parser.Found("casino_ug")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_ug"), 4); - else - { - std::cerr << "Please specify the g-channel projector with either " - << " --g_ref or --casino_ug.\n"; - // exit(-1); + if (numChannels > 4) { + if (parser.Found ("g_ref")) + nlpp.CalcProjector (parser.GetArg("g_ref"), 4); + else if(parser.Found("casino_ug")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_ug"), 4); + else { + std::cerr << "Please specify the g-channel projector with either " + << " --g_ref or --casino_ug.\n"; + // exit(-1); } } } @@ -2135,27 +2013,30 @@ int main(int argc, char** argv) nlpp.WriteXML(parser.GetArg("xml")); if (parser.Found("tm")) nlpp.WriteABINIT(parser.GetArg("tm")); - if (parser.Found("upf")) - nlpp.WriteUPF(parser.GetArg("upf")); - if (parser.Found("fhi")) - nlpp.WriteFHI(parser.GetArg("fhi")); - if (parser.Found("fpmd")) - nlpp.WriteFPMD(parser.GetArg("fpmd")); - if (parser.Found("casino")) - nlpp.WriteCASINO(parser.GetArg("casino")); - - // nlpp.WriteXML(xmlFile); - // nlpp.WriteABINIT(); + if (parser.Found ("upf")) + nlpp.WriteUPF (parser.GetArg("upf")); + if (parser.Found ("fhi")) + nlpp.WriteFHI (parser.GetArg("fhi")); + if (parser.Found ("fpmd")) + nlpp.WriteFPMD (parser.GetArg("fpmd")); + if (parser.Found ("casino")) + nlpp.WriteCASINO (parser.GetArg("casino")); + +// nlpp.WriteXML(xmlFile); +// nlpp.WriteABINIT(); nlpp.WriteASCII(); - // nlpp.ReadCASINO_PP ("b_pp.data.HF"); - // nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 0); - // nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 1); - // nlpp.ReadCASINO_WF ("awfn.data_s2d1_2D", 2); - // nlpp.WriteXML("test.xml"); +// nlpp.ReadCASINO_PP ("b_pp.data.HF"); +// nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 0); +// nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 1); +// nlpp.ReadCASINO_WF ("awfn.data_s2d1_2D", 2); +// nlpp.WriteXML("test.xml"); } + + + #include "common/IO.h" //Array vector2Array(std::vector &vec) @@ -2167,54 +2048,53 @@ int main(int argc, char** argv) //} -bool PseudoClass::GetNextState(std::string& state, int& n, int& l, double& occ) + +bool +PseudoClass::GetNextState (std::string &state, int &n, int &l, double &occ) { if (state.length() <= 0) return false; - if ((state[0] < '1') || (state[0] > '9')) - { + if ((state[0]<'1') || (state[0] > '9')) { std::cerr << "Error parsing reference state.\n"; abort(); } - n = state[0] - '0'; - std::string channel = state.substr(1, 1); - if ((channel != "s") && (channel != "p") && (channel != "d") && (channel != "f") && (channel != "g")) - { + n = state[0] - '0'; + std::string channel = state.substr (1,1); + if ((channel != "s") && (channel != "p") && + (channel != "d") && (channel != "f") && (channel != "g")) { std::cerr << "Unrecognized angular momentum channel in reference state.\n"; abort(); } l = ChannelRevMap[channel]; // cerr << "n=" << n << " l=" << l << endl; - if (state[2] != '(') - { + if (state[2] != '(') { std::cerr << "Error parsing occupancy in reference state.\n"; abort(); } - state.erase(0, 3); + state.erase(0,3); std::string occString; - while ((state.length() > 0) && (state[0] != ')')) - { - occString.append(state.substr(0, 1)); - state.erase(0, 1); + while ((state.length() > 0) && (state[0] != ')')) { + occString.append (state.substr(0,1)); + state.erase(0,1); } - char* endptr; - const char* occStr = occString.c_str(); - occ = strtod(occStr, &endptr); - if (state[0] != ')') - { + char *endptr; + const char *occStr = occString.c_str(); + occ = strtod (occStr, &endptr); + if (state[0] != ')') { std::cerr << "Expected a ')' in parsing reference state.\n"; abort(); } - state.erase(0, 1); + state.erase(0,1); return true; } #include "common/DFTAtom.h" -void PseudoClass::CalcProjector(std::string refstate, int lchannel) +void +PseudoClass::CalcProjector(std::string refstate, int lchannel) { DFTAtom atom; std::string saveState = refstate; @@ -2225,70 +2105,87 @@ void PseudoClass::CalcProjector(std::string refstate, int lchannel) int n, l; double occ; int lindex = -1; - int index = 0; - while (GetNextState(refstate, n, l, occ)) - { - nList.push_back(n); - lList.push_back(l); - occList.push_back(occ); + int index = 0; + while (GetNextState(refstate, n, l, occ)) { + nList.push_back (n); + lList.push_back (l); + occList.push_back (occ); if (l == lchannel && lindex == -1) lindex = index; index++; } - if (lindex == -1) - { - nList.push_back(lchannel + 1); + if (lindex == -1) { + nList.push_back(lchannel+1); lList.push_back(lchannel); occList.push_back(0.0); - lindex = nList.size() - 1; + lindex = nList.size()-1; } atom.RadialWFs.resize(nList.size()); - for (int i = 0; i < atom.RadialWFs.size(); i++) - { + for (int i=0; i optimalGrid = std::make_shared(PseudoCharge, PotentialGrid.End()); - atom.SetGrid(optimalGrid); + std::shared_ptr grid = std::make_shared(PseudoCharge, PotentialGrid.End()); + atom.SetGrid (grid); // Set the potential - atom.SetBarePot(this); + atom.SetBarePot (this); // Solve atom atom.NewMix = DensityMix; std::cerr << "Solving atom for reference state " << saveState << ":\n"; atom.Solve(); // Now, initialize the channel u functions - std::vector ul(PotentialGrid.NumPoints()), rhoAtom(PotentialGrid.NumPoints()); - for (int i = 0; i < ul.size(); i++) - { - double r = PotentialGrid[i]; - ul[i] = sqrt(4.0 * M_PI) * atom.RadialWFs(lindex).u(r); + std::vector ul(PotentialGrid.NumPoints()), + rhoAtom(PotentialGrid.NumPoints()); + for (int i=0; iWrite(str); - if (lineCount + str.size() + 2 * Level > 73) - { + if (lineCount + str.size() + 2*Level > 73) { out << "\n"; - Indent(out); + Indent (out); out << " "; lineCount = 1; } @@ -74,142 +78,155 @@ void XMLElement::Write(std::ostream& out) out << str; } int numLines = 0; - for (int i = 0; i < Content.size(); i++) + for (int i=0; i\n"; - else - { + else { out << ">"; if (numLines > 0 || Children.size() > 0) out << "\n"; out << Content; - for (int i = 0; i < Children.size(); i++) + for (int i=0; iWrite(out); - if (numLines > 0 || Children.size() > 0) + if (numLines > 0 || Children.size()>0) Indent(out); out << "\n"; } } + - -void XMLElement::AddContent(std::vector& data) +void +XMLElement::AddContent(std::vector &data) { std::stringstream str; str.setf(std::ios_base::scientific, std::ios_base::floatfield); str << std::setprecision(14); - for (int i = 0; i < data.size(); i++) - { - if ((i % 3 == 0)) + for (int i=0; i\n"; + + Out << "\n"; return true; } -bool XMLWriterClass::EndDocument() +bool +XMLWriterClass::EndDocument() { - if (Elements.size() <= 0) + if (Elements.size() <=0) return false; Elements[0]->Write(Out); return true; } -bool XMLWriterClass::StartElement(std::string name) +bool +XMLWriterClass::StartElement(std::string name) { int level = Elements.size(); - + auto elem = std::make_shared(name, level); if (level > 0) - Elements.back()->AddElement(elem); + Elements.back()->AddElement (elem); Elements.push_back(elem); return true; } -bool XMLWriterClass::EndElement() +bool +XMLWriterClass::EndElement() { if (Elements.size() > 1) Elements.pop_back(); return true; } -bool XMLWriterClass::FullEndElement() +bool +XMLWriterClass::FullEndElement() { Elements.pop_back(); return true; } -bool XMLWriterClass::WriteAttribute(std::string name, std::string content) +bool +XMLWriterClass::WriteAttribute (std::string name, std::string content) { auto attr = std::make_shared(name, content); - Elements.back()->AddAttribute(attr); + Elements.back()->AddAttribute (attr); return true; } -bool XMLWriterClass::WriteAttribute(std::string name, double val, bool scientific) +bool +XMLWriterClass::WriteAttribute (std::string name, double val, bool scientific) { std::stringstream content; - if (scientific) - { + if (scientific) { content.setf(std::ios_base::scientific, std::ios_base::floatfield); content << std::setprecision(14); } content << val; auto attr = std::make_shared(name, content.str()); - Elements.back()->AddAttribute(attr); + Elements.back()->AddAttribute (attr); return true; } -bool XMLWriterClass::WriteAttribute(std::string name, int val) +bool +XMLWriterClass::WriteAttribute (std::string name, int val) { std::stringstream content; content << val; auto attr = std::make_shared(name, content.str()); - Elements.back()->AddAttribute(attr); + Elements.back()->AddAttribute (attr); return true; } -bool XMLWriterClass::WriteData(std::vector data) +bool +XMLWriterClass::WriteData(std::vector data) { - Elements.back()->AddContent(data); + Elements.back()->AddContent (data); return true; } -bool XMLWriterClass::WriteData(std::string data) +bool +XMLWriterClass::WriteData(std::string data) { - Elements.back()->AddContent(data); + Elements.back()->AddContent (data); return true; } -bool XMLWriterClass::WriteElement(std::string name, std::vector data) +bool +XMLWriterClass::WriteElement (std::string name, std::vector data) { int level = Elements.size(); auto elem = std::make_shared(name, level); - elem->AddContent(data); + elem->AddContent (data); if (level > 0) - Elements.back()->AddElement(elem); + Elements.back()->AddElement (elem); return true; } + diff --git a/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h b/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h index f140b75064..b878ab61a3 100644 --- a/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h +++ b/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h @@ -139,11 +139,11 @@ class CubicSplineCommon /// Trivial constructor CubicSplineCommon() { - UpToDate = 0; - NumParams = 0; + UpToDate = 0; + NumParams = 0; StartDeriv = 0; - EndDeriv = 0; - grid = NULL; + EndDeriv = 0; + grid = NULL; } }; diff --git a/src/QMCTools/ppconvert/src/common/DFTAtom.cc b/src/QMCTools/ppconvert/src/common/DFTAtom.cc index abf81ae2b5..4f364170fd 100644 --- a/src/QMCTools/ppconvert/src/common/DFTAtom.cc +++ b/src/QMCTools/ppconvert/src/common/DFTAtom.cc @@ -8,8 +8,8 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// @@ -17,7 +17,10 @@ #include "RungeKutta.h" #include "Functionals.h" -AtomType DFTAtom::Type() { return (DFTType); } +AtomType DFTAtom::Type() +{ + return (DFTType); +} void DFTAtom::UpdateVHXC() { @@ -25,22 +28,20 @@ void DFTAtom::UpdateVHXC() UpdateHartree(); UpdateExCorr(); - for (int i = 0; i < grid->NumPoints; i++) + for (int i=0; i < grid->NumPoints; i++) V.HXC(i) = Hartree(i) + ExCorr(i); } /// Radial WFs must be normalized before calling this function void DFTAtom::UpdateChargeDensity() { - for (int i = 0; i < grid->NumPoints; i++) - { + for (int i=0; iNumPoints; i++) { ChargeDensity(i) = 0.0; - double r = (*grid)(i); - double rinv2 = 1.0 / (r * r); - for (int j = 0; j < RadialWFs.size(); j++) - { + double r = (*grid)(i); + double rinv2 = 1.0/(r*r); + for (int j=0; jNumPoints; - + HartreeDeriv1 H1(*this); HartreeDeriv2 H2(*this); - RungeKutta integrator1(H1); - RungeKutta integrator2(H2); - temp(0) = 0.0; - temp2(0) = 0.0; - integrator1.Integrate(*grid, 0, N - 1, temp); - integrator2.Integrate(*grid, 0, N - 1, temp2); - - for (int i = 0; i < N; i++) - { - double r = (*grid)(i); - Hartree(i) = 4.0 * M_PI * (temp(i) / r + (temp2(N - 1) - temp2(i))); + RungeKutta integrator1(H1); + RungeKutta integrator2(H2); + temp(0) = 0.0; temp2(0) = 0.0; + integrator1.Integrate(*grid, 0, N-1, temp); + integrator2.Integrate(*grid, 0, N-1, temp2); + + for (int i=0; iNumPoints; - for (int i = 0; i < N; i++) - { + for (int i=0; i& newgrid) { - grid = newgrid; + grid = newgrid; int N = grid->NumPoints; temp.resize(N); temp2.resize(N); temp = 0.0; V.HXC.Init(grid, temp); - ChargeDensity.Init(grid, temp); + ChargeDensity.Init(grid,temp); Hartree.Init(grid, temp); - ExCorr.Init(grid, temp); - for (int i = 0; i < RadialWFs.size(); i++) + ExCorr.Init(grid,temp); + for (int i=0; iNumPoints; +// int N = grid->NumPoints; // // Just rename temp and temp2 for clarity // Array &oldCharge = temp; // Array &newCharge = temp2; @@ -142,7 +138,7 @@ void DFTAtom::SetBarePot(Potential* newPot) // for (int i=0; iNumPoints; +// int N = grid->NumPoints; // // Just rename temp and temp2 for clarity // Array &oldCharge = temp; // Array &newCharge = temp2; @@ -172,7 +168,7 @@ void DFTAtom::SetBarePot(Potential* newPot) // UpdateExCorr(); // for (int i=0; i < grid->NumPoints; i++) // V.HXC(i) = Hartree(i) + ExCorr(i); -// +// // double maxDiff = 0.0; // for (int i=0; iNumPoints; + int N = grid->NumPoints; // Just rename temp and temp2 for clarity - Array& oldCharge = temp; - Array& newCharge = temp2; + Array &oldCharge = temp; + Array &newCharge = temp2; // First, zero out screening - for (int i = 0; i < N; i++) + for (int i=0; i oldEnergies(RadialWFs.size()); + Array oldEnergies(RadialWFs.size()); // Now solve radial equations - for (int i = 0; i < RadialWFs.size(); i++) - { + for (int i=0; iNumPoints; i++) + for (int i=0; i < grid->NumPoints; i++) V.HXC(i) = Hartree(i) + ExCorr(i); done = true; - for (int i = 0; i < RadialWFs.size(); i++) - { + for (int i=0; i 1.0e-8) - done = false; + if (fabs(oldEnergies(i)-RadialWFs(i).Energy) > 1.0e-8) + done = false; oldEnergies(i) = RadialWFs(i).Energy; } - for (int i = 0; i < RadialWFs.size(); i++) - fprintf(stderr, "Energy(%d) = %1.16f\n", i, RadialWFs(i).Energy); + for (int i=0; iWrite(out); out.CloseSection(); - for (int i = 0; i < RadialWFs.size(); i++) - { + for (int i=0; iWrite(out); out.CloseSection(); - out.WriteVar("NewMix", NewMix); + out.WriteVar ("NewMix", NewMix); } -void DFTAtom::Read(IOSectionClass& in) +void DFTAtom::Read(IOSectionClass &in) { assert(in.OpenSection("Grid")); grid = ReadGrid(in); @@ -280,22 +274,22 @@ void DFTAtom::Read(IOSectionClass& in) int numRadialWFs = in.CountSections("RadialWF"); RadialWFs.resize(numRadialWFs); SetGrid(grid); - in.ReadVar("ChargeDensity", ChargeDensity.Data()); - in.ReadVar("Hartree", Hartree.Data()); - in.ReadVar("ExCorr", ExCorr.Data()); - for (int i = 0; i < V.HXC.size(); i++) - V.HXC(i) = Hartree(i) + ExCorr(i); + in.ReadVar ("ChargeDensity", ChargeDensity.Data()); + in.ReadVar ("Hartree", Hartree.Data()); + in.ReadVar ("ExCorr", ExCorr.Data()); + for (int i=0; i vdata; - assert(in.ReadVar("V", vdata)); - assert(in.ReadVar("Z", Z)); - PotSpline.Init(PotGrid, vdata); + Array vdata; + assert (in.ReadVar("V", vdata)); + assert (in.ReadVar("Z", Z)); + PotSpline.Init (PotGrid, vdata); } -void GeneralPot::Write(IOSectionClass& out) +void +GeneralPot::Write(IOSectionClass &out) { out.NewSection("Grid"); PotGrid->Write(out); @@ -36,29 +38,35 @@ void GeneralPot::Write(IOSectionClass& out) out.WriteVar("Type", "General"); } -double GeneralPot::V(double r) +double +GeneralPot::V(double r) { if (r < PotGrid->End) return PotSpline(r); else - return (-Z / r); + return (-Z/r); } -double GeneralPot::dVdr(double r) +double +GeneralPot::dVdr (double r) { if (r < PotGrid->End) return PotSpline.Deriv(r); else - return Z / (r * r); + return Z/(r*r); } -double GeneralPot::d2Vdr2(double r) +double +GeneralPot::d2Vdr2 (double r) { if (r < PotGrid->End) return PotSpline.Deriv2(r); else - return -2.0 * Z / (r * r * r); + return -2.0*Z/(r*r*r); } -GeneralPot::GeneralPot() : PotGrid(NULL) {} +GeneralPot::GeneralPot() : PotGrid(NULL) +{ + +} diff --git a/src/QMCTools/ppconvert/src/common/Grid.h b/src/QMCTools/ppconvert/src/common/Grid.h index ac8e90fee6..cc5e3d120f 100644 --- a/src/QMCTools/ppconvert/src/common/Grid.h +++ b/src/QMCTools/ppconvert/src/common/Grid.h @@ -65,7 +65,7 @@ class Grid virtual int ReverseMap(double r) = 0; virtual void Write(IOSectionClass& out) = 0; virtual void Read(IOSectionClass& inSection) = 0; - virtual ~Grid() {} + virtual ~Grid(){} }; diff --git a/src/QMCTools/ppconvert/src/common/NLPP.cc b/src/QMCTools/ppconvert/src/common/NLPP.cc index 7f54d858a8..39bab55b46 100644 --- a/src/QMCTools/ppconvert/src/common/NLPP.cc +++ b/src/QMCTools/ppconvert/src/common/NLPP.cc @@ -8,30 +8,38 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// + + #include "NLPP.h" #include "GKIntegration.h" #include "MatrixOps.h" -bool NLPPClass::IsNonlocal() { return true; } +bool +NLPPClass::IsNonlocal() +{ + return true; +} -void ChannelPotential::Read(IOSectionClass& in, std::shared_ptr& grid) +void +ChannelPotential::Read(IOSectionClass &in, std::shared_ptr& grid) { - assert(in.ReadVar("l", l)); - assert(in.ReadVar("n_principal", n_principal)); - assert(in.ReadVar("Cutoff", rc)); + assert (in.ReadVar("l", l)); + assert (in.ReadVar("n_principal", n_principal)); + assert (in.ReadVar("Cutoff", rc)); R0 = 1.75 * rc; - assert(in.ReadVar("Occupation", Occupation)); - assert(in.ReadVar("Eigenvalue", Eigenvalue)); - Array V_data, u_data; - assert(in.ReadVar("Vl", V_data)); - assert(in.ReadVar("ul", u_data)); - V.Init(grid, V_data); - u.Init(grid, u_data); + assert (in.ReadVar("Occupation", Occupation)); + assert (in.ReadVar("Eigenvalue", Eigenvalue)); + Array V_data, u_data; + assert (in.ReadVar("Vl", V_data)); + assert (in.ReadVar("ul", u_data)); + V.Init (grid, V_data); + u.Init (grid, u_data); } -void ChannelPotential::Write(IOSectionClass& out) +void +ChannelPotential::Write(IOSectionClass &out) { out.WriteVar("l", l); out.WriteVar("n_principal", n_principal); @@ -42,153 +50,148 @@ void ChannelPotential::Write(IOSectionClass& out) out.WriteVar("ul", u.Data()); } -void NLPPClass::Read(IOSectionClass& in) +void +NLPPClass::Read(IOSectionClass &in) { assert(in.ReadVar("AtomicNumber", AtomicNumber)); assert(in.ReadVar("LocalChannel", lLocal)); assert(in.ReadVar("ValenceCharge", Zion)); assert(in.ReadVar("Symbol", Symbol)); - + int numChannels = in.CountSections("lChannel"); Vl.resize(numChannels); - // vector > vl(numChannels), ul(numChannels); - // vector rc(numChannels); - assert(in.OpenSection("PotentialGrid")); - PotentialGrid = ReadGrid(in); +// vector > vl(numChannels), ul(numChannels); +// vector rc(numChannels); + assert (in.OpenSection("PotentialGrid")); + PotentialGrid = ReadGrid (in); in.CloseSection(); // "PotentialGrid" - for (int i = 0; i < numChannels; i++) - { - assert(in.OpenSection("lChannel", i)); + for (int i=0; i numChannels) - { + assert (in.ReadVar("l", l)); + if (l > numChannels) { std::cerr << "Skipped channels in NLPPClass read.\n"; abort(); } Vl[l].Read(in, PotentialGrid); - in.CloseSection(); // "lChannel" + in.CloseSection (); // "lChannel" } - for (int l = 0; l < numChannels; l++) - { - Array deltav(PotentialGrid->NumPoints); - deltav = Vl[l].V.Data() - Vl[lLocal].V.Data(); - Vl[l].DeltaV.Init(PotentialGrid, deltav); + for (int l=0; l deltav(PotentialGrid->NumPoints); + deltav = Vl[l].V.Data()- Vl[lLocal].V.Data(); + Vl[l].DeltaV.Init (PotentialGrid, deltav); } } -void NLPPClass::Write(IOSectionClass& out) +void +NLPPClass::Write(IOSectionClass &out) { - out.WriteVar("Type", "NLPP"); - out.WriteVar("LocalChannel", lLocal); - out.WriteVar("AtomicNumber", AtomicNumber); - out.WriteVar("Symbol", Symbol); - out.WriteVar("ValenceCharge", Zion); + out.WriteVar ("Type", "NLPP"); + out.WriteVar ("LocalChannel", lLocal); + out.WriteVar ("AtomicNumber", AtomicNumber); + out.WriteVar ("Symbol", Symbol); + out.WriteVar ("ValenceCharge", Zion); out.NewSection("PotentialGrid"); PotentialGrid->Write(out); - out.CloseSection(); // "PotentialGrid" - for (int i = 0; i < Vl.size(); i++) - { + out.CloseSection(); // "PotentialGrid" + for (int i=0; i::quiet_NaN(); // sqrt(-1.0); } @@ -210,91 +213,87 @@ double ChannelPotential::A(double q, double qp) // DeltaV and u splines. It then applies the methods of King-Smith et // al to filter out the high Fourier components, so that the // projector can be applied without error in real-space. -void ChannelPotential::SetupProjector(double G_max, double G_FFT) +void +ChannelPotential::SetupProjector (double G_max, double G_FFT) { - Grid& grid = *u.grid; + Grid &grid = *u.grid; // First, compute zeta_r, normalization, and E_KB Job = NORM; GKIntegration integrator(*this); - double norm = integrator.Integrate(0.0, grid.End, 1.0e-12); - ProjectorNorm = 1.0 / sqrt(norm); - Job = EKB; - E_KB = norm / integrator.Integrate(0.0, grid.End, 1.0e-12); - std::cerr << "l = " << l << " Norm is " << norm << " E_KB is " << E_KB << " R0 = " << R0 << std::endl; - + double norm = integrator.Integrate(0.0, grid.End, 1.0e-12); + ProjectorNorm = 1.0/sqrt(norm); + Job = EKB; + E_KB = norm/integrator.Integrate(0.0, grid.End, 1.0e-12); + std::cerr << "l = " << l << " Norm is " << norm + << " E_KB is " << E_KB << " R0 = " << R0 << std::endl; + // Compute zeta(r) - Array zeta(grid.NumPoints); - zeta(0) = ProjectorNorm * DeltaV(0) * u(1.0e-8) * 1.0e8; - for (int i = 1; i < grid.NumPoints; i++) - zeta(i) = ProjectorNorm * DeltaV(i) * u(i) / grid(i); - zeta_r.Init(u.grid, zeta); + Array zeta(grid.NumPoints); + zeta(0) = ProjectorNorm * DeltaV(0)*u(1.0e-8)*1.0e8; + for (int i=1; i qGridSharedPtr(&qGrid); - zeta_q.Init(qGridSharedPtr, zeta); + zeta_q.Init (qGridSharedPtr, zeta); double gamma = G_FFT - G_max; // Zero out zeta_q above gamma; - Array chi_q_data(qGrid.NumPoints); - for (int i = 0; i < qGrid.NumPoints; i++) + Array chi_q_data(qGrid.NumPoints); + for (int i=0; i= gamma) ? 0.0 : zeta_q(i); - - chi_q.Init(qGridSharedPtr, chi_q_data); + chi_q.Init (qGridSharedPtr, chi_q_data); // Now for the magic: We adjust chi_q between G_max and gamma so // that the real-space oscillations outside R0 are damped out // See King-Smith et al, PRB 44 13063 // Find index of gamma int gammaIndex = qGrid.ReverseMap(gamma); - int G_maxIndex = qGrid.ReverseMap(G_max) + 1; - double delta = qGrid(1) - qGrid(0); - int nb = gammaIndex - G_maxIndex; - Array b(nb), x(nb); + int G_maxIndex = qGrid.ReverseMap(G_max)+1; + double delta = qGrid(1)-qGrid(0); + int nb = gammaIndex - G_maxIndex; + Array b(nb), x(nb); // First, create the b vector b = 0.0; - for (int i = 0; i < nb; i++) - { - double q = qGrid(G_maxIndex + i); - for (int j = 0; j < G_maxIndex; j++) - { - double qp = qGrid(j); - b(i) -= delta * A(q, qp) * zeta_q(j); + for (int i=0; i M(nb, nb); - for (int i = 0; i < nb; i++) - { - double q = qGrid(G_maxIndex + i); - for (int j = 0; j < nb; j++) - { - double qp = qGrid(G_maxIndex + j); - M(i, j) = delta * A(q, qp); + Array M(nb, nb); + for (int i=0; i perm({nb}, int{0}); @@ -302,35 +301,36 @@ void ChannelPotential::SetupProjector(double G_max, double G_FFT) assert(size(LU) == size(M)); // check it is invertible x = lup::solve(LU, perm, b); - for (int i = 0; i < nb; i++) - chi_q(G_maxIndex + i) = x(i); - chi_q(G_maxIndex + nb) = 0.0; - - // FILE *fout = fopen("chicheck.dat","w"); - // for (double q=0.0; q chi_r_data(grid.NumPoints); - for (int i = 1; i < grid.NumPoints; i++) - { - rCurrent = grid(i); + Array chi_r_data(grid.NumPoints); + for (int i=1; i 1.0e-16) - std::cerr << "Fractional error in real-space projection = " << (error / norm2) << std::endl; + std::cerr << "Fractional error in real-space projection = " + << (error / norm2) << std::endl; } -double NLPPClass::V(int l, double r) +double +NLPPClass::V(int l, double r) { if (l < Vl.size()) return Vl[l].V(r); @@ -338,7 +338,8 @@ double NLPPClass::V(int l, double r) return Vl[lLocal].V(r); } -double NLPPClass::dVdr(int l, double r) +double +NLPPClass::dVdr(int l, double r) { if (l < Vl.size()) return Vl[l].V.Deriv(r); @@ -346,7 +347,8 @@ double NLPPClass::dVdr(int l, double r) return Vl[lLocal].V.Deriv(r); } -double NLPPClass::d2Vdr2(int l, double r) +double +NLPPClass::d2Vdr2(int l, double r) { if (l < Vl.size()) return Vl[l].V.Deriv2(r); @@ -354,8 +356,20 @@ double NLPPClass::d2Vdr2(int l, double r) return Vl[lLocal].V.Deriv2(r); } -double NLPPClass::V(double r) { return Vl[lLocal].V(r); } +double +NLPPClass::V(double r) +{ + return Vl[lLocal].V(r); +} -double NLPPClass::dVdr(double r) { return Vl[lLocal].V.Deriv(r); } +double +NLPPClass::dVdr(double r) +{ + return Vl[lLocal].V.Deriv(r); +} -double NLPPClass::d2Vdr2(double r) { return Vl[lLocal].V.Deriv2(r); } +double +NLPPClass::d2Vdr2(double r) +{ + return Vl[lLocal].V.Deriv2(r); +} diff --git a/src/QMCTools/ppconvert/src/common/RadialWF.cc b/src/QMCTools/ppconvert/src/common/RadialWF.cc index a2d87a1999..dbe505de53 100644 --- a/src/QMCTools/ppconvert/src/common/RadialWF.cc +++ b/src/QMCTools/ppconvert/src/common/RadialWF.cc @@ -8,91 +8,91 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// #include "RadialWF.h" #include "RungeKutta.h" -int RadialWF::TurningIndex() +int +RadialWF::TurningIndex() { // Start in classically forbidden region and search inward toward // origin looking for classically allowed region - Grid& grid = *u.grid; - int index = grid.NumPoints - 1; - bool done = false; - - while (!done && (index >= 0)) - { - double r = grid(index); - double A = pot->A(r); - double B = pot->B(r); - double V = pot->V(l, r); - double dAdr = pot->dAdr(r); - double E = Energy; - double sl = (double)l; - - double Deriv2 = dAdr / r + sl * (sl + 1.0) * B / (r * r) + 2.0 * (V - E); - - if (Deriv2 < 0.0) - done = true; - else - index--; - } + Grid &grid = *u.grid; + int index = grid.NumPoints-1; + bool done = false; + + while (!done && (index >=0)) + { + double r = grid(index); + double A = pot->A(r); + double B = pot->B(r); + double V = pot->V(l,r); + double dAdr = pot->dAdr(r); + double E = Energy; + double sl = (double) l; + + double Deriv2 = dAdr/r + sl*(sl+1.0)*B/(r*r) + 2.0*(V-E); + + if (Deriv2 < 0.0) + done = true; + else + index--; + } // If we didn't fine a turning point, select the middle grid point; if (index == -1) - index = grid.ReverseMap(0.5 * grid(grid.NumPoints - 1)); + index = grid.ReverseMap(0.5*grid(grid.NumPoints-1)); return (index); } -void RadialWF::OriginBC(double r0, double& u0, double& du0) +void +RadialWF::OriginBC(double r0, double &u0, double &du0) { - if (pot->NeedsRel()) - { // Use relativistic equations - const double alpha = 1.0 / 137.036; - double Z = -pot->V(l, r0) * r0; - double a2Z2 = alpha * alpha * (double)Z * (double)Z; - - double sl = (double)l; - double gamma = (sl + 1.0) * sqrt((sl + 1.0) * (sl + 1.0) - a2Z2) / (2.0 * sl + 1.0); - if (l != 0) - gamma += sl * sqrt(sl * sl - a2Z2) / (2.0 * sl + 1.0); - - u0 = pow(r0, gamma); - du0 = gamma * pow(r0, gamma - 1.0); + if (pot->NeedsRel()) { // Use relativistic equations + const double alpha = 1.0/137.036; + double Z = -pot->V(l,r0)*r0; + double a2Z2 = alpha*alpha*(double)Z*(double)Z; + + double sl = (double) l; + double gamma = + (sl+1.0)*sqrt((sl+1.0)*(sl+1.0)-a2Z2) / + (2.0*sl + 1.0); + if (l!=0) + gamma += sl*sqrt(sl*sl-a2Z2)/(2.0*sl+1.0); + + u0 = pow(r0, gamma); + du0 = gamma * pow(r0,gamma-1.0); } - else - { // Use pseudoHamiltonian equations + else { // Use pseudoHamiltonian equations if (l == 0) - { - double E = Energy; - double A = pot->A(r0); - double B = pot->B(r0); - double V = pot->V(l, r0); - if (V > Energy) - { - double kappa = sqrt(2.0 * (V - E) / A); - u0 = sinh(kappa * r0); - du0 = kappa * cosh(kappa * r0); - } - else { - double k = sqrt(2.0 * (E - V) / A); - u0 = sin(k * r0); - du0 = k * cos(k * r0); + double E = Energy; + double A = pot->A(r0); + double B = pot->B(r0); + double V = pot->V(l,r0); + if (V > Energy) + { + double kappa = sqrt(2.0 * (V-E)/A); + u0 = sinh(kappa * r0); + du0 = kappa * cosh (kappa * r0); + } + else + { + double k = sqrt(2.0 * (E-V)/A); + u0 = sin(k * r0); + du0 = k * cos(k * r0); + } } + else { // l != 0 + u0 = 1.0; + du0 = (double)(l+1)/r0; } - else - { // l != 0 - u0 = 1.0; - du0 = (double)(l + 1) / r0; - } - } + } // Flip sign for odd number of nodes - if (((n - l - 1) % 2) == 1) - { + if (((n-l-1) % 2) == 1) { u0 *= -1.0; du0 *= -1.0; } @@ -105,7 +105,7 @@ void RadialWF::OriginBC(double r0, double& u0, double& du0) // Grid &grid = *u.grid; // Array Temp(grid.NumPoints); // // Set up initial conditions: -// double r0 = grid(0); +// double r0 = grid(0); // OriginBC(r0, Temp(0)[0], Temp(0)[1]); // // Now do integration @@ -117,12 +117,12 @@ void RadialWF::OriginBC(double r0, double& u0, double& du0) // else if (pot->NeedsRel()) { // NonPHDerivs derivs(*this); // RungeKutta integrator(derivs); -// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); +// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); // } // else { // RegularDerivs derivs(*this); // RungeKutta integrator(derivs); -// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); +// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); // } // // Copy results of integration into RadialWF @@ -134,159 +134,152 @@ void RadialWF::OriginBC(double r0, double& u0, double& du0) //} -double RadialWF::IntegrateInOut(int& tindex) +double +RadialWF::IntegrateInOut (int &tindex) { - Grid& grid = *u.grid; + Grid &grid = *u.grid; // Find classical turning point tindex = TurningIndex(); //cerr << "TurningIndex = " << tindex << endl; //cerr << "Turning Point = " << (*u.grid)(tindex) << endl; // Compute starting value and derivative at origin double r0 = grid(0); - OriginBC(r0, uduVec(0)[0], uduVec(0)[1]); + OriginBC (r0, uduVec(0)[0], uduVec(0)[1]); // Do integration from the origin to the turning point - if (pot->IsPH()) - { + if (pot->IsPH()) { PHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, 0, tindex, uduVec); } - else if (pot->NeedsRel()) - { + else if (pot->NeedsRel()) { NonPHDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, 0, tindex, uduVec); + RungeKutta integrator(derivs); + integrator.Integrate(grid, 0, tindex, uduVec); } - else - { + else { RegularDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, 0, tindex, uduVec); - } + RungeKutta integrator(derivs); + integrator.Integrate(grid, 0, tindex, uduVec); + } - for (int j = 0; j <= tindex; j++) - { - u(j) = uduVec(j)[0]; + for (int j=0; j<=tindex; j++) { + u(j) = uduVec(j)[0]; dudr(j) = uduVec(j)[1]; } // Now initilize value and derivative at rmax - int endPoint = grid.NumPoints - 1; - double rend = grid(endPoint); + int endPoint = grid.NumPoints-1; + double rend = grid(endPoint); InfinityBC(rend, uduVec(endPoint)[0], uduVec(endPoint)[1]); - + // Do integration from the right to the turning point - if (pot->IsPH()) - { + if (pot->IsPH()) { PHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, endPoint, tindex, uduVec); } - else if (pot->NeedsRel()) - { + else if (pot->NeedsRel()) { NonPHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, endPoint, tindex, uduVec); } - else - { + else { RegularDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, endPoint, tindex, uduVec); - } + RungeKutta integrator(derivs); + integrator.Integrate(grid, endPoint, tindex, uduVec); + } - if ((u(tindex) * uduVec(tindex)[0]) < 0.0) - for (int i = tindex; i <= endPoint; i++) + if ((u(tindex)*uduVec(tindex)[0]) < 0.0) + for (int i=tindex; i<=endPoint; i++) uduVec(i) *= -1.0; - double cuspValue = uduVec(tindex)[1] / uduVec(tindex)[0] - dudr(tindex) / u(tindex); + double cuspValue = uduVec(tindex)[1]/uduVec(tindex)[0] - + dudr(tindex)/u(tindex); // Copy values in, normalizing to make R continuous double factor = u(tindex) / uduVec(tindex)[0]; - for (int i = tindex + 1; i < grid.NumPoints; i++) - { - u(i) = factor * uduVec(i)[0]; - dudr(i) = factor * uduVec(i)[1]; + for (int i=tindex+1; iV(l, rend); - double dVdrend = pot->dVdr(l, rend); - double E = Energy; + double Vend = pot->V(l,rend); + double dVdrend = pot->dVdr(l,rend); + double E = Energy; double k; uend = 1.0; - if (Vend > E) - { - k = sqrt(l * (l + 1.0) / (rend * rend) + (Vend - E)); - duend = -uend * (k + 0.5 * rend / k * (dVdrend - 2.0 * l * (l + 1.0) / (rend * rend * rend))); + if (Vend > E) { + k = sqrt(l*(l+1.0)/(rend*rend) + (Vend-E)); + duend = -uend * (k + 0.5*rend/k*(dVdrend-2.0*l*(l+1.0)/(rend*rend*rend))); } else duend = -1.0; - // cerr << "duend = " << duend << endl; - // cerr << "rend = " << rend << endl; - // cerr << "k = " << k << endl; - // cerr << "Vend = " << Vend << endl; - // cerr << "dVend = " << dVdrend << endl; +// cerr << "duend = " << duend << endl; +// cerr << "rend = " << rend << endl; +// cerr << "k = " << k << endl; +// cerr << "Vend = " << Vend << endl; +// cerr << "dVend = " << dVdrend << endl; } -void RadialWF::Solve(double tolerance) + +void +RadialWF::Solve(double tolerance) { int tindex; IntegrateInOut(tindex); int NumNodes = CountNodes(); double Ehigh, Elow, Etrial; - Ehigh = 0.0; - Grid& grid = *u.grid; - int TotalNodes = n - l - 1; - - // char fname[100]; - // snprintf (fname, 100, "WFn%dl%d.h5", n, l); - // IOSectionClass out; - // out.NewFile(fname); - // out.WriteVar ("x", u.grid->Points()); - // Array tmp(1,u.grid->NumPoints); - // tmp(0,Range::all()) = u.Data(); - // out.WriteVar ("u", tmp); - // VarClass *varPtr = out.GetVarPtr("u"); - - if (pot->NeedsRel()) - { + Ehigh = 0.0; + Grid &grid = *u.grid; + int TotalNodes = n-l-1; + +// char fname[100]; +// snprintf (fname, 100, "WFn%dl%d.h5", n, l); +// IOSectionClass out; +// out.NewFile(fname); +// out.WriteVar ("x", u.grid->Points()); +// Array tmp(1,u.grid->NumPoints); +// tmp(0,Range::all()) = u.Data(); +// out.WriteVar ("u", tmp); +// VarClass *varPtr = out.GetVarPtr("u"); + + if (pot->NeedsRel()){ double N = n; - double Z = -pot->V(l, grid(0)) * grid(0); - Elow = -1.5 * Z * Z / (N * N); - } - else - { + double Z = -pot->V(l,grid(0))*grid(0); + Elow = -1.5*Z*Z/(N*N); + } + else { // Eigenenergy can't be lower than lowest potential -- otherwise // we'd have no turning point. - Elow = pot->V(l, grid(0)); - for (int i = 1; i < grid.NumPoints; i++) - { + Elow = pot->V(l,grid(0)); + for (int i=1; i TotalNodes) Ehigh = Etrial; @@ -298,28 +291,27 @@ void RadialWF::Solve(double tolerance) Ehigh = Etrial; else if (std::isnan(CuspValue)) Elow = Etrial; - + Normalize(); // varPtr->Append(u.Data()); - double A = pot->A(grid(tindex)); - double C = 0.5 * A * CuspValue; - double u0 = u(tindex); - double Etest = Eold - 4.0 * M_PI * C * u0 * u0; + double A = pot->A(grid(tindex)); + double C = 0.5 * A * CuspValue; + double u0 = u(tindex); + double Etest = Eold - 4.0*M_PI*C*u0*u0; if ((Etest > Elow) && (Etest < Ehigh) && (NumNodes == TotalNodes)) Etrial = Etest; - else + else Etrial = 0.5 * (Ehigh + Elow); - + Energy = Etrial; - - if ((NumNodes == TotalNodes) && (fabs(Etrial - Eold) < tolerance)) - { + + if ((NumNodes == TotalNodes) && (fabs(Etrial - Eold) < tolerance)) { Energy = Eold; - done = true; + done = true; } else { - if (std::isnan(Etrial)) + if(std::isnan(Etrial)) { std::cerr << "NaN detected!" << std::endl; std::cerr << "NumNodes = " << NumNodes << " TotalNodes = " << TotalNodes << std::endl; @@ -327,48 +319,48 @@ void RadialWF::Solve(double tolerance) exit(1); } } - Eold = Etrial; + Eold = Etrial; } IntegrateInOut(tindex); Normalize(); NumNodes = CountNodes(); - if (NumNodes != TotalNodes) - { - std::cerr << "Node number error! We have " << NumNodes << " nodes and want " << TotalNodes << ".\n"; - // IOSectionClass out; - // out.NewFile ("BadWF.h5"); - // out.WriteVar ("u", u.Data()); - // out.CloseFile(); + if (NumNodes != TotalNodes) { + std::cerr << "Node number error! We have " << NumNodes + << " nodes and want " << TotalNodes << ".\n"; +// IOSectionClass out; +// out.NewFile ("BadWF.h5"); +// out.WriteVar ("u", u.Data()); +// out.CloseFile(); std::cerr << "Energy = " << Energy << std::endl; } //out.CloseFile(); } -void RadialWF::Normalize() +void +RadialWF::Normalize() { normVec(0) = 0.0; NormalizeDeriv normDeriv(*this); - RungeKutta integrator(normDeriv); - // The false means "don't scale" - integrator.Integrate(*u.grid, 0, u.grid->NumPoints - 1, normVec, false); - - double norm = sqrt(1.0 / (4.0 * M_PI * normVec(u.grid->NumPoints - 1))); - for (int i = 0; i < u.grid->NumPoints; i++) - { + RungeKutta integrator(normDeriv); + // The false means "don't scale" + integrator.Integrate(*u.grid, 0, u.grid->NumPoints-1, normVec, false); + + double norm = sqrt(1.0/(4.0*M_PI*normVec(u.grid->NumPoints-1))); + for (int i=0; iNumPoints; i++) { u(i) *= norm; dudr(i) *= norm; } } -int RadialWF::CountNodes() +int +RadialWF::CountNodes() { - int nodes = 0; + int nodes=0; double sign = u(0); - for (int i = 1; i < u.grid->NumPoints; i++) - if ((sign * u(i)) < 0.0) - { + for (int i=1; iNumPoints; i++) + if ((sign*u(i)) < 0.0) { nodes++; sign *= -1.0; // cerr << "Node at i=" << i << " r=" << (*u.grid)(i) << endl; @@ -376,67 +368,79 @@ int RadialWF::CountNodes() return (nodes); } -void RadialWF::SetGrid(std::shared_ptr& newgrid) +void +RadialWF::SetGrid(std::shared_ptr& newgrid) { - grid = newgrid; + grid = newgrid; int N = grid->NumPoints; uduVec.resize(N); normVec.resize(N); - uduVec = 0.0; + uduVec = 0.0; normVec = 0.0; - u.Init(grid, normVec); + u.Init (grid, normVec); dudr.Init(grid, normVec); } -void RadialWF::SetPotential(Potential* newPot) { pot = newPot; } +void +RadialWF::SetPotential(Potential *newPot) +{ + pot = newPot; +} -Potential* RadialWF::GetPotential() { return pot; } +Potential* +RadialWF::GetPotential() +{ + return pot; +} -double RadialWF::PartialNorm() +double +RadialWF::PartialNorm() { normVec(0) = 0.0; NormalizeDeriv normDeriv(*this); - RungeKutta integrator(normDeriv); + RungeKutta integrator(normDeriv); int N = u.grid->NumPoints; - integrator.Integrate(*u.grid, 0, N - 1, normVec); - double uend = u(N - 1); - double partNorm = normVec(N - 1) / (uend * uend); + integrator.Integrate(*u.grid, 0, N-1, normVec); + double uend = u(N-1); + double partNorm = normVec(N-1)/(uend*uend); return (partNorm); } -double RadialWF::LogDerivative() +double +RadialWF::LogDerivative() { double rend = (*u.grid).End; - return (dudr(rend) / u(rend)); + return (dudr(rend)/u(rend)); } // This will write all the information except the potential and the // grid. We assume that those are store somewhere else -void RadialWF::Write(IOSectionClass& out) +void +RadialWF::Write(IOSectionClass &out) { - out.WriteVar("u", u.Data()); - out.WriteVar("dudr", dudr.Data()); - out.WriteVar("n", n); - out.WriteVar("l", l); - out.WriteVar("CoreNodes", CoreNodes); - out.WriteVar("Occupancy", Occupancy); - out.WriteVar("Weight", Weight); - out.WriteVar("Energy", Energy); + out.WriteVar ("u", u.Data()); + out.WriteVar ("dudr", dudr.Data()); + out.WriteVar ("n", n); + out.WriteVar ("l", l); + out.WriteVar ("CoreNodes", CoreNodes); + out.WriteVar ("Occupancy", Occupancy); + out.WriteVar ("Weight", Weight); + out.WriteVar ("Energy", Energy); // out.WriteVar ("PartialNorm", PartialNorm); - out.WriteVar("Label", Label); + out.WriteVar ("Label", Label); } // This function assumes the grid has already been set. -void RadialWF::Read(IOSectionClass& in) +void +RadialWF::Read (IOSectionClass &in) { bool succ; - if (u.grid == NULL) - { + if (u.grid == NULL) { std::cerr << "Grid not set prior to calling RadialWF::Read.\n"; exit(1); } - in.ReadVar("u", u.Data()); - in.ReadVar("dudr", dudr.Data()); + in.ReadVar ("u", u.Data()); + in.ReadVar ("dudr", dudr.Data()); assert(in.ReadVar("n", n)); assert(in.ReadVar("l", l)); assert(in.ReadVar("Occupancy", Occupancy)); diff --git a/src/QMCTools/ppconvert/src/common/SplinePot.cc b/src/QMCTools/ppconvert/src/common/SplinePot.cc index a6f89a96df..8f1d0f6994 100644 --- a/src/QMCTools/ppconvert/src/common/SplinePot.cc +++ b/src/QMCTools/ppconvert/src/common/SplinePot.cc @@ -8,8 +8,8 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// @@ -19,10 +19,9 @@ double SplinePot::V(double r) { if (r <= Spline.grid->End) return Spline(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->V(r)); - else - { + else { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -34,10 +33,9 @@ double SplinePot::dVdr(double r) { if (r <= Spline.grid->End) return Spline.Deriv(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->dVdr(r)); - else - { + else { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -49,10 +47,9 @@ double SplinePot::d2Vdr2(double r) { if (r <= Spline.grid->End) return Spline.Deriv2(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->d2Vdr2(r)); - else - { + else { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -60,34 +57,32 @@ double SplinePot::d2Vdr2(double r) } } -void SplinePot::Read(IOSectionClass& in) +void SplinePot::Read(IOSectionClass &in) { assert(in.OpenSection("Grid")); auto grid = ReadGrid(in); - in.CloseSection(); // "Grid" - Array data; + in.CloseSection(); // "Grid" + Array data; assert(in.ReadVar("SplineData", data)); - Spline.Init(grid, data); - if (in.OpenSection("Vouter")) - { + Spline.Init (grid, data); + if(in.OpenSection("Vouter")) { Vouter = ReadPotential(in); in.CloseSection(); } else Vouter = NULL; -} + } -void SplinePot::Write(IOSectionClass& out) +void SplinePot::Write(IOSectionClass &out) { - out.WriteVar("Type", "Spline"); + out.WriteVar ("Type", "Spline"); out.NewSection("Grid"); Spline.grid->Write(out); out.CloseSection(); - out.WriteVar("SplineData", Spline.Data()); - if (Vouter != NULL) - { - out.NewSection("Vouter"); + out.WriteVar ("SplineData", Spline.Data()); + if (Vouter != NULL) { + out.NewSection ("Vouter"); Vouter->Write(out); out.CloseSection(); }