88       return 1.0/(1.0 + 
exp(-x));
 
   98   template <std::
size_t NDIM>
 
  107               : exponent(exponent), coeff(coeff) {}
 
  111           for (std::size_t i=0; i<
NDIM; ++i) {
 
  112               sum += x[i]*exponent[i];
 
  127       std::vector<coord_3d> specialpt;
 
  130           : aofunc(aofunc), L(L), kx(kx), ky(ky), kz(kz)
 
  135           r[0]=x; r[1]=y; r[2]=z;
 
  136           specialpt=std::vector<coord_3d>(1,r);
 
  145           for (
int i=-R; i<=+R; i++) {
 
  146               double xx = x[0]+i*L;
 
  147               for (
int j=-R; j<=+R; j++) {
 
  148                   double yy = x[1]+j*L;
 
  149                   for (
int k=-R; 
k<=+R; 
k++) {
 
  150                       double zz = x[2]+
k*L;
 
  192   template <
typename T, 
int NDIM>
 
  196     typedef std::complex<T> valueT;
 
  198     typedef std::vector<functionT> vecfuncT;
 
  199     typedef std::pair<vecfuncT,vecfuncT> pairvecfuncT;
 
  200     typedef std::vector<pairvecfuncT> subspaceT;
 
  201     typedef Tensor<valueT> tensorT;
 
  202     typedef std::vector<tensorT> vectensorT;
 
  203     typedef std::vector<subspaceT> vecsubspaceT;
 
  214     vecsubspaceT _subspace;
 
  218     std::vector<KPoint> _kpoints;
 
  233             const std::vector<KPoint>& kpoints) : _world(world), _kpoints(kpoints),
 
  237       for (
unsigned int kp = 0; kp < _kpoints.size(); kp++)
 
  239         _Q.push_back(tensorT(1,1));
 
  240         _subspace.push_back(subspaceT());
 
  248                          const vecfuncT& awfs_old,
 
  249                          const vecfuncT& bwfs_old)
 
  252       vecfuncT t_rm = 
sub(_world, awfs_old, awfs_new);
 
  255         vecfuncT br = 
sub(_world, bwfs_old, bwfs_new);
 
  256         t_rm.insert(t_rm.end(), br.begin(), br.end());
 
  258       std::vector<double> rnvec = norm2<valueT,NDIM>(_world, t_rm);
 
  259       if (_world.rank() == 0)
 
  262         for (
unsigned int i = 0; i < rnvec.size(); i++) rnorm += rnvec[i];
 
  263         if (_world.rank() == 0) 
print(
"residual = ", rnorm);
 
  266       _world.gop.broadcast(_residual, 0);
 
  268       for (
unsigned int kp = 0; kp < _kpoints.size(); kp++)
 
  270         KPoint kpoint = _kpoints[kp];
 
  272         vecfuncT k_phisa(awfs_old.begin() + kpoint.begin, awfs_old.begin() + kpoint.end);
 
  273         vecfuncT k_phisb(bwfs_old.begin() + kpoint.begin, bwfs_old.begin() + kpoint.end);
 
  274         vecfuncT k_awfs(awfs_new.begin() + kpoint.begin, awfs_new.begin() + kpoint.end);
 
  275         vecfuncT k_bwfs(bwfs_new.begin() + kpoint.begin, bwfs_new.begin() + kpoint.end);
 
  279         vecfuncT k_rm = 
sub(_world, k_phisa, k_awfs);
 
  280         vecfuncT k_vm(k_phisa);
 
  283           vecfuncT k_br = 
sub(_world, k_phisb, k_bwfs);
 
  284           k_rm.insert(k_rm.end(), k_br.begin(), k_br.end());
 
  285           k_vm.insert(k_vm.end(), k_phisb.begin(), k_phisb.end());
 
  292         subspaceT k_subspace = _subspace[kp];
 
  293         k_subspace.push_back(pairvecfuncT(k_vm,k_rm));
 
  295         int m = k_subspace.size();
 
  298         for (
int s = 0; s < 
m; s++)
 
  300             const vecfuncT& k_vs = k_subspace[s].first;
 
  301             const vecfuncT& k_rs = k_subspace[s].second;
 
  302             for (
unsigned int i = 0; i < k_vm.size(); i++)
 
  304                 ms[s] += k_vm[i].inner_local(k_rs[i]);
 
  305                 sm[s] += k_vs[i].inner_local(k_rm[i]);
 
  308         _world.gop.sum(ms.ptr(),
m);
 
  309         _world.gop.sum(sm.ptr(),
m);
 
  312         if (m > 1) newQ(
Slice(0,-2),
Slice(0,-2)) = _Q[kp];
 
  317         if (_world.rank() == 0) 
print(_Q[kp]);
 
  321         if (_world.rank() == 0) {
 
  322             double rcond = 1e-12;
 
  324                 c = 
KAIN(_Q[kp],rcond);
 
  325                 if (
abs(c[m-1]) < 3.0) {
 
  328                 else if (rcond < 0.01) {
 
  329                     if (_world.rank() == 0)
 
  330                       print(
"Increasing subspace singular value threshold ", c[m-1], rcond);
 
  334                     if (_world.rank() == 0)
 
  335                       print(
"Forcing full step due to subspace malfunction");
 
  343         _world.gop.broadcast_serializable(c, 0);
 
  344         if (_world.rank() == 0) {
 
  347             print(
"Subspace solution", c);
 
  351         vecfuncT k_phisa_new = zero_functions<valueT,NDIM>(_world, k_phisa.size());
 
  352         vecfuncT k_phisb_new = zero_functions<valueT,NDIM>(_world, k_phisb.size());
 
  353         compress(_world, k_phisa_new, 
false);
 
  354         compress(_world, k_phisb_new, 
false);
 
  356         std::complex<double> 
one = std::complex<double>(1.0,0.0);
 
  357         unsigned int norbitals = awfs_old.size() / _kpoints.size();
 
  358         for (
unsigned int m = 0; m < k_subspace.size(); m++)
 
  360             const vecfuncT& k_vm = k_subspace[
m].first;
 
  361             const vecfuncT& k_rm = k_subspace[
m].second;
 
  363             const vecfuncT  vma(k_vm.begin(),k_vm.begin() + norbitals);
 
  364             const vecfuncT  rma(k_rm.begin(),k_rm.begin() + norbitals);
 
  365             const vecfuncT  vmb(k_vm.end() - norbitals, k_vm.end());
 
  366             const vecfuncT  rmb(k_rm.end() - norbitals, k_rm.end());
 
  368             gaxpy(_world, one, k_phisa_new, 
c(m), vma, 
false);
 
  369             gaxpy(_world, one, k_phisa_new,-
c(m), rma, 
false);
 
  370             gaxpy(_world, one, k_phisb_new, 
c(m), vmb, 
false);
 
  371             gaxpy(_world, one, k_phisb_new,-
c(m), rmb, 
false);
 
  375         if (_params.
maxsub <= 1) {
 
  379         else if (k_subspace.size() == _params.
maxsub) {
 
  381             k_subspace.erase(k_subspace.begin());
 
  385         _subspace[kp] = k_subspace;
 
  387         for (
unsigned int wi = kpoint.begin, fi = 0; wi < kpoint.end;
 
  390           awfs_new[wi] = k_phisa_new[fi];
 
  391           bwfs_new[wi] = k_phisb_new[fi];
 
  411   template <
typename T, 
int NDIM>
 
  415     typedef std::complex<T> valueT;
 
  417     typedef std::vector<functionT> vecfuncT;
 
  418     typedef std::pair<vecfuncT,vecfuncT> pairvecfuncT;
 
  419     typedef std::vector<pairvecfuncT> subspaceT;
 
  420     typedef Tensor<valueT> tensorT;
 
  435     std::vector<KPoint> _kpoints;
 
  446       : _world(world), _params(params)
 
  454                          const vecfuncT& awfs_old,
 
  455                          const vecfuncT& bwfs_old,
 
  459       vecfuncT vm = awfs_old;
 
  462         vm.insert(vm.end(), bwfs_old.begin(), bwfs_old.end());
 
  469       _subspace.push_back(pairvecfuncT(vm,rm));
 
  471       int m = _subspace.size();
 
  474       for (
int s=0; s<
m; s++)
 
  476           const vecfuncT& vs = _subspace[s].first;
 
  477           const vecfuncT& rs = _subspace[s].second;
 
  478           for (
unsigned int i=0; i<vm.size(); i++)
 
  480               ms[s] += vm[i].inner_local(rs[i]);
 
  481               sm[s] += vs[i].inner_local(rm[i]);
 
  488       if (m > 1) newQ(
Slice(0,-2),
Slice(0,-2)) = _Q;
 
  497       if (_world.
rank() == 0) {
 
  498           double rcond = 1e-12;
 
  501               if (
abs(c[m-1]) < 3.0) {
 
  504               else if (rcond < 0.01) {
 
  505                   if (_world.
rank() == 0)
 
  506                     print(
"Increasing subspace singular value threshold ", c[m-1], rcond);
 
  510                   if (_world.
rank() == 0)
 
  511                     print(
"Forcing full step due to subspace malfunction");
 
  520       if (_world.
rank() == 0) {
 
  523           print(
"Subspace solution", c);
 
  527       vecfuncT phisa_new = zero_functions<valueT,NDIM>(_world, awfs_old.
size());
 
  528       vecfuncT phisb_new = zero_functions<valueT,NDIM>(_world, bwfs_old.size());
 
  532       std::complex<double> 
one = std::complex<double>(1.0,0.0);
 
  533       for (
unsigned int m=0; m<_subspace.size(); m++) {
 
  534           const vecfuncT& vm = _subspace[
m].first;
 
  535           const vecfuncT& rm = _subspace[
m].second;
 
  536           const vecfuncT  vma(vm.begin(),vm.begin()+awfs_old.size());
 
  537           const vecfuncT  rma(rm.begin(),rm.begin()+awfs_old.size());
 
  538           const vecfuncT  vmb(vm.end()-bwfs_old.size(), vm.end());
 
  539           const vecfuncT  rmb(rm.end()-bwfs_old.size(), rm.end());
 
  541           gaxpy(_world, one, phisa_new, 
c(m), vma, 
false);
 
  542           gaxpy(_world, one, phisa_new,-
c(m), rma, 
false);
 
  543           gaxpy(_world, one, phisb_new, 
c(m), vmb, 
false);
 
  544           gaxpy(_world, one, phisb_new,-
c(m), rmb, 
false);
 
  548       if (_params.
maxsub <= 1) {
 
  552       else if (_subspace.size() == _params.
maxsub) {
 
  554           _subspace.erase(_subspace.begin());
 
  557       awfs_new = phisa_new;
 
  558       bwfs_new = phisb_new;
 
  624   template <
typename T, 
int NDIM>
 
  628     typedef std::complex<T> valueT;
 
  632     typedef std::vector<functionT> vecfuncT;
 
  637     typedef Tensor<double> rtensorT;
 
  638     typedef Tensor<std::complex<double> > ctensorT;
 
  639     typedef Tensor<valueT> tensorT;
 
  640     typedef std::pair<vecfuncT,vecfuncT> pairvecfuncT;
 
  641     typedef std::vector<pairvecfuncT> subspaceT;
 
  642     typedef std::vector<tensorT> vectensorT;
 
  643     typedef std::vector<subspaceT> vecsubspaceT;
 
  653     rfunctionT _vnucrhon;
 
  665     std::vector<T> _eigsa;
 
  669     std::vector<T> _eigsb;
 
  677     std::vector<KPoint> _kpoints;
 
  681     std::vector<double> _occsa;
 
  685     std::vector<double> _occsb;
 
  737     std::ofstream _outputF;
 
  749     std::ofstream _kmeshF;
 
  773     ttt=
wall_time()-
ttt; sss=cpu_time()-
sss; 
if (world.
rank()==0) printf(
"timer: %20.20s %8.2fs %8.2fs\n", msg, sss, ttt);
 
  800       if (_world.
rank() == 0)
 
  816       if (_world.
rank() == 0)
 
  830       if ((_params.
nelec % 2) == 1) _params.
nelec++;
 
  833       _outputF.open(
"output.txt");
 
  834       _matF.open(
"matrix.txt");
 
  835       _eigF.open(
"eigs.txt");
 
  850             double t1 = TWO_PI/_params.
L;
 
  853             _kpoints.push_back(
KPoint(c1, 0.5));
 
  854             _kpoints.push_back(
KPoint(c2, 0.5));
 
  868         if (_world.
rank() == 0)
 
  870           _kmeshF.open(
"kpoints.txt");
 
  871           _kmeshF << 
"kpts: " << _kpoints.size() << endl;
 
  872           _kmeshF << 
"ik" << setw(10) << 
"kpt" << setw(30) << 
"weight" << endl;
 
  873           _kmeshF << 
"--" << setw(10) << 
"---" << setw(30) << 
"------" << endl;
 
  878           for (
unsigned int i = 0; i < _kpoints.size(); i++)
 
  880             KPoint kpoint = _kpoints[i];
 
  881             _kmeshF << i << setw(10) << kpoint.k[0];
 
  882             _kmeshF << setw(10) << kpoint.k[1];
 
  883             _kmeshF << setw(10) << kpoint.k[2];
 
  884             _kmeshF << setw(10) << kpoint.
weight << endl;
 
  897     std::vector<KPoint> 
genkmesh(
unsigned int ngridk0, 
unsigned ngridk1, 
unsigned int ngridk2,
 
  898                                  double koffset0, 
double koffset1, 
double koffset2, 
double R)
 
  900       std::vector<KPoint> kmesh;
 
  901       double step0 = 1.0/ngridk0;
 
  902       double step1 = 1.0/ngridk1;
 
  903       double step2 = 1.0/ngridk2;
 
  904       double weight = 1.0/(ngridk0*ngridk1*ngridk2);
 
  906       for (
unsigned int i = 0; i < ngridk0; i++)
 
  908         for (
unsigned int j = 0; j < ngridk1; j++)
 
  910           for (
unsigned int k = 0; 
k < ngridk2; 
k++)
 
  915             double k0 = ((i*step0)+koffset0) * TWO_PI/R;
 
  916             double k1 = ((j*step1)+koffset1) * TWO_PI/R;
 
  917             double k2 = ((
k*step2)+koffset2) * TWO_PI/R;
 
  918             KPoint kpoint(k0, k1, k2, weight);
 
  919             kmesh.push_back(kpoint);
 
  932       ar & (
unsigned int)(_kpoints.size());
 
  933       for (
unsigned int i = 0; i < _kpoints.size(); i++) ar & _kpoints[i];
 
  936       ar & (
unsigned int)(_phisa.size());
 
  937       for (
unsigned int i = 0; i < _phisa.size(); i++) ar & _phisa[i];
 
  942         ar & (
unsigned int)(_phisb.size());
 
  943         for (
unsigned int i = 0; i < _phisb.size(); i++) ar & _phisb[i];
 
  963       for (
unsigned int i = 0; i < nkpts; i++)
 
  967         _kpoints.push_back(tkpt);
 
  984       for (
unsigned int i = 0; i < norbs; i++)
 
  988         _phisa.push_back(tfunc);
 
  989         _eigsa.push_back(-0.1);
 
  992       if (_phisa[0].k() != k)
 
  995         for (
unsigned int i = 0; i < _phisa.size(); i++)
 
 1000       for (
unsigned int i = 0; i < _kpoints.size(); i++)
 
 1007         for (
unsigned int i = 0; i < norbs; i++)
 
 1011           _phisb.push_back(tfunc);
 
 1012           _eigsb.push_back(-0.1);
 
 1015         if (_phisb[0].k() != k)
 
 1018           for (
unsigned int i = 0; i < _phisb.size(); i++)
 
 1023         for (
unsigned int i = 0; i < _kpoints.size(); i++)
 
 1028         for (
unsigned int i = 0; i < norbs; i++)
 
 1030           _phisb.push_back(_phisa[i]);
 
 1031           _eigsb.push_back(_eigsa[i]);
 
 1035       _occsa = std::vector<double>(norbs, 0.0);
 
 1036       _occsb = std::vector<double>(norbs, 0.0);
 
 1044       _vnuc = 
copy(_vnucrhon);
 
 1051       std::vector<coordT> specialpts;
 
 1052       for (
int i = 0; i < _mentity.
natom(); i++)
 
 1056         pt[0] = atom.
x; pt[1] = atom.
y; pt[2] = atom.
z;
 
 1057         specialpts.push_back(pt);
 
 1058         if (_world.
rank() == 0) 
print(
"Special point: ", pt);
 
 1066       _vnucrhon = rfactoryT(_world).functor(
 
 1068           thresh(_params.
thresh).initial_level(6).truncate_on_project();
 
 1071       if (_world.
rank() == 0) 
print(
"calculating trace of rhon ..\n\n");
 
 1072       double rtrace = _vnucrhon.trace();
 
 1073       if (_world.
rank() == 0) 
print(
"rhon trace = ", rtrace);
 
 1075       _vnucrhon.truncate();
 
 1076       _vnuc = 
apply(*_cop, _vnucrhon);
 
 1078       if (_world.
rank() == 0) 
print(
"Done creating nuclear potential ..\n");
 
 1082       rfunctionT vnuc2 = rfactoryT(_world).functor(
rfunctorT(
new 
 1085       rfunctionT vnucdiff = _vnuc-vnuc2;
 
 1086       double t1 = vnucdiff.
trace();
 
 1087       if (_world.
rank() == 0) printf(
"Difference in nuclear potential: %15.8f\n\n", t1);
 
 1088       for (
int i = 0; i < 101; i++)
 
 1090         double dx = _params.
L/100;
 
 1091         double pt2 = -_params.
L/2 + dx*i;
 
 1093         double val = vnucdiff(cpt);
 
 1094         if (_world.
rank() == 0) printf(
"%10.5f    %15.8f\n",pt2,val);
 
 1107       if (_world.
rank() == 0)
 
 1109         printf(
"Cell parameters\n");
 
 1110         printf(
"------------------------------\n");
 
 1111         print(
"cell(x) is ",csize(0,0), csize(0,1));
 
 1112         print(
"cell(y) is ",csize(1,0), csize(1,1));
 
 1113         print(
"cell(z) is ",csize(2,0), csize(2,1));
 
 1139             for (
int xr = -2; xr <= 2; xr += 1)
 
 1141               for (
int yr = -2; yr <= 2; yr += 1)
 
 1143                 for (
int zr = -2; zr <= 2; zr += 1)
 
 1146                       x[0]+xr*R, x[1]+yr*R, x[2]+zr*R);
 
 1159             const double& R, 
const bool& periodic)
 
 1160         : mentity(mentity), aobasis(aobasis), R(R), periodic(periodic) {}
 
 1165     template <
typename Q>
 
 1171       double delta = _params.
L/(npts-1);
 
 1172       double begin = -_params.
L/2;
 
 1173       double end = _params.
L/2;
 
 1176       printf(
"periodicity along x-axis:  \n");
 
 1177       printf(
"-------------------------------------------------------------\n\n");
 
 1178       for (
int i = 0; i < npts; i++)
 
 1180         printf(
"\n-------------------- edge --------------------\n");
 
 1181         for (
int j = 0; j < npts; j++)
 
 1184           r1[0] = begin+eps; r1[1] = (i*
delta)+begin; r1[2] = (j*
delta)+begin;
 
 1185           r2[0] = end-eps; r2[1] = (i*
delta)+begin; r2[2] = (j*
delta)+begin;
 
 1186           dr1[0] = begin+2*eps; dr1[1] = (i*
delta)+begin; dr1[2] = (j*
delta)+begin;
 
 1187           dr2[0] = end-2*eps; dr2[1] = (i*
delta)+begin; dr2[2] = (j*
delta)+begin;
 
 1188           double val = std::abs(
f(r1)-
f(r2));
 
 1189           std::string success = val < tol ? 
"PASS!" : 
"FAIL!";
 
 1190           printf(
"%10.6f%10.6f%10.6f  %10.6f%10.6f%10.6f  %10.5e   %s\n",
 
 1191               r1[0],r1[1],r1[2],r2[0],r2[1],r2[2],val,success.c_str());
 
 1195       printf(
"\nperiodicity along y-axis:  \n");
 
 1196       printf(
"-------------------------------------------------------------\n\n");
 
 1197       for (
int i = 0; i < npts; i++)
 
 1199         printf(
"\n-------------------- edge --------------------\n");
 
 1200         for (
int j = 0; j < npts; j++)
 
 1203           r1[0] = (i*
delta)+begin; r1[1] = begin+eps; r1[2] = (j*
delta)+begin;
 
 1204           r2[0] = (i*
delta)+begin; r2[1] = end-eps; r2[2] = (j*
delta)+begin;
 
 1205           dr1[0] = (i*
delta)+begin; dr1[1] = begin+2*eps; dr1[2] = (j*
delta)+begin;
 
 1206           dr2[0] = (i*
delta)+begin; dr2[1] = end-2*eps; dr2[2] = (j*
delta)+begin;
 
 1207           double val = std::abs(
f(r1)-
f(r2));
 
 1208           std::string success = val < tol ? 
"PASS!" : 
"FAIL!";
 
 1209           printf(
"%10.6f%10.6f%10.6f  %10.6f%10.6f%10.6f  %10.5e   %s\n",
 
 1210               r1[0],r1[1],r1[2],r2[0],r2[1],r2[2],val,success.c_str());
 
 1214       printf(
"\nperiodicity along z-axis:  \n");
 
 1215       printf(
"-------------------------------------------------------------\n\n");
 
 1216       for (
int i = 0; i < npts; i++)
 
 1218         printf(
"\n-------------------- edge --------------------\n");
 
 1219         for (
int j = 0; j < npts; j++)
 
 1222           r1[0] = (i*
delta)+begin; r1[1] = (j*
delta)+begin; r1[2] = begin+eps;
 
 1223           r2[0] = (i*
delta)+begin; r2[1] = (j*
delta)+begin; r2[2] = end-eps;
 
 1224           dr1[0] = (i*
delta)+begin; dr1[1] = (j*
delta)+begin; dr1[2] = begin+2*eps;
 
 1225           dr2[0] = (i*
delta)+begin; dr2[1] = (j*
delta)+begin; dr2[2] = end-2*eps;
 
 1226           double val = std::abs(
f(r1)-
f(r2));
 
 1227           std::string success = val < tol ? 
"PASS!" : 
"FAIL!";
 
 1228           printf(
"%10.6f%10.6f%10.6f  %10.6f%10.6f%10.6f  %10.5e   %s\n",
 
 1229               r1[0],r1[1],r1[2],r2[0],r2[1],r2[2],val,success.c_str());
 
 1238                        const rfunctionT& arho,
 
 1239                        const rfunctionT& brho,
 
 1240                        const rfunctionT& adelrhosq,
 
 1241                        const rfunctionT& bdelrhosq)
 
 1244         rfunctionT vlda = 
copy(arho);
 
 1246         vlda.
unaryop(&::ldaop<double>);
 
 1251         vecfuncT ao(_aobasis.
nbf(_mentity));
 
 1268         for (
int i=0; i < _aobasis.
nbf(_mentity); i++) {
 
 1270               _params.
L, kpt.k[0], kpt.k[1], kpt.k[2]));
 
 1271             ao[i] = factoryT(world).functor(aofunc).truncate_on_project().truncate_mode(0);
 
 1297            rfunctionT vnucrhon,
 
 1300            std::vector<T> eigsa,
 
 1301            std::vector<T> eigsb,
 
 1304        : _world(world), _vnucrhon(vnucrhon), _phisa(phisa), _phisb(phisb),
 
 1305        _eigsa(eigsa), _eigsb(eigsb), _params(params), _mentity(mentity)
 
 1308       _cop = CoulombOperatorPtr(const_cast<World&>(world), params.
lo, params.
thresh * 0.1);
 
 1312         _vnuc = 
copy(_vnucrhon);
 
 1316         _vnuc = 
apply(*_cop, _vnucrhon);
 
 1326       if (_world.
rank() == 0) 
print(
"Guessing rho ...\n\n");
 
 1328       rfunctionT rho = rfactoryT(_world);
 
 1332               _aobasis, _params.
L, _params.
periodic))).initial_level(3);
 
 1363           if (_world.
rank() == 0) 
print(
"Creating Coulomb op ...\n\n");
 
 1371             op = CoulombOperatorPtr(_world, _params.
lo, _params.
thresh * 0.1);
 
 1375             op = CoulombOperatorPtr(_world, _params.
lo, _params.
thresh * 0.1);
 
 1377           if (_world.
rank() == 0) 
print(
"Building effective potential ...\n\n");
 
 1378           rfunctionT vc = 
apply(*op, rho);
 
 1379           vlocal = _vnuc + vc; 
 
 1386           vlocal = vlocal + vlda;
 
 1401         int _nao = _aobasis.
nbf(_mentity);
 
 1404         int nkpts = _kpoints.size();
 
 1406         int norbs = _params.
nbands * nkpts;
 
 1408         if (_params.
nbands > _nao)
 
 1409           MADNESS_EXCEPTION(
"Error: basis not large enough to accomodate number of bands", _nao);
 
 1411         _eigsa = std::vector<double>(norbs, 0.0);
 
 1412         _eigsb = std::vector<double>(norbs, 0.0);
 
 1413         _occsa = std::vector<double>(norbs, 0.0);
 
 1414         _occsb = std::vector<double>(norbs, 0.0);
 
 1415         if (_world.
rank() == 0) 
print(
"Building kinetic energy matrix ...\n\n");
 
 1417         for (
int ki = 0; ki < nkpts; ki++)
 
 1420           if (_world.
rank() == 0) 
print(
"Projecting atomic orbitals ...\n\n");
 
 1423           END_TIMER(_world, 
"projecting atomic orbital basis");
 
 1429           for (
unsigned int ai = 0; ai < ao.size(); ai++)
 
 1431             std::vector<long> npt(3,101);
 
 1433             sprintf(fnamedx, 
"aofunc_k_%2.2d__%2.2d__.dx",ki,ai);
 
 1434             std::vector<long> npt2(3,101);
 
 1440           for (
int i = 0; i < ao.size(); i++)
 
 1443             sprintf(fname, 
"ao_line_%d.txt",i);
 
 1447           sprintf(fname2, 
"vnuc_line.txt");
 
 1450           sprintf(fname3, 
"vlocal_line.txt");
 
 1468           KPoint& kpoint = _kpoints[ki];
 
 1484           ctensorT kinetic = ::kinetic_energy_matrix_slow<T,NDIM>(_world, ao, _params.
periodic, kpoint);
 
 1486           if (_world.rank() == 0) 
print(
"Building overlap matrix ...\n\n");
 
 1490           if (_world.rank() == 0) 
print(
"Building potential energy matrix ...\n\n");
 
 1493           for (
int i = 0; i < ao.size(); i++)
 
 1494             vpsi.push_back(vlocal*ao[i]);
 
 1507           ctensorT fock = potential + kinetic;
 
 1509           if (_world.rank() == 0)
 
 1513             print(
"Potential:");
 
 1515             print(
"Fock: (pre-symmetrized)");
 
 1517             print(
"FockZero: (should be zero)");
 
 1523           for (
unsigned int i = 0; i < fock.dim(0); i++)
 
 1525             fock(i,i) += i*_params.
thresh*0.1;
 
 1528           ctensorT 
c; rtensorT e;
 
 1529           sygv(fock, overlap, 1, c, e);
 
 1532           ctensorT ck; rtensorT ek;
 
 1533           sygv(kinetic, overlap, 1, ck, ek);
 
 1535           ctensorT cp; rtensorT ep;
 
 1536           sygv(potential, overlap, 1, cp, ep);
 
 1538           ctensorT co; rtensorT eo;
 
 1539           syev(overlap, co, eo);
 
 1541           if (_world.rank() == 0)
 
 1543             print(
"fock eigenvectors dims:",c.dim(0),c.dim(1));
 
 1544             print(
"fock eigenvectors:");
 
 1548           if (_world.rank() == 0)
 
 1550             print(
"kinetic eigenvalues");
 
 1554           if (_world.rank() == 0)
 
 1556             print(
"potential eigenvalues");
 
 1560           if (_world.rank() == 0)
 
 1562             print(
"overlap eigenvalues");
 
 1565           if (_world.rank() == 0)
 
 1567             print(
"fock eigenvalues");
 
 1571           if (_world.rank() == 0)
 
 1573             printf(
"Overlap: \n");
 
 1574             for (
int i = 0; i < overlap.dim(0); i++)
 
 1576                     for (
int j = 0; j < overlap.dim(1); j++)
 
 1578                             printf(
"%10.5f", 
real(overlap(i,j)));
 
 1590           vecfuncT tmp_orbitals = 
transform(_world, ao, 
c(_, 
Slice(0, _nao - 1)));
 
 1723           if (_world.rank() == 0) 
print(
"Building overlap matrix ...\n\n");
 
 1724           ctensorT overlap2 = 
matrix_inner(_world, tmp_orbitals, tmp_orbitals, 
true);
 
 1726           rtensorT tmp_eigs = e(
Slice(0, _nao - 1));
 
 1728           if (_world.rank() == 0) printf(
"(%8.4f,%8.4f,%8.4f)\n",kpoint.k[0], kpoint.k[1], kpoint.k[2]);
 
 1729           if (_world.rank() == 0) 
print(tmp_eigs);
 
 1730           if (_world.rank() == 0) 
print(
"\n");
 
 1737           if (_world.rank() == 0) {
 
 1738               printf(
"Overlap: \n");
 
 1739               for (
int i = 0; i < kinetic.dim(0); i++)
 
 1741                       for (
int j = 0; j < kinetic.dim(1); j++)
 
 1743                               printf(
"%10.5f", 
real(overlap(i,j)));
 
 1750               printf(
"Kinetic: \n");
 
 1751               for (
int i = 0; i < kinetic.dim(0); i++)
 
 1753                       for (
int j = 0; j < kinetic.dim(1); j++)
 
 1755                               printf(
"%10.5f", 
real(kinetic(i,j)));
 
 1763               for (
int i = 0; i < potential.dim(0); i++)
 
 1765                       for (
int j = 0; j < potential.dim(1); j++)
 
 1775               for (
int i = 0; i < fock.dim(0); i++)
 
 1777                       for (
int j = 0; j < fock.dim(1); j++)
 
 1779                               printf(
"%10.5f", 
real(fock(i,j)));
 
 1786               printf(
"New overlap: \n");
 
 1787               for (
int i = 0; i < overlap2.dim(0); i++)
 
 1789                       for (
int j = 0; j < overlap2.dim(1); j++)
 
 1791                               printf(
"%10.5f", 
real(overlap2(i,j)));
 
 1800           kpoint.begin = ki*_params.
nbands;
 
 1801           kpoint.end = (ki+1)*_params.
nbands;
 
 1802           for (
unsigned int oi = kpoint.begin, ti = 0; oi < kpoint.end; oi++, ti++)
 
 1807             _phisa.push_back(tmp_orbitals[ti]);
 
 1808             _phisb.push_back(tmp_orbitals[ti]);
 
 1809             _eigsa[oi] = tmp_eigs[ti];
 
 1810             _eigsb[oi] = tmp_eigs[ti];
 
 1820            const rfunctionT& vnucrhon,
 
 1821            const vecfuncT& phis,
 
 1822            const std::vector<T>& eigs,
 
 1825        : _world(world), _vnucrhon(vnucrhon), _phisa(phis), _phisb(phis),
 
 1826        _eigsa(eigs), _eigsb(eigs), _params(params), _mentity(mentity)
 
 1834         _cop = CoulombOperatorPtr(const_cast<World&>(world), params.
lo, params.
thresh * 0.1);
 
 1838         _cop = CoulombOperatorPtr(const_cast<World&>(world), params.
lo, params.
thresh * 0.1);
 
 1843         _vnuc = 
copy(_vnucrhon);
 
 1847         _vnuc = 
apply(*_cop, _vnucrhon);
 
 1855            rfunctionT vnucrhon,
 
 1857            std::vector<T> eigs,
 
 1858            std::vector<KPoint> kpoints,
 
 1859            std::vector<double> occs,
 
 1862        : _world(world), _vnucrhon(vnucrhon), _phisa(phis), _phisb(phis),
 
 1863          _eigsa(eigs), _eigsb(eigs), _params(params),
 
 1864          _kpoints(kpoints), _occsa(occs), _occsb(occs), _mentity(mentity)
 
 1870         _cop = CoulombOperatorPtr(const_cast<World&>(world), params.
lo, params.
thresh * 0.1);
 
 1874         _cop = CoulombOperatorPtr(const_cast<World&>(world), params.
lo, params.
thresh * 0.1);
 
 1879         _vnuc = 
copy(_vnucrhon);
 
 1883         _vnuc = 
apply(*_cop, _vnucrhon);
 
 1901                    const std::vector<double>& eigsa,
 
 1902                    const std::vector<double>& eigsb,
 
 1903                    std::vector<double>& occsa,
 
 1904                    std::vector<double>& occsb)
 
 1906       for (
unsigned int ik = 0; ik < kpoints.size(); ik++)
 
 1912         const std::vector<double> k_eigsa(eigsa.begin() + k.begin, eigsa.begin() + k.end);
 
 1913         const std::vector<double> k_eigsb(eigsb.begin() + k.begin, eigsb.begin() + k.end);
 
 1914         std::vector<double> k_occsa(occsa.begin() + k.begin, occsa.begin() + k.end);
 
 1915         std::vector<double> k_occsb(occsb.begin() + k.begin, occsb.begin() + k.end);
 
 1918         unsigned int sz = k_eigsa.size();
 
 1919         MADNESS_ASSERT(k_eigsb.size() == sz);
 
 1920         MADNESS_ASSERT(k_occsa.size() == sz);
 
 1921         MADNESS_ASSERT(k_occsb.size() == sz);
 
 1923         std::vector<double> teigs;
 
 1927         for (
unsigned int ist = 0; ist < k_eigsa.size(); ist++) teigs.push_back(k_eigsa[ist]);
 
 1928         for (
unsigned int ist = 0; ist < k_eigsb.size(); ist++) teigs.push_back(k_eigsb[ist]);
 
 1930         if (_world.
rank() == 0) printf(
"setting occs ....\n\n");
 
 1931         for (
unsigned int ist = 0; ist < teigs.size(); ist++)
 
 1933           if (_world.
rank() == 0)
 
 1935             printf(
"%5d    %15.8f\n", ist, teigs[ist]);
 
 1940         std::vector<unsigned int> inds(2*sz);
 
 1941         for (
unsigned int i = 0; i < 2*sz; i++) inds[i] = i;
 
 1943         for (
unsigned int i = 0; i < 2*sz; i++)
 
 1945           for (
unsigned int j = i+1; j < 2*sz; j++)
 
 1947             if (teigs[j] < teigs[i])
 
 1949               double t1 = teigs[i];
 
 1950               teigs[i] = teigs[j];
 
 1959         if (_world.
rank() == 0)
 
 1960           printf(
"\nSorted eigenvalues:\n");
 
 1961         for (
unsigned int i = 0; i < teigs.size(); i++)
 
 1963           if (_world.
rank() == 0)
 
 1964             printf(
"%10d%10d     %15.8f\n",i,inds[i],teigs[i]);
 
 1968         double availablecharge = _params.
ncharge;
 
 1969         for (
unsigned int i = 0; (i < 2*sz) && (availablecharge > 0.0) ; i++)
 
 1971           unsigned int current = inds[i];
 
 1975             k_occsb[current] = 1.0;
 
 1976             availablecharge -= 1.0;
 
 1980             k_occsa[current] = 1.0;
 
 1981             availablecharge -= 1.0;
 
 1985         for (
unsigned int ik1 = k.begin, ik2 = 0; ik1 < k.end; ik1++,ik2++)
 
 1987           occsa[ik1] = k_occsa[ik2];
 
 1988           occsb[ik1] = k_occsb[ik2];
 
 1992       for (
unsigned int ik = 0; ik < kpoints.size(); ik++)
 
 1995         if (_world.
rank() == 0)
 
 1997           printf(
"k-point is: %d: \n",ik);
 
 1999         for (
unsigned int ist = k.begin; ist < k.end; ist++)
 
 2001           if (_world.
rank() == 0)
 
 2003             printf(
"occa:    %12.5f          occb:    %12.5f \n",occsa[ist],occsb[ist]);
 
 2018                                std::vector<double> occs)
 
 2021       rfunctionT rho = rfactoryT(_world);
 
 2023       if (_world.
rank() == 0) _outputF << 
"computing rho ..." << endl;
 
 2025       for (
unsigned int kp = 0; kp < kpoints.size(); kp++)
 
 2028         KPoint kpoint = kpoints[kp];
 
 2030         for (
unsigned int j = kpoint.begin; j < kpoint.end; j++)
 
 2033           const functionT& phij = phis[j];
 
 2036           rfunctionT prod = 
abssq(phij,
true);
 
 2037           double rnrm = prod.
trace();
 
 2040           rho += occs[j] * kpoint.
weight * prod;
 
 2049     rfunctionT 
compute_rho(
const vecfuncT& phis, std::vector<KPoint> kpoints,
 
 2050                           std::vector<double> occs)
 
 2052       if (_world.
rank() == 0) _outputF << 
"computing rho ..." << endl;
 
 2053       rfunctionT rho = rfactoryT(_world);       
 
 2056       std::vector<rfunctionT> phisq(phis.size());
 
 2057       for (
unsigned int i=0; i<phis.size(); i++) {
 
 2058           phisq[i] = 
abssq(phis[i],
false);
 
 2061       std::vector<double> phinorm = 
norm2s(_world, phis);
 
 2067       for (
unsigned int kp = 0; kp < kpoints.size(); kp++)
 
 2070         KPoint kpoint = kpoints[kp];
 
 2072         for (
unsigned int j = kpoint.begin; j < kpoint.end; j++)
 
 2074           rho.
gaxpy(1.0, phisq[j], occs[j] * kpoint.
weight / (phinorm[j]*phinorm[j]), 
false);
 
 2091       std::vector<poperatorT> bops;
 
 2096       int sz = eigs.size();
 
 2097       for (
int i = 0; i < sz; i++)
 
 2102               if (_world.
rank() == 0)
 
 2104                   std::cout << 
"bsh: warning: positive eigenvalue" << i << eps << endl;
 
 2109           bops.push_back(poperatorT(BSHOperatorPtr3D(_world, 
sqrt(-2.0*eps), _params.
lo, tol * 0.1)));
 
 2150         for (
unsigned int i = 0; i < _phisa.size(); i++)
 
 2152           functionT dpdx = Dx(_phisa[i]);
 
 2153           functionT dpdy = Dy(_phisa[i]);
 
 2154           functionT dpdz = Dz(_phisa[i]);
 
 2160           for (
unsigned int i = 0; i < _phisb.size(); i++)
 
 2162             functionT dpdx = Dx(_phisb[i]);
 
 2163             functionT dpdy = Dy(_phisb[i]);
 
 2164             functionT dpdz = Dz(_phisb[i]);
 
 2185         vecfuncT& pfuncsb, 
const vecfuncT& phisa,
 
 2186         const vecfuncT& phisb, 
const rfunctionT& rhoa, 
const rfunctionT& rhob,
 
 2187         const rfunctionT& rho)
 
 2190       rfunctionT vc = 
apply(*_cop, rho);
 
 2193       rfunctionT rho2 = rho + _vnucrhon;
 
 2194       double vnucrhontrace = _vnucrhon.
trace();
 
 2195       double rhotrace = rho.
trace();
 
 2196       double rho2trace = rho2.
trace();
 
 2197       if (_world.
rank() == 0) printf(
"_vnucrhon trace: %10e\n", vnucrhontrace);
 
 2198       if (_world.
rank() == 0) printf(
"rho trace: %10e\n", rhotrace);
 
 2199       if (_world.
rank() == 0) printf(
"rho2 trace: %10e\n", rho2trace);
 
 2200       rfunctionT vlocal = (_params.
ispotential) ? _vnuc + vc : 
apply(*_cop, rho2);
 
 2201       rfunctionT vlocal2 = _vnuc + vc;
 
 2202       double vlerr = (vlocal-vlocal2).
norm2();
 
 2203       if (_world.
rank() == 0) printf(
"vlerr trace: %10e\n\n", vlerr);
 
 2207       double ce = 0.5*
inner(vc,rho);
 
 2208       double pe = 
inner(_vnuc,rho);
 
 2231           rfunctionT vxc = 
copy(rhoa);
 
 2234           vxc.
unaryop(&::ldaop<double>);
 
 2252           END_TIMER(_world,
"Applying LDA potential");
 
 2254           rfunctionT fc = 
copy(rhoa);
 
 2255           fc.
unaryop(&::ldaeop<double>);
 
 2263         END_TIMER(_world,
"Applying local potential");
 
 2274         END_TIMER(_world, 
"Applying HF exchange");
 
 2276       std::cout.precision(8);
 
 2277       if (_world.
rank() == 0)
 
 2279         printf(
"Energies:\n");
 
 2280         printf(
"Kinetic energy:     %20.10f\n", ke);
 
 2281         printf(
"Potential energy:   %20.10f\n", pe);
 
 2282         printf(
"Coulomb energy:     %20.10f\n", ce);
 
 2283         printf(
"Exchange energy:    %20.10f\n", xc);
 
 2284         printf(
"Total energy:       %20.10f\n\n", ke + pe + ce + xc);
 
 2326                             vecfuncT& funcsa, vecfuncT& funcsb,
 
 2329       for (
unsigned int j = 0; j < phisa.size(); j++)
 
 2331         rfunctionT phi_j = 
real(phisa[j]);
 
 2333         rfunctionT dprod = phi_j*phi_j;
 
 2335         rfunctionT dVex = 
apply(*_cop,dprod);
 
 2336         functionT tf_jjj = dVex*phisa[j];
 
 2337         funcsa[j] -= tf_jjj;
 
 2339         for (
unsigned int i = j+1; i < phisa.size(); i++)
 
 2341           rfunctionT phi_i = 
real(phisa[i]);
 
 2342           rfunctionT prod = phi_i*phi_j;
 
 2344           rfunctionT Vex = 
apply(*_cop,prod);
 
 2346           functionT tf_jij = Vex*phisa[j];
 
 2347           funcsa[i] -= tf_jij;
 
 2351           functionT tf_iji = Vex*phisa[i];
 
 2352           funcsa[j] -= tf_iji;
 
 2362       for (
unsigned int i = 0; i < _kpoints.size(); i++)
 
 2365         if (k1.is_orb_in_kpoint(idx)) 
return k1;
 
 2374                            vecfuncT& funcsa, vecfuncT& funcsb,
 
 2377       for (
unsigned int i = 0; i < phisa.size(); i++)
 
 2379         functionT phi_i = phisa[i];
 
 2381         for (
unsigned int j = 0; j < phisa.size(); j++)
 
 2383           functionT phi_j = phisa[j];
 
 2386                                    (k_i.k[1]-k_j.k[1])*_params.
L,
 
 2387                                    (k_i.k[2]-k_j.k[2])*_params.
L);
 
 2392               factoryT(_world).functor(
functorT(
new 
 2394           functionT cexp2 = 
conj(cexp);
 
 2397           functionT prod = phi_i*phi_j*cexp;
 
 2399               PeriodicHFExchangeOperator(_world, q, _params.
lo,
 
 2401           functionT Vex = 
apply(hfexop,prod);
 
 2402           functionT tf1 = Vex*phisa[j]*cexp2;
 
 2414                            vecfuncT& funcsa, vecfuncT& funcsb)
 
 2416       for (
unsigned int ink1 = 0, ik1 = 0; ink1 < _phisa.size(); ++ink1)
 
 2418         for (
unsigned int ink2 = 0, ik2 = 0; ink2 <= ink1; ink2++)
 
 2420           KPoint k1 = _kpoints[ik1];
 
 2421           KPoint k2 = _kpoints[ik2];
 
 2423           if (ink1 == k1.end) ik1++;
 
 2424           if (ink2 == k2.end) ik2++;
 
 2426           MADNESS_ASSERT(ik1 == 0);
 
 2427           MADNESS_ASSERT(ik2 == 0);
 
 2442               functionT 
f = phisa[ink1]*
conj(phisa[ink2]);
 
 2445               functionT fr = 
apply(hfexop,f);
 
 2446               funcsa[ink1] -= funcsa[ink2]*fr;
 
 2447               funcsa[ink2] -= funcsa[ink1]*
conj(fr);
 
 2450               rfunctionT g1 = 
abs(phisa[ink1]);
 
 2451               rfunctionT g2 = 
abs(phisa[ink2]);
 
 2452               rfunctionT ff = g1*g2;
 
 2456               rfunctionT fr2 = 
apply(*_cop,ff);
 
 2457               MADNESS_ASSERT(
abs(fr.norm2()-fr2.
norm2()) <= 1e-5);
 
 2487       if (_world.
rank() == 0) _outputF << 
"reprojecting to wavelet order " 
 2490       for(
unsigned int i = 0; i < _phisa.size(); i++)
 
 2501         for(
unsigned int i = 0; i < _phisb.size(); i++)
 
 2533       if (_world.
rank() == 0) 
print(
"size of phisa is:  ", _phisa.size());
 
 2537       for (_it = 0; _it < _params.
maxits && _residual > _params.
rcriterion; _it++, rit++)
 
 2540         if ((_it > 0) && ((_residual < 20*_params.
thresh) || (rit == rpthresh)))
 
 2547         if (_world.
rank() == 0) _outputF << 
"_it = " << _it << endl;
 
 2550         set_occs2(_kpoints,_eigsa,_eigsb,_occsa,_occsb);
 
 2553         rfunctionT rhoa = 
compute_rho(_phisa, _kpoints, _occsa);
 
 2557         double drhoa = (_rhoa-rhoa).trace();
 
 2558         double drhob = (_rhob-rhob).trace();
 
 2559         if (_world.
rank() == 0)
 
 2561           printf(
"diff of alpha rho: %15.7f\n",drhoa);
 
 2562           printf(
"diff of beta rho: %15.7f\n",drhob);
 
 2569         double rtrace = _rho.
trace();
 
 2570         if (_world.
rank() == 0) _outputF << 
"trace of rho" << rtrace << endl;
 
 2579         std::vector<functionT> pfuncsa =
 
 2580                 zero_functions<valueT,NDIM>(_world, _phisa.
size());
 
 2581         std::vector<functionT> pfuncsb =
 
 2582                 zero_functions<valueT,NDIM>(_world, _phisb.size());
 
 2585         if (_world.rank() == 0) _outputF << 
"applying potential ...\n" << endl;
 
 2587         apply_potential(pfuncsa, pfuncsb, _phisa, _phisb, _rhoa, _rhob, _rho);
 
 2591         std::vector<double> alpha(pfuncsa.size(), 0.0);
 
 2596           std::vector<long> npt(3,101);
 
 2597           for (
unsigned int ik = 0; ik < _kpoints.size(); ik++)
 
 2599             KPoint kpoint = _kpoints[ik];
 
 2601             for (
unsigned int kst = kpoint.begin; kst < kpoint.end; kst++, ist++)
 
 2603               std::ostringstream strm;
 
 2604               strm << 
"pre_unk_" << ik << 
"_" << ist << 
".dx";
 
 2612         if (_world.rank() == 0)
 
 2613           printf(
"\n\n\n\n------ Debugging BSH operator -----");
 
 2614         for (
unsigned int ik = 0; ik < _kpoints.size(); ik++)
 
 2616           KPoint kpoint = _kpoints[ik];
 
 2617           std::vector<double> k_alpha(alpha.begin() + kpoint.begin, alpha.begin() + kpoint.end);
 
 2618           if (_world.rank() == 0)
 
 2619             printf(
"alpha: (%6.4f,%6.4f,%6.4f)\n",kpoint.k[0],kpoint.k[1],kpoint.k[2]);
 
 2620           for (
unsigned int ia = 0; ia < k_alpha.size(); ia++)
 
 2622             if (_world.rank() == 0) printf(
"%15.8f\n", k_alpha[ia]);
 
 2625         if (_world.rank() == 0) printf(
"\n\n\n\n");
 
 2628         if (_world.rank() == 0) printf(
"before BSH application ...\n\n");
 
 2629         for (
unsigned int ik = 0; ik < _kpoints.size(); ik++)
 
 2631           KPoint kpoint = _kpoints[ik];
 
 2632           double k0 = kpoint.k[0];
 
 2633           double k1 = kpoint.k[1];
 
 2634           double k2 = kpoint.k[2];
 
 2635           if (_world.rank() == 0)
 
 2636             printf(
"(%6.5f, %6.5f, %6.5f)\n",k0,k1,k2);
 
 2637           std::vector<functionT> k_phisa(_phisa.begin() + kpoint.begin, _phisa.begin() + kpoint.end);
 
 2638           std::vector<functionT> k_pfuncsa(pfuncsa.begin() + kpoint.begin, pfuncsa.begin() + kpoint.end);
 
 2643           tensorT overlap = 
matrix_inner(_world,k_pfuncsa,k_pfuncsa,
true);
 
 2644           ctensorT co; rtensorT eo;
 
 2645           syev(overlap, co, eo);
 
 2647           if (_world.rank() == 0) printf(
"Overlap eigenvalues: \n");
 
 2648           if (_world.rank() == 0) 
print(overlap);
 
 2649           for (
unsigned int ie = 0; ie < eo.dim(0); ie++)
 
 2651             if (_world.rank() == 0) printf(
"%d    %15.8e\n", ie, eo(ie,ie));
 
 2655         if (_world.rank() == 0) printf(
"\n\n\n\n");
 
 2669         std::vector<T> sfactor(pfuncsa.size(), -2.0);
 
 2670         scale(_world, pfuncsa, sfactor);
 
 2673         if (_world.rank() == 0) std::cout << 
"applying BSH operator ...\n" << endl;
 
 2674         truncate<valueT,NDIM>(_world, pfuncsa);
 
 2676         std::vector<functionT> tmpa = 
apply(_world, bopsa, pfuncsa);
 
 2682         if (_world.rank() == 0) printf(
"norms of tmpa\n");
 
 2683         std::vector<double> tmpa_norms = 
norm2s(_world, tmpa);
 
 2684         for (
unsigned int i = 0; i < tmpa_norms.size(); i++)
 
 2686           if (_world.rank() == 0) printf(
"%10d     %15.8f\n", i, tmpa_norms[i]);
 
 2688         if (_world.rank() == 0) printf(
"\n\n\n\n");
 
 2691         vecfuncT tmpb = zero_functions<valueT,NDIM>(_world, _phisb.size());
 
 2694           alpha = std::vector<double>(_phisb.size(), 0.0);
 
 2697           scale(_world, pfuncsb, sfactor);
 
 2698           truncate<valueT,NDIM>(_world, pfuncsb);
 
 2699           tmpb = 
apply(_world, bopsb, pfuncsb);
 
 2704           for (
unsigned int i = 0; i < _eigsa.size(); i++) _eigsb[i] = _eigsa[i];
 
 2708         std::vector<functionT> pfuncsa2=
 
 2709                 zero_functions<valueT,NDIM>(_world, _phisa.size());
 
 2710         std::vector<functionT> pfuncsb2=
 
 2711                 zero_functions<valueT,NDIM>(_world, _phisa.size());
 
 2714         if (_world.rank() == 0) _outputF << 
"applying potential2 ...\n" << endl;
 
 2716         for (
unsigned int ik = 0; ik < _kpoints.size(); ik++)
 
 2718           KPoint kpoint = _kpoints[ik];
 
 2719           double k0 = kpoint.k[0];
 
 2720           double k1 = kpoint.k[1];
 
 2721           double k2 = kpoint.k[2];
 
 2722           if (_world.rank() == 0)
 
 2723             printf(
"(%6.5f, %6.5f, %6.5f)\n",k0,k1,k2);
 
 2724           std::vector<functionT> k_tmpa(tmpa.begin() + kpoint.begin, tmpa.begin() + kpoint.end);
 
 2725           std::vector<functionT> k_pfuncsa2(pfuncsa2.begin() + kpoint.begin, pfuncsa2.begin() + kpoint.end);
 
 2741         if (_world.rank() == 0) printf(
"\n\n\n\n");
 
 2745         if (_world.rank() == 0) printf(
"\n\n\n\n");
 
 2752         if (_world.rank() == 0) _outputF << 
"after update_orbitals() ...\n" << endl;
 
 2753         pfuncsa2=zero_functions<valueT,NDIM>(_world, _phisa.size());
 
 2754         pfuncsb2=zero_functions<valueT,NDIM>(_world, _phisa.size());
 
 2755         apply_potential(pfuncsa2, pfuncsb2, _phisa, _phisb, _rhoa, _rhob, _rho);
 
 2756         for (
unsigned int ik = 0; ik < _kpoints.size(); ik++)
 
 2758           KPoint kpoint = _kpoints[ik];
 
 2759           double k0 = kpoint.k[0];
 
 2760           double k1 = kpoint.k[1];
 
 2761           double k2 = kpoint.k[2];
 
 2762           if (_world.rank() == 0)
 
 2763             printf(
"(%6.5f, %6.5f, %6.5f)\n",k0,k1,k2);
 
 2764           std::vector<functionT> k_phisa(_phisa.begin() + kpoint.begin, _phisa.begin() + kpoint.end);
 
 2765           std::vector<functionT> k_pfuncsa2(pfuncsa2.begin() + kpoint.begin, pfuncsa2.begin() + kpoint.end);
 
 2768         if (_world.rank() == 0) printf(
"\n\n\n\n");
 
 2774         std::vector<long> npt(3,101);
 
 2775         for (
unsigned int ik = 0; ik < _kpoints.size(); ik++)
 
 2777           KPoint kpoint = _kpoints[ik];
 
 2779           for (
unsigned int kst = kpoint.begin; kst < kpoint.end; kst++, ist++)
 
 2781             std::ostringstream strm;
 
 2782             strm << 
"unk_" << ik << 
"_" << ist << 
".dx";
 
 2794         const double tol = 1e-13;
 
 2795         MADNESS_ASSERT(A.dim(0) == A.dim(1));
 
 2798         double anorm = A.normf();
 
 2801         while (anorm*scale > 0.1)
 
 2806         tensorT 
B = scale*A;    
 
 2809         ctensorT expB = ctensorT(2, B.dims());
 
 2810         for (
int i = 0; i < expB.dim(0); i++) expB(i,i) = std::complex<T>(1.0,0.0);
 
 2814         while (term.normf() > tol)
 
 2817             term = 
inner(term,B);
 
 2825             expB = 
inner(expB,expB);
 
 2833     template<
typename Q>
 
 2837       for (
int i = 0; i < t.dim(0); i++)
 
 2839         for (
int j = 0; j < t.dim(1); j++)
 
 2841           os << t(i,j) << setw(12);
 
 2856       END_TIMER(_world,
"potential energy matrix");
 
 2857       if (_world.
rank()==0) printf(
"\n");
 
 2862       ctensorT cp; rtensorT ep;
 
 2863       sygv(potential, overlap, 1, cp, ep);
 
 2864       if (_world.
rank() == 0)
 
 2866         print(
"potential eigenvectors dims:",cp.dim(0),cp.dim(1));
 
 2867         print(
"potential eigenvectors:");
 
 2870         print(
"potential eigenvalues:");
 
 2885       END_TIMER(_world,
"potential energy matrix");
 
 2886       if (_world.
rank()==0) printf(
"\n");
 
 2889       if (_world.
rank() == 0) _outputF << 
"Building kinetic energy matrix ...\n\n" << endl;
 
 2893         tensorT kinetic = ::kinetic_energy_matrix<T,NDIM>(_world, wf,
 
 2897       END_TIMER(_world,
"kinetic energy matrix");
 
 2898       if (_world.rank() == 0) printf(
"\n");
 
 2900       if (_world.rank() == 0) _outputF << 
"Constructing Fock matrix ...\n\n" << endl;
 
 2901       tensorT fock = potential + kinetic;
 
 2910       ctensorT ck; rtensorT ek;
 
 2911       sygv(kinetic, overlap, 1, ck, ek);
 
 2913       ctensorT cp; rtensorT ep;
 
 2914       sygv(potential, overlap, 1, cp, ep);
 
 2916       ctensorT co; rtensorT eo;
 
 2917       syev(overlap, co, eo);
 
 2918       ctensorT 
c; rtensorT e;
 
 2919       sygv(fock, overlap, 1, c, e);
 
 2921       if (_world.rank() == 0)
 
 2923         print(
"kinetic matrix:");
 
 2925         print(
"\nkinetic eigenvalues:");
 
 2929         print(
"potential matrix:");
 
 2931         print(
"\npotential eigenvalues:");
 
 2935         print(
"fock matrix:");
 
 2937         print(
"\nfock eigenvalues:");
 
 2948                 std::vector<KPoint> kpoints,
 
 2949                 std::vector<T>& alpha,
 
 2950                 std::vector<double>& eigs)
 
 2953       double trantol = 0.1*_params.
thresh/
std::min(30.0,
double(wf.size()));
 
 2956       if (_world.
rank() == 0) _eigF << 
"Iteration: " << _it << endl;
 
 2957       for (
unsigned int kp = 0; kp < kpoints.size(); kp++)
 
 2960         KPoint kpoint = kpoints[kp];
 
 2961         double k0 = kpoint.k[0];
 
 2962         double k1 = kpoint.k[1];
 
 2963         double k2 = kpoint.k[2];
 
 2966         vecfuncT k_wf(wf.begin() + kpoint.begin, wf.begin() + kpoint.end);
 
 2967         vecfuncT k_vwf(vwf.begin() + kpoint.begin, vwf.begin() + kpoint.end);
 
 2970         tensorT overlap = 
matrix_inner(_world, k_wf, k_wf, 
true);
 
 3001           ctensorT U; rtensorT e;
 
 3002           sygv(fock, overlap, 1, U, e);
 
 3004           unsigned int nmo = k_wf.size();
 
 3007           for (
long j = 0; j < nmo; j++)
 
 3010               U(_,j).absmax(&imax);
 
 3011               T ang = 
arg(U(imax,j));
 
 3012               std::complex<T> phase = 
exp(std::complex<T>(0.0,-ang));
 
 3014               for (
long i = 0; i < nmo; i++)
 
 3025           for (
int pass = 0; pass < maxpass; pass++)
 
 3028               for (
long i = 0; i < nmo; i++)
 
 3033                   tensorT tmp = 
copy(U(_, i));
 
 3039                   e[i] = tj; e[j] = ti;
 
 3047           while (ilo < nmo-1) {
 
 3051                   if (ihi == nmo-1) 
break;
 
 3053               long nclus = ihi - ilo + 1;
 
 3055                   if (_world.
rank() == 0) 
print(
"   found cluster", ilo, ihi);
 
 3086               printf(
"(%10.5f, %10.5f, %10.5f)\n", k0, k1, k2);
 
 3087               print(
"Overlap matrix:");
 
 3090               print(
"Fock matrix:");
 
 3093               print(
"U matrix: (eigenvectors)");
 
 3096               print(
"Fock matrix eigenvalues:");
 
 3111           bool isgamma = (
is_equal(k0,0.0,1e-5) &&
 
 3117             vecfuncT d_wf = zero_functions<valueT,NDIM>(_world, k_wf.
size());
 
 3121             for (
unsigned int i = 0; i < k_wf.size(); i++)
 
 3124               functionT dx_wf = Dx(k_wf[i]);
 
 3125               functionT dy_wf = Dy(k_wf[i]);
 
 3126               functionT dz_wf = Dz(k_wf[i]);
 
 3127               d_wf[i] = std::complex<T>(0.0,k0)*dx_wf +
 
 3128                         std::complex<T>(0.0,k1)*dy_wf +
 
 3129                         std::complex<T>(0.0,k2)*dz_wf;
 
 3131               double ksq = k0*k0 + k1*k1 + k2*k2;
 
 3132               k_vwf[i] += 0.5 * ksq * k_wf[i];
 
 3133               k_vwf[i] -= d_wf[i];
 
 3138           unsigned int eimax = -1;
 
 3139           double eimaxval = -1e10;
 
 3140           for (
unsigned int ei = kpoint.begin, fi = 0; ei < kpoint.end;
 
 3143             if ((
real(e(fi,fi)) > 0.0) && (
real(e(fi,fi)) > eimaxval))
 
 3146               eimaxval = 
real(e(fi,fi));
 
 3150           double eshift = (eimaxval > 0.0) ? eimaxval + 0.1 : 0.0;
 
 3151           for (
unsigned int ei = kpoint.begin, fi = 0; ei < kpoint.end;
 
 3155             eigs[ei] = 
real(e(fi,fi));
 
 3156             alpha[ei] = e(fi,fi)-eshift;
 
 3157             k_vwf[fi] += (alpha[ei]-eigs[ei])*k_wf[fi];
 
 3160           if (_world.
rank() == 0)
 
 3162             _eigF << 
"kpt: " << kp << endl;
 
 3163             _eigF << setfill(
'-') << setw(20) << 
" " << endl;
 
 3164             for (
unsigned int ei = kpoint.begin; ei < kpoint.end; ei++)
 
 3167               printf(
"%3d%15.10f",ei,
real(eigs[ei]));
 
 3169               _eigF << eigstr << endl;
 
 3171             _eigF << 
"\n\n" << endl;
 
 3177           tensorT overlap = 
matrix_inner(_world, k_wf, k_wf, 
true);
 
 3178           ctensorT 
c; rtensorT e;
 
 3179           sygv(fock, overlap, 1, c, e);
 
 3180           for (
unsigned int ei = 0; ei < e.dim(0); ei++)
 
 3182             double diffe = (ei == 0) ? 0.0 : 
real(e(ei,ei))-
real(e(ei-1,ei-1));
 
 3183             if (_world.
rank() == 0)
 
 3184               print(
"kpoint ", kp, 
"ei ", ei, 
"eps ", 
real(e(ei,ei)), 
"\tdiff\t", diffe);
 
 3187           for (
unsigned int ei = kpoint.begin, fi = 0;
 
 3188             ei < kpoint.end; ei++, fi++)
 
 3191             fock(fi,fi) -= std::complex<T>(alpha[ei], 0.0);
 
 3194           std::vector<functionT> fwf = 
transform(_world, k_wf, fock, trantol);
 
 3195           gaxpy(_world, 1.0, k_vwf, -1.0, fwf);
 
 3198         for (
unsigned int wi = kpoint.begin, fi = 0; wi < kpoint.end;
 
 3202           vwf[wi] = k_vwf[fi];
 
 3211                 std::vector<KPoint> kpoints,
 
 3212                 std::vector<T>& alpha,
 
 3213                 std::vector<double>& eigs)
 
 3216       double trantol = 0.1*_params.
thresh/
std::min(30.0,
double(wf.size()));
 
 3219       if (_world.
rank() == 0) _eigF << 
"Iteration: " << _it << endl;
 
 3220       for (
unsigned int kp = 0; kp < kpoints.size(); kp++)
 
 3223         KPoint kpoint = kpoints[kp];
 
 3224         double k0 = kpoint.k[0];
 
 3225         double k1 = kpoint.k[1];
 
 3226         double k2 = kpoint.k[2];
 
 3229         vecfuncT k_wf(wf.begin() + kpoint.begin, wf.begin() + kpoint.end);
 
 3230         vecfuncT k_vwf(vwf.begin() + kpoint.begin, vwf.begin() + kpoint.end);
 
 3234         tensorT overlap = 
matrix_inner(_world, k_wf, k_wf, 
true);
 
 3235         for (
unsigned int i = 0; i < k_wf.size(); i++)
 
 3236           fock(i,i) += std::complex<double>(i*_params.
thresh*0.1,0.0);
 
 3238         ctensorT U; rtensorT e;
 
 3239         sygv(fock, overlap, 1, U, e);
 
 3243             printf(
"(%10.5f, %10.5f, %10.5f)\n", k0, k1, k2);
 
 3244             print(
"Overlap matrix:");
 
 3247             print(
"Fock matrix:");
 
 3250             print(
"U matrix: (eigenvectors)");
 
 3253             print(
"Fock matrix eigenvalues:");
 
 3261           unsigned int nmo = k_wf.size();
 
 3264           for (
long j = 0; j < nmo; j++)
 
 3267               U(_,j).absmax(&imax);
 
 3268               T ang = 
arg(U(imax,j));
 
 3269               std::complex<T> phase = 
exp(std::complex<T>(0.0,-ang));
 
 3271               for (
long i = 0; i < nmo; i++)
 
 3282           for (
int pass = 0; pass < maxpass; pass++)
 
 3285               for (
long i = 0; i < nmo; i++)
 
 3290                   tensorT tmp = 
copy(U(_, i));
 
 3296                   e[i] = tj; e[j] = ti;
 
 3304           while (ilo < nmo-1) {
 
 3308                   if (ihi == nmo-1) 
break;
 
 3310               long nclus = ihi - ilo + 1;
 
 3312                   if (_world.
rank() == 0) 
print(
"   found cluster", ilo, ihi);
 
 3342         k_vwf = 
transform(_world, k_vwf, U, 1e-5 / 
std::min(30.0, 
double(k_wf.size())), 
false);
 
 3346         bool isgamma = (
is_equal(k0,0.0,1e-5) &&
 
 3352           vecfuncT d_wf = zero_functions<valueT,NDIM>(_world, k_wf.
size());
 
 3356           for (
unsigned int i = 0; i < k_wf.size(); i++)
 
 3359             functionT dx_wf = Dx(k_wf[i]);
 
 3360             functionT dy_wf = Dy(k_wf[i]);
 
 3361             functionT dz_wf = Dz(k_wf[i]);
 
 3478             d_wf[i] = std::complex<T>(0.0,k0)*dx_wf +
 
 3479                       std::complex<T>(0.0,k1)*dy_wf +
 
 3480                       std::complex<T>(0.0,k2)*dz_wf;
 
 3482             double ksq = k0*k0 + k1*k1 + k2*k2;
 
 3483             k_vwf[i] += 0.5 * ksq * k_wf[i];
 
 3484             k_vwf[i] -= d_wf[i];
 
 3490         unsigned int eimax = -1;
 
 3491         double eimaxval = -1e10;
 
 3492         for (
unsigned int ei = kpoint.begin, fi = 0; ei < kpoint.end;
 
 3495           if ((
real(e(fi,fi)) > 0.0) && (
real(e(fi,fi)) > eimaxval))
 
 3498             eimaxval = 
real(e(fi,fi));
 
 3502         double eshift = (eimaxval > 0.0) ? eimaxval + 0.1 : 0.0;
 
 3503         for (
unsigned int ei = kpoint.begin, fi = 0; ei < kpoint.end;
 
 3507           eigs[ei] = 
real(e(fi,fi));
 
 3508           alpha[ei] = e(fi,fi)-eshift;
 
 3509           k_vwf[fi] += (alpha[ei]-eigs[ei])*k_wf[fi];
 
 3515         if (_world.
rank() == 0)
 
 3517           _eigF << 
"kpt: " << kp << endl;
 
 3518           _eigF << setfill(
'-') << setw(20) << 
" " << endl;
 
 3519           for (
unsigned int ei = kpoint.begin; ei < kpoint.end; ei++)
 
 3522             sprintf(eigstr,
"%3d%15.10f",ei,
real(eigs[ei]));
 
 3523             _eigF << eigstr << endl;
 
 3525           _eigF << 
"\n\n" << endl;
 
 3527         for (
unsigned int wi = kpoint.begin, fi = 0; wi < kpoint.end;
 
 3531           vwf[wi] = k_vwf[fi];
 
 3566         return f1 + f2 + 
f3;
 
 3579       END_TIMER(_world,
"potential energy matrix");
 
 3580       if (_world.
rank()==0) printf(
"\n");
 
 3583       if (_world.
rank() == 0) _outputF << 
"Building kinetic energy matrix ...\n\n" << endl;
 
 3584         tensorT kinetic = ::kinetic_energy_matrix<T,NDIM>(_world, 
psi,
 
 3589       END_TIMER(_world,
"kinetic energy matrix");
 
 3590       if (_world.rank() == 0) printf(
"\n");
 
 3592       if (_world.rank() == 0) _outputF << 
"Constructing Fock matrix ...\n\n" << endl;
 
 3593       tensorT fock = potential + kinetic;
 
 3597       if (_world.rank() == 0)
 
 3603         print(
"POTENTIAL:");
 
 3616       for (
unsigned int fi = kpoint.begin; fi < kpoint.end; ++fi)
 
 3619         for (
unsigned int fj = kpoint.begin; fj < fi; ++fj)
 
 3621           valueT overlap = 
inner(f[fj], f[fi]);
 
 3622           f[fi] -= overlap*f[fj];
 
 3624         f[fi].scale(1.0/f[fi].
norm2());
 
 3631     tensorT 
Q3(
const tensorT& s) {
 
 3632         tensorT Q = 
inner(s,s);
 
 3633         Q.gaxpy(0.2,s,-2.0/3.0);
 
 3634         for (
int i=0; i<s.dim(0); ++i) Q(i,i) += 1.0;
 
 3635         return Q.scale(15.0/8.0);
 
 3641     ctensorT 
csqrt(
const ctensorT& s, 
double tol=1e-8) {
 
 3642         int n=s.dim(0), 
m=s.dim(1);
 
 3643         MADNESS_ASSERT(n==
m);
 
 3644         ctensorT 
c; rtensorT e;
 
 3647         for (
int i=0; i<n; ++i) {
 
 3651             else if (e(i) < tol) { 
 
 3652                 print(
"Matrix square root: Warning: small eigenvalue ", i, e(i));
 
 3655             e(i) = 1.0/
sqrt(e(i));
 
 3657         for (
int j=0; j<n; ++j) {
 
 3658             for (
int i=0; i<n; ++i) {
 
 3670       vecfuncT k_wf(wf.begin() + kpoint.begin, wf.begin() + kpoint.end);
 
 3672       printf(
"orthonormalize: \n");
 
 3673       printf(
"before matrix (after): \n");
 
 3675       ctensorT U = 
csqrt(S);
 
 3679       printf(
"overlap matrix (after): \n");
 
 3681       for (
unsigned int wi = kpoint.begin, fi = 0; wi < kpoint.end;
 
 3691                               const vecfuncT& bwfs)
 
 3694       vecfuncT rm = 
sub(_world, _phisa, awfs);
 
 3698         vecfuncT br = 
sub(_world, _phisb, bwfs);
 
 3699         rm.insert(rm.end(), br.begin(), br.end());
 
 3702       std::vector<double> rnvec = norm2s<valueT,NDIM>(_world, rm);
 
 3704       for (
unsigned int i = 0; i < rnvec.size(); i++) rnorm += rnvec[i];
 
 3706       _residual = rnorm / rnvec.size();
 
 3707       if (_world.rank() == 0) _outputF << 
"\nResiduals\n---------" << endl;
 
 3708       if (_world.rank() == 0) _outputF << std::setiosflags(std::ios::scientific) << 
"residual = " << _residual << endl;
 
 3709       if (_world.rank() == 0)
 
 3712         for (
unsigned int i = 0; i < rnvec.size(); i++)
 
 3714           _outputF << 
"residual" << i << 
"\t" << rnvec[i] << endl;
 
 3725                          std::vector<KPoint> kpoints)
 
 3728       truncate<valueT,NDIM> (_world, awfs);
 
 3729       truncate<valueT,NDIM> (_world, _phisa);
 
 3732         truncate<valueT,NDIM> (_world, bwfs);
 
 3733         truncate<valueT,NDIM> (_world, _phisb);
 
 3750       for (
unsigned int kp = 0; kp < kpoints.size(); kp++)
 
 3762       truncate<valueT,NDIM>(_world, awfs);
 
 3763       for (
unsigned int ai = 0; ai < awfs.size(); ai++) {
 
 3764           _phisa[ai] = awfs[ai].scale(1.0 / awfs[ai].
norm2());
 
 3768         truncate<valueT,NDIM>(_world, bwfs);
 
 3769         for (
unsigned int bi = 0; bi < bwfs.size(); bi++)
 
 3771             _phisb[bi] = bwfs[bi].scale(1.0 / bwfs[bi].
norm2());
 
 3776         for (
unsigned int ia = 0; ia < awfs.size(); ia++)
 
 3778           _phisb[ia] = _phisa[ia];
 
 3789       double s = (_it < 4) ? 0.75 : _params.
sd;
 
 3790       if (_world.
rank() == 0) 
print(
"damping factor: ", s);
 
 3791       for (
unsigned int i = 0; i < owfs.size(); i++)
 
 3792           nwfs[i].
gaxpy(1.0 - s, owfs[i], s, 
false);
 
 3818                          std::vector<double>& occs)
 
 3821       double emax = eps[0];
 
 3823       for (
int i = 0; i < eps.size(); i++)
 
 3825         emax = (eps[i] > emax) ? eps[i] : emax;
 
 3826         emin = (eps[i] < emin) ? eps[i] : emin;
 
 3831       double occmax = 2.0;
 
 3833       double efermi = 0.0;
 
 3837       double t1 = 1.0/_params.
swidth;
 
 3838       for (
int it = 0; (it < maxits)&&(!bstop); it++)
 
 3841         efermi = 0.5 * (emax + emin);
 
 3843         double charge = 0.0;
 
 3845         for (
int i = 0; i < eps.size(); i++)
 
 3847           double x = (efermi-eps[i]) * t1;
 
 3850           charge += _kpoints[i].weight() * occs[i];
 
 3852         if (
fabs(emax-emin) < 1e-5)
 
 3854         else if (charge < _params.
ncharge)
 
void matrix_inner(DistributedMatrix< T > &A, const std::vector< Function< T, NDIM > > &f, const std::vector< Function< T, NDIM > > &g, bool sym=false)
Definition: chem/distpm.cc:38
const double thresh
Definition: dielectric.cc:185
tensor_complex make_kinetic_matrix(World &world, const vector_complex_function_3d &v, const KPoint &k)
Definition: solver.h:3538
WorldGopInterface & gop
Global operations. 
Definition: worldfwd.h:462
Corresponding C and Fortran types. 
Tensor< double > B
Definition: tdse1d.cc:167
void apply_hf_exchange4(vecfuncT &phisa, vecfuncT &phisb, vecfuncT &funcsa, vecfuncT &funcsb, double &xc)
Definition: solver.h:2373
void reconstruct(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Reconstruct a vector of functions. 
Definition: vmra.h:149
bool centered
Definition: electronicstructureparams.h:113
const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2234
const double pi
Mathematical constant pi. 
Definition: constants.h:44
const double R
Definition: dielectric.cc:191
double thresh
Definition: electronicstructureparams.h:64
std::complex< double > double_complex
Definition: lineplot.cc:16
Main include file for MADNESS and defines Function interface. 
Function< T, NDIM > & truncate(double tol=0.0, bool fence=true)
Truncate the function with optional fence. Compresses with fence if not compressed. 
Definition: mra.h:577
const T1 const T2 const T3 & f3
Definition: gtest-tuple.h:686
void do_rhs_simple(vecfuncT &wf, vecfuncT &vwf, std::vector< KPoint > kpoints, std::vector< T > &alpha, std::vector< double > &eigs)
Definition: solver.h:3209
double operator()(const coordT &x) const 
Definition: solver.h:1134
FunctionDefaults holds default paramaters as static class members. 
Definition: funcdefaults.h:175
Tensor< T > conj_transpose(const Tensor< T > &t)
Returns a new deep copy of the complex conjugate transpose of the input tensor. 
Definition: tensor.h:1954
int solver
Definition: electronicstructureparams.h:92
static void set_bc(const BoundaryConditions< NDIM > &value)
Sets the default boundary conditions. 
Definition: funcdefaults.h:350
void gaxpy(World &world, Q alpha, std::vector< Function< T, NDIM > > &a, Q beta, const std::vector< Function< R, NDIM > > &b, bool fence=true)
Generalized A*X+Y for vectors of functions -— a[i] = alpha*a[i] + beta*b[i]. 
Definition: vmra.h:680
WSTAtomicBasisFunctor(const AtomicBasisFunction &aofunc, double L, double kx, double ky, double kz)
Definition: solver.h:129
double swidth
Definition: electronicstructureparams.h:105
bool spinpol
Definition: electronicstructureparams.h:56
GuessDensity(const MolecularEntity &mentity, const AtomicBasisSet &aobasis, const double &R, const bool &periodic)
Definition: solver.h:1158
SubspaceK(World &world, const ElectronicStructureParams ¶ms, const std::vector< KPoint > &kpoints)
Definition: solver.h:232
Vector< double, NDIM > coordT
Definition: solver.h:101
The SubspaceK class is a container class holding previous orbitals and residuals. ...
Definition: solver.h:412
std::vector< coord_3d > special_points() const 
Override this to return list of special points to be refined more deeply. 
Definition: solver.h:159
const int NDIM
Definition: tdse1.cc:44
Definition: solver.h:1128
An archive for storing local or parallel data wrapping BinaryFstreamOutputArchive. 
Definition: parar.h:241
Vector< double, NDIM > vec3dT
Definition: solver.h:102
Definition: eigsolver.h:63
const Function< T, NDIM > & compress(bool fence=true) const 
Compresses the function, transforming into wavelet basis. Possible non-blocking comm. 
Definition: mra.h:683
Implements derivatives operators with variety of boundary conditions on simulation domain...
Definition: derivative.h:272
Definition: electronicstructureparams.h:45
void update_subspace(vecfuncT &awfs_new, vecfuncT &bwfs_new, const vecfuncT &awfs_old, const vecfuncT &bwfs_old, const vecfuncT &rm)
Definition: solver.h:452
double z
Definition: chem/molecule.h:57
double L
Definition: electronicstructureparams.h:48
void plotdx(const Function< T, NDIM > &f, const char *filename, const Tensor< double > &cell=FunctionDefaults< NDIM >::get_cell(), const std::vector< long > &npt=std::vector< long >(NDIM, 201L), bool binary=true)
Writes an OpenDX format file with a cube/slice of points on a uniform grid. 
Definition: mraimpl.h:3228
void truncate(World &world, std::vector< Function< T, NDIM > > &v, double tol=0.0, bool fence=true)
Truncates a vector of functions. 
Definition: vmra.h:194
::std::string string
Definition: gtest-port.h:872
Convolutions in separated form (including Gaussian) 
Definition: operator.h:117
double rcriterion
Definition: electronicstructureparams.h:111
bool canon
Definition: electronicstructureparams.h:90
bool periodic
Definition: electronicstructureparams.h:58
A MADNESS functor to compute either x, y, or z. 
Definition: chem/SCF.h:194
bool fractional
Definition: electronicstructureparams.h:84
XCfunctional xc
Definition: hedft.cc:54
void reproject()
Definition: solver.h:2481
NDIM & f
Definition: mra.h:2179
Definition: funcdefaults.h:56
ProcessID size() const 
Returns the number of processes in this world (same as MPI_Comm_size()) 
Definition: worldfwd.h:533
static const double & get_thresh()
Returns the default threshold. 
Definition: funcdefaults.h:225
Defines interfaces for optimization and non-linear equation solvers. 
AtomicBasisFunction get_atomic_basis_function(const Molecule &molecule, int ibf) const 
Returns the ibf'th atomic basis function. 
Definition: chem/molecularbasis.h:474
Vector< double, 3 > coordT
Definition: chem/corepotential.cc:57
ctensorT matrix_exponential(const ctensorT &A)
Definition: solver.h:2793
const vec3dT exponent
Definition: solver.h:104
rfunctionT make_lda_potential(World &world, const rfunctionT &arho, const rfunctionT &brho, const rfunctionT &adelrhosq, const rfunctionT &bdelrhosq)
Definition: solver.h:1237
rfunctionT compute_rho_slow(const vecfuncT &phis, std::vector< KPoint > kpoints, std::vector< double > occs)
Compute the electronic density for either a molecular or periodic system. 
Definition: solver.h:2017
Definition: electronicstructureapp.h:85
Function< T, NDIM > & scale(const Q q, bool fence=true)
Inplace, scale the function by a constant. No communication except for optional fence. 
Definition: mra.h:896
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only) ...
Definition: tensor.h:2429
static const Tensor< double > & get_cell()
Gets the user cell for the simulation. 
Definition: funcdefaults.h:369
This header should include pretty much everything needed for the parallel runtime. 
T inner(const vecfunc< T, NDIM > &a, const vecfunc< T, NDIM > &b)
the non-linear solver requires an inner product 
Definition: nemo.h:112
Definition: potentialmanager.h:54
KPoint find_kpt_from_orb(unsigned int idx)
Definition: solver.h:2360
tensorT Q3(const tensorT &s)
Given overlap matrix, return rotation with 3rd order error to orthonormalize the vectors. 
Definition: solver.h:3631
std::vector< double > norm2s(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions. 
Definition: vmra.h:312
ComplexExp(vec3dT exponent, double_complex coeff)
Definition: solver.h:106
void syev(const Tensor< T > &A, Tensor< T > &V, Tensor< typename Tensor< T >::scalar_type > &e)
Real-symmetric or complex-Hermitian eigenproblem. 
Definition: lapack.cc:478
void init(const std::string &filename)
Definition: solver.h:796
void END_TIMER(World &world, const char *msg)
Definition: solver.h:772
Function< double, NDIM > abssq(const Function< double_complex, NDIM > &z, bool fence=true)
Returns a new function that is the square of the absolute value of the input. 
Definition: mra.h:2255
void save_orbitals()
Definition: solver.h:928
ctensorT csqrt(const ctensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?) 
Definition: solver.h:3641
Solver(World &world, const std::string &filename)
Definition: solver.h:778
double ncharge
Definition: electronicstructureparams.h:103
bool plotorbs
Definition: electronicstructureparams.h:109
std::shared_ptr< FunctionFunctorInterface< double, 3 > > functorT
Definition: chem/corepotential.cc:58
std::vector< KPoint > genkmesh(unsigned int ngridk0, unsigned ngridk1, unsigned int ngridk2, double koffset0, double koffset1, double koffset2, double R)
Definition: solver.h:897
double_complex operator()(const coordT &x) const 
You should implement this to return f(x) 
Definition: solver.h:109
int nbf(const Molecule &molecule) const 
Given a molecule count the number of basis functions. 
Definition: chem/molecularbasis.h:498
void orthonormalize(vecfuncT &wf, KPoint kpoint)
Definition: solver.h:3667
Solver(World &world, const rfunctionT &vnucrhon, const vecfuncT &phis, const std::vector< T > &eigs, const ElectronicStructureParams ¶ms, MolecularEntity mentity)
Definition: solver.h:1819
FLOAT weight(const FLOAT &x)
Definition: y.cc:309
void broadcast_serializable(objT &obj, ProcessID root)
Broadcast a serializable object. 
Definition: worldgop.h:707
double R
Definition: solver.h:1131
double norm2() const 
Returns the 2-norm of the function ... global sum ... works in either basis. 
Definition: mra.h:650
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
#define max(a, b)
Definition: lda.h:53
void step_restriction(vecfuncT &owfs, vecfuncT &nwfs, int aorb)
Definition: solver.h:3785
Vector< T, 1 > vec(T x)
Your friendly neighborhood factory function. 
Definition: array.h:456
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values. 
Definition: vmra.h:290
int functional
Definition: electronicstructureparams.h:52
void reconstruct(bool fence=true) const 
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm...
Definition: mra.h:737
const int k
Definition: dielectric.cc:184
void initial_guess()
Initializes alpha and beta mos, occupation numbers, eigenvalues. 
Definition: solver.h:1323
std::vector< poperatorT > make_bsh_operators(const std::vector< T > &eigs)
Definition: solver.h:2088
tensorT build_fock_matrix(vecfuncT &psi, vecfuncT &vpsi, KPoint kpoint)
Definition: solver.h:3571
static int get_k()
Returns the default wavelet order. 
Definition: funcdefaults.h:212
Used to represent one basis function from a shell on a specific center. 
Definition: chem/molecularbasis.h:335
int ngridk2
Definition: electronicstructureparams.h:78
void read_file(std::string filename)
read the atomic basis set from file 
Definition: chem/molecularbasis.cc:107
The main class of the periodic DFT solver . 
Definition: solver.h:625
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
double sd
Definition: electronicstructureparams.h:115
double sss
Definition: solver.h:767
T trace() const 
Returns global value of int(f(x),x) ... global comm required. 
Definition: mra.h:1034
double total_nuclear_charge() const 
Definition: mentity.cc:444
const mpreal min(const mpreal &x, const mpreal &y)
Definition: mpreal.h:2675
Function< TENSOR_RESULT_TYPE(L, R), NDIM > sub(const Function< L, NDIM > &left, const Function< R, NDIM > &right, bool fence=true)
Same as operator- but with optional fence and no automatic compression. 
Definition: mra.h:1778
int nempty
Definition: electronicstructureparams.h:72
int waveorder
Definition: electronicstructureparams.h:66
unsigned int maxsub
Definition: electronicstructureparams.h:86
double psi(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:42
double koffset0
Definition: electronicstructureparams.h:94
int nelec
Definition: electronicstructureparams.h:50
void center()
Moves the center of nuclear charge to the origin. 
Definition: mentity.cc:413
void print_potential_matrix_eigs(const vecfuncT &wf, const vecfuncT &vwf)
Definition: solver.h:2850
double operator()(const coordT &x) const 
Definition: solver.h:171
void load_orbitals()
Definition: solver.h:949
bool print_matrices
Definition: electronicstructureparams.h:107
void read_file(const std::string &filename, bool fractional)
Definition: mentity.cc:289
void gram_schmidt(vecfuncT &f, KPoint kpoint)
Definition: solver.h:3614
std::string basis
Definition: electronicstructureparams.h:96
const MolecularEntity & mentity
Definition: solver.h:1129
const double_complex coeff
Definition: solver.h:103
Subspace(World &world, const ElectronicStructureParams ¶ms)
Definition: solver.h:445
double ttt
Definition: solver.h:767
int nio
Definition: electronicstructureparams.h:98
const AtomicBasisSet & aobasis
Definition: solver.h:1130
void print_fock_matrix_eigs(const vecfuncT &wf, const vecfuncT &vwf, KPoint kpoint)
Definition: solver.h:2879
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks. 
Definition: worldgop.h:767
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?) 
Definition: DFcode/moldft.cc:446
virtual ~DipoleFunctor()
Definition: solver.h:174
A parallel world with full functionality wrapping an MPI communicator. 
Definition: worldfwd.h:416
const Atom & get_atom(unsigned int i) const 
Definition: mentity.cc:369
void fence()
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks. 
Definition: worldgop.cc:52
vecfuncT project_ao_basis(World &world, KPoint kpt)
Definition: solver.h:1250
void make_nuclear_potential()
Definition: solver.h:1101
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions. 
Definition: vmra.h:325
vecfuncT compute_residual(const vecfuncT &awfs, const vecfuncT &bwfs)
Definition: solver.h:3690
double potential(const coord_3d &r)
Definition: 3dharmonic.cc:133
DipoleFunctor(int axis)
Definition: solver.h:170
double x
Definition: chem/molecule.h:57
int ngridk0
Definition: electronicstructureparams.h:78
void set_occs2(const std::vector< KPoint > &kpoints, const std::vector< double > &eigsa, const std::vector< double > &eigsb, std::vector< double > &occsa, std::vector< double > &occsb)
Definition: solver.h:1900
A multiresolution adaptive numerical function. 
Definition: derivative.h:61
Definition: chem/molecule.h:55
double eval_guess_density(const Molecule &molecule, double x, double y, double z) const 
Evaluates the guess density. 
Definition: chem/molecularbasis.h:520
std::vector< complex_functionT > cvecfuncT
Definition: chem/SCF.h:73
int nbands
Definition: electronicstructureparams.h:76
void read_file(const std::string &filename)
Definition: electronicstructureparams.h:170
std::shared_ptr< FunctionFunctorInterface< double, 3 > > rfunctorT
Definition: esolver.h:46
double calculate_kinetic_energy()
Definition: solver.h:2142
double y
Definition: chem/molecule.h:57
static void set_thresh(double value)
Sets the default threshold. 
Definition: funcdefaults.h:232
const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode)
Definition: mpreal.cc:241
Abstract base class interface required for functors used as input to Functions. 
Definition: function_interface.h:58
const double m
Definition: gfit.cc:199
#define rot(x, k)
Definition: lookup3.c:72
ProcessID rank() const 
Returns the process rank in this world (same as MPI_Comm_rank())) 
Definition: worldfwd.h:526
void START_TIMER(World &world)
Definition: solver.h:768
std::vector< complex_function_3d > vector_complex_function_3d
Definition: functypedefs.h:86
double real(double x)
Definition: complexfun.h:52
Function< TENSOR_RESULT_TYPE(L, R), NDIM > mul_sparse(const Function< L, NDIM > &left, const Function< R, NDIM > &right, double tol, bool fence=true)
Sparse multiplication — left and right must be reconstructed and if tol!=0 have tree of norms alread...
Definition: mra.h:1569
void plot_line(const char *filename, int npt, const Vector< double, NDIM > &lo, const Vector< double, NDIM > &hi, const Function< T, NDIM > &f)
Generates ASCII file tabulating f(r) at npoints along line r=lo,...,hi. 
Definition: funcplot.h:388
void apply_potential(vecfuncT &pfuncsa, vecfuncT &pfuncsb, const vecfuncT &phisa, const vecfuncT &phisb, const rfunctionT &rhoa, const rfunctionT &rhob, const rfunctionT &rho)
Applies the LDA effective potential to each orbital. Currently only lda and spin-polarized is not imp...
Definition: solver.h:2184
double abs(double x)
Definition: complexfun.h:48
rfunctionT compute_rho(const vecfuncT &phis, std::vector< KPoint > kpoints, std::vector< double > occs)
Definition: solver.h:2049
~WSTAtomicBasisFunctor()
Definition: solver.h:139
const bool periodic
Definition: solver.h:1132
const double delta
Definition: dielectric_external_field.cc:120
Solver(World &world, rfunctionT vnucrhon, vecfuncT phis, std::vector< T > eigs, std::vector< KPoint > kpoints, std::vector< double > occs, ElectronicStructureParams params, MolecularEntity mentity)
Definition: solver.h:1854
int ngridk1
Definition: electronicstructureparams.h:78
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension. 
Definition: funcdefaults.h:391
static void set_cubic_cell(double lo, double hi)
Sets the user cell to be cubic with each dimension having range [lo,hi]. 
Definition: funcdefaults.h:384
Function< T, NDIM > & gaxpy(const T &alpha, const Function< Q, NDIM > &other, const R &beta, bool fence=true)
Inplace, general bi-linear operation in wavelet basis. No communication except for optional fence...
Definition: mra.h:924
virtual ~Solver()
Definition: solver.h:1889
double koffset2
Definition: electronicstructureparams.h:94
void make_nuclear_charge_density_impl()
Definition: solver.h:1049
void sygv(const Tensor< T > &A, const Tensor< T > &B, int itype, Tensor< T > &V, Tensor< typename Tensor< T >::scalar_type > &e)
Generalized real-symmetric or complex-Hermitian eigenproblem. 
Definition: lapack.cc:519
void unaryop(T(*f)(T))
Inplace unary operation on function values. 
Definition: mra.h:840
void make_nuclear_potential_impl()
Definition: solver.h:1041
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
void apply_hf_exchange(vecfuncT &phisa, vecfuncT &phisb, vecfuncT &funcsa, vecfuncT &funcsb)
Definition: solver.h:2413
int restart
Definition: electronicstructureparams.h:101
const T1 & f1
Definition: gtest-tuple.h:680
double lo
Definition: electronicstructureparams.h:54
Contracted Gaussian basis. 
Definition: chem/molecularbasis.h:391
void print(const A &a)
Print a single item to std::cout terminating with new line. 
Definition: print.h:122
Function< T, NDIM > project(const Function< T, NDIM > &other, int k=FunctionDefaults< NDIM >::get_k(), double thresh=FunctionDefaults< NDIM >::get_thresh(), bool fence=true)
Definition: mra.h:2162
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
A slice defines a sub-range or patch of a dimension. 
Definition: slice.h:103
void update_orbitals(vecfuncT &awfs, vecfuncT &bwfs, std::vector< KPoint > kpoints)
Definition: solver.h:3723
double thresh() const 
Returns value of truncation threshold. No communication. 
Definition: mra.h:542
double koffset1
Definition: electronicstructureparams.h:94
const T1 const T2 & f2
Definition: gtest-tuple.h:680
void solve()
Definition: solver.h:2520
FunctionFactory implements the named-parameter idiom for Function. 
Definition: funcimpl.h:70
bool is_equal(double val1, double val2, double eps)
Definition: esolver.h:190
const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2187
Tensor< double_complex > tensor_complex
Definition: functypedefs.h:44
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces. 
Definition: chem/atomutil.cc:45
T stheta_fd(const T &x)
Definition: solver.h:76
Function< T, NDIM > apply(const Derivative< T, NDIM > &D, const Function< T, NDIM > &f, bool fence=true)
Applies derivative operator to function (for syntactic equivalence to integral operator apply) ...
Definition: derivative.h:613
const double c
Definition: gfit.cc:200
double weight()
Definition: eigsolver.h:79
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const DistributedMatrix< R > &c, bool fence=true)
Definition: chem/SCF.cc:86
double wall_time()
Returns the wall time in seconds relative to arbitrary origin. 
Definition: world.cc:248
void normalize(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Normalizes a vector of functions — v[i] = v[i].scale(1.0/v[i].norm2()) 
Definition: vmra.h:765
void get_coords(double &x, double &y, double &z) const 
Definition: chem/molecularbasis.h:380
void apply_hf_exchange3(vecfuncT &phisa, vecfuncT &phisb, vecfuncT &funcsa, vecfuncT &funcsb, double &xc)
Definition: solver.h:2325
void print_tensor2d(ostream &os, Tensor< Q > t)
Definition: solver.h:2834
static void set_k(int value)
Sets the default wavelet order. 
Definition: funcdefaults.h:219
void reproject()
Definition: solver.h:563
int natom() const 
Definition: mentity.h:112
double_complex operator()(const coord_3d &x) const 
Definition: solver.h:141
The SubspaceK class is a container class holding previous orbitals and residuals. ...
Definition: solver.h:193
void fix_occupations(const std::vector< T > &eps, std::vector< double > &occs)
Definition: solver.h:3817
bool ispotential
Definition: electronicstructureparams.h:62
Function< T, NDIM > conj(const Function< T, NDIM > &f, bool fence=true)
Return the complex conjugate of the input function with the same distribution and optional fence...
Definition: mra.h:1879
Tensor< T > KAIN(const Tensor< T > &Q, double rcond=1e-12)
Solves non-linear equation using KAIN (returns coefficients to compute next vector) ...
Definition: solvers.h:98
void do_rhs(vecfuncT &wf, vecfuncT &vwf, std::vector< KPoint > kpoints, std::vector< T > &alpha, std::vector< double > &eigs)
Definition: solver.h:2946
void update_subspace(vecfuncT &awfs_new, vecfuncT &bwfs_new, const vecfuncT &awfs_old, const vecfuncT &bwfs_old)
Definition: solver.h:246
Solver(World &world, rfunctionT vnucrhon, vecfuncT phisa, vecfuncT phisb, std::vector< T > eigsa, std::vector< T > eigsb, ElectronicStructureParams params, MolecularEntity mentity)
Definition: solver.h:1296
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions. 
Definition: vmra.h:130
void test_periodicity(const Function< Q, 3 > &f)
Definition: solver.h:1166
int maxits
Definition: electronicstructureparams.h:60