00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "QMCBasisFunctionCoefficients.h"
00014 #include "StringManipulation.h"
00015 #include <iomanip>
00016
00017 QMCBasisFunctionCoefficients::QMCBasisFunctionCoefficients()
00018 {
00019 N_Orbitals = 0;
00020 }
00021
00022 int QMCBasisFunctionCoefficients::getNumberBasisFunctions()
00023 {
00024 return N_Orbitals;
00025 }
00026
00027 void QMCBasisFunctionCoefficients::operator=(
00028 const QMCBasisFunctionCoefficients & rhs)
00029 {
00030 this->Label = rhs.Label;
00031 this->N_Orbitals = rhs.N_Orbitals;
00032 this->Max_Gaussians = rhs.Max_Gaussians;
00033 this->Coeffs = rhs.Coeffs;
00034 this->xyz_powers = rhs.xyz_powers;
00035 this->N_Gauss = rhs.N_Gauss;
00036 this->Type = rhs.Type;
00037 }
00038
00039 void type_to_xyz(string type, int &x, int &y, int &z)
00040 {
00041 type = StringManipulation::toAllLower(type);
00042 const char * bf = type.c_str();
00043 const int maxl = 7;
00044 char lnames[maxl] = {'s','p','d','f','g','h','i'};
00045
00046 int idx = -1;
00047 for(int i=0; i<maxl; i++)
00048 if(bf[0] == lnames[i]){
00049 idx = i;
00050 break;
00051 }
00052
00053 if(idx == -1){
00054 clog << "ERROR: Unknown Basis Function (" << type
00055 << ")" << endl;
00056 clog << "You requested type = " << bf[0] << " but we only have ";
00057 for(int i=0; i<maxl; i++)
00058 clog << lnames[i];
00059 clog << " available." << endl;
00060 exit(1);
00061 }
00062
00063 if((int)type.size()-1 != idx){
00064 clog << "ERROR: Basis Function (" << type << ")"
00065 << " doesn't have angular momentum = " << idx << "." << endl;
00066 exit(1);
00067 }
00068
00069 x = y = z = 0;
00070 for(unsigned int i=1; i<type.size(); i++)
00071 {
00072 switch (bf[i]){
00073 case 'x': x++; break;
00074 case 'y': y++; break;
00075 case 'z': z++; break;
00076 default:
00077 clog << "Error: unknown angular component " << bf[i]
00078 << " in basis function " << type << endl;
00079 exit(0);
00080 }
00081 }
00082 }
00083
00084 istream& operator >>(istream &strm, QMCBasisFunctionCoefficients &rhs)
00085 {
00086 strm >> rhs.Label;
00087 rhs.Label = StringManipulation::toFirstUpperRestLower( rhs.Label );
00088
00089 strm >> rhs.N_Orbitals;
00090 strm >> rhs.Max_Gaussians;
00091
00092 rhs.Coeffs.allocate(rhs.N_Orbitals,rhs.Max_Gaussians,2);
00093 rhs.xyz_powers.allocate(rhs.N_Orbitals,3);
00094 rhs.N_Gauss.allocate(rhs.N_Orbitals);
00095 rhs.Type.allocate(rhs.N_Orbitals);
00096
00097 int x,y,z;
00098 rhs.lmax = 0;
00099 for(int i=0; i<rhs.N_Orbitals; i++)
00100 {
00101 strm >> rhs.N_Gauss(i);
00102 strm >> rhs.Type(i);
00103
00104 type_to_xyz(rhs.Type(i),x,y,z);
00105 rhs.xyz_powers(i,0) = x;
00106 rhs.xyz_powers(i,1) = y;
00107 rhs.xyz_powers(i,2) = z;
00108 rhs.lmax = max(rhs.lmax,x+y+z);
00109
00110 for(int j=0; j<rhs.N_Gauss(i); j++)
00111 {
00112 strm >> rhs.Coeffs(i,j,0);
00113 strm >> rhs.Coeffs(i,j,1);
00114 }
00115 }
00116 return strm;
00117 }
00118
00119 void QMCBasisFunctionCoefficients::read(string runfile)
00120 {
00121 ifstream input_file(runfile.c_str());
00122
00123 if(!input_file)
00124 {
00125 cerr << "ERROR: Could not open " << runfile << "!" << endl;
00126 exit(1);
00127 }
00128
00129 string temp_string;
00130 input_file >> temp_string;
00131 while((temp_string != "&basis") && (input_file.eof() != 1))
00132 {
00133 input_file >> temp_string;
00134 }
00135
00136 input_file >> *this;
00137 }
00138
00139 ostream& operator <<(ostream& strm, QMCBasisFunctionCoefficients& rhs)
00140 {
00141 int width = 20;
00142 strm << setw(3) << left << rhs.Label
00143 << setw(5) << right << rhs.N_Orbitals
00144 << setw(5) << rhs.Max_Gaussians << endl;
00145
00146 strm.unsetf(ios::fixed);
00147 strm.unsetf(ios::scientific);
00148
00149 for(int i=0; i<rhs.N_Orbitals; i++)
00150 {
00151 strm << right;
00152 strm << setw(3) << rhs.N_Gauss(i) << " "
00153 << setw(5) << left << rhs.Type(i) << endl;
00154 for(int j=0; j<rhs.N_Gauss(i); j++)
00155 {
00156 strm << setw(width) << right << rhs.Coeffs(i,j,0) << " ";
00157
00158 if(rhs.Coeffs(i,j,1) < 0.0) strm << " -";
00159 else strm << " ";
00160 strm << setw(width) << left << fabs(rhs.Coeffs(i,j,1)) << endl;
00161 }
00162 }
00163 strm << right;
00164 return strm;
00165 }
00166