void colorTest() { ofColor rgb1 = ofColor::fromHex(0xe20bca); ofColor rgb2 = ofColor::fromHex(0x17bb04); ColorXYZ xyz1(rgb1); ColorXYZ xyz2(rgb2); for (int i = 0; i < 1024; ++i) { float f = i / 1024.0f; ofColor tmp(rgb1); ofSetColor(tmp.lerp(rgb2, f)); ofRect(i, 0, i + 1, 384); ofSetColor(xyz1.lerp(xyz2, f).getRgb()); ofRect(i, 384, i + 1, 768); } }
void Nodes_method::run(Program_options & options, ostream & output) { ofstream os; //for writing to *.plt files string pltfile; //name of plotfile being written string confile; //name of configuration of electrons to be being written double max_value,min_value; int count; Array1 <doublevar> xyz(3), xyz2(3), resolution_array(3); //position of electron "in" MO Array1 <int> D_array1(3); //dummy array1 Array2 <doublevar> oldpos(mywalker->electronSize(),3); Array1 <doublevar> tmp(3); D_array1=0; //sets all 3 components to 0. use as counter for gridpoints D_array1(0)=roundoff((minmax(1)-minmax(0))/resolution); D_array1(1)=roundoff((minmax(3)-minmax(2))/resolution); D_array1(2)=roundoff((minmax(5)-minmax(4))/resolution); resolution_array(0)=(minmax(1)-minmax(0))/(D_array1(0)-1); resolution_array(1)=(minmax(3)-minmax(2))/(D_array1(1)-1); resolution_array(2)=(minmax(5)-minmax(4))/(D_array1(2)-1); Array2 <doublevar> grid(plots.GetSize(),D_array1(0)*D_array1(1)*D_array1(2)); Wf_return wfvals(wf->nfunc(), 2); //where wfval fist index labels //wf number ie. ground state // excited state and so on, and second label is for two values, sign and log(wf). //scan electron positions cout << "Using these electron positions:"<<endl; for(int i=0; i<mywalker->electronSize(); i++){ mywalker->getElectronPos(i, tmp); cout.precision(5); cout.width(8); cout <<i+1<<" "<<tmp(0)<<" "<<tmp(1)<<" "<<tmp(2)<<endl; for (int d=0;d<3;d++) oldpos(i,d)=tmp(d); // cout << "pos " << oldpos(i,0) << " " << oldpos(i,1) << " " << oldpos(i,2) // << endl; } //generate .xyz file for gOpenMol to view coordinates pltfile=options.runid + ".xyz"; os.open(pltfile.c_str()); cout<<"writing to "<<pltfile<<endl; vector <string> atomlabels; sysprop->getAtomicLabels(atomlabels); os<<atomlabels.size()+mywalker->electronSize()<<endl; os<<endl; int spin_up=sysprop->nelectrons(0); //cout << "Up electrons "<<spin_up<<endl; for(unsigned int i=0; i<atomlabels.size(); i++){ Array1 <doublevar> pos(3); mywalker->getIonPos(i, pos); os<<atomlabels[i] <<" "<< pos(0) <<" "<<pos(1) <<" "<< pos(2)<<endl; } for(int j=0; j<mywalker->electronSize(); j++){ if (j<spin_up) os<<"Eu"; else os<<"Ed"; // mywalker->getElectronPos(j, pos); os<<" "<< oldpos(j,0)<<" "<<oldpos(j,1) <<" "<< oldpos(j,2)<<endl; } os.close(); if (!doublemove) { //calculate value of each molecular orbital at each grid point and store in an Array1 // grid values with x=fastest running variable, and z=slowest cout<<"calculating "<<D_array1(0)*D_array1(1)*D_array1(2) <<" grid points"<<endl; cout<<"for "<< plots.GetDim(0) <<" 3D projections of wavefunction"<<endl; count=0; xyz(0)=minmax(0); xyz(1)=minmax(2); xyz(2)=minmax(4); //init elec probe to xmin ymin zmin //Array1 <doublevar> oldpos(3) for(int i=0; i<plots.GetSize(); i++){ cout.width(3); cout <<"============================="<<plots(i) <<"==============================" <<endl; count=0; for(int xx=0; xx<D_array1(0);xx++){ xyz(0)=minmax(0)+xx*resolution_array(0); //move forward on x axis one resolution unit max_value=min_value=0.0; cout << "x "; cout.precision(5); cout.width(8); cout<< xyz(0); for(int yy=0; yy<D_array1(1);yy++){ xyz(1)=minmax(2)+yy*resolution_array(1); //move forward on y axis one resolution unit for(int zz=0;zz<D_array1(2);zz++){ xyz(2)=minmax(4)+zz*resolution_array(2); //move forward on z axis one resolution unit // mywalker->getElectronPos(plots(i), oldpos); mywalker->setElectronPos(plots(i)-1,xyz); //move elec#plots(i) to point specified by xyz wf->updateVal(wfdata, mywalker); //update wfdata wf->getVal(wfdata, 0, wfvals); //get wf value const doublevar cutoff=15; if(wfvals.amp(0,0)<cutoff) { grid(i,count)=wfvals.sign(0)*exp(wfvals.amp(0,0)); } else { //cut off the maximum value output so that there aren't overflow errors grid(i,count)=wfvals.sign(0)*exp(cutoff); } //grid(i,count)=exp(2.0*wfvals(0,1));//!square of wavefunction if (grid(i,count)>max_value) max_value=grid(i,count); if (grid(i,count)<min_value) min_value=grid(i,count); // cout << "grid " << grid(i,count)<< " " << xyz(0) << endl; count++; //index for cycling through grid points } } cout.setf(ios::scientific| ios:: showpos); cout <<", max. value "<<max_value<<", min. value "<<min_value<< endl; cout.unsetf(ios::scientific| ios:: showpos); } mywalker->setElectronPos(plots(i)-1, oldpos(plots(i)-1)); } //Loop through and generate plot files for each orbital requested if(plots.GetSize()<=0) error("Number of requested plots is not a positive number"); cout<<"saving data for "<<plots.GetSize()<<" 3D projections of wavefunction"<<endl; for(int i=0; i<plots.GetSize(); i++) { //output to file with orbital number in it char strbuff[40]; sprintf(strbuff, "%d", plots(i)); confile=pltfile = options.runid; confile += ".orb."; pltfile += ".orb."; pltfile += strbuff; confile += strbuff; pltfile += ".cube"; /*FIGURE OUT HOW TO CONVERT INT TO STRING*/ confile += ".xyz"; os.open(pltfile.c_str()); cout<<"writing to "<<pltfile<<endl; os << "QWalk nodes output\n"; os << "Wavefunction single scan with " << plots(i) <<" electron"<<endl; int natoms=sysprop->nIons(); os << " " << natoms+ mywalker->electronSize()-1 << " " << minmax(0) << " " << minmax(2) << " " << minmax(4) << endl; os << D_array1(0) << " " << resolution_array(0) << " 0.0000 0.0000" << endl; os << D_array1(1) << " 0.0000 " << resolution_array(1) << " 0.0000" << endl; os << D_array1(2) << " 0.0000 0.0000 " << resolution_array(2) << endl; Array1 <doublevar> pos(3); for(int at=0; at< natoms; at++) { mywalker->getIonPos(at,pos); os << " " << mywalker->getIonCharge(at) << " 0.0000 " << pos(0) <<" " << pos(1) << " " << pos(2) << endl; } for(int j=0; j<mywalker->electronSize(); j++){ if (j!=plots(i)-1){ if (j<spin_up) os<<" 3 0.0000 "; else os<<" 3 0.0000 "; os<< oldpos(j,0)<<" "<<oldpos(j,1)<<" "<< oldpos(j,2)<<endl; } } os.setf(ios::scientific); for(int j=0; j< D_array1(0)*D_array1(1)*D_array1(2); j++) { os <<setw(16)<<setprecision(8)<<grid(i,j); if(j%6 ==5) os << endl; } os << endl; os.unsetf(ios::scientific); os<<setprecision(6); os.close(); /* old plt file plots // http://www.csc.fi/gopenmol/developers/plt_format.phtml os<<"3 "; //rank=3 always os<<"2\n"; //dummy variable => "Orbital/density surface" //number of grid points for x, y, & z direction os <<D_array1(2)<<" "<<D_array1(1)<<" "<<D_array1(0)<<endl; os <<minmax(4)<<" "<<minmax(5)<<" "<<minmax(2)<<" "<<minmax(3) <<" "<<minmax(0)<<" "<<minmax(1)<<endl; for(int j=0; j<(D_array1(0)*D_array1(1)*D_array1(2)); j++) os<<grid(i,j)<<endl; os.close(); os.open(confile.c_str()); cout<<"writing to "<<confile<<endl; Array1 <doublevar> pos(3); sysprop->getAtomicLabels(atomlabels); os<<atomlabels.size()+ mywalker->electronSize()-1 <<endl; os << endl; for(unsigned int j=0; j<atomlabels.size();j++){ mywalker->getIonPos(j, pos); os<<atomlabels[j] <<" "<< pos(0) <<" "<<pos(1) <<" "<< pos(2)<<endl; } for(int j=0; j<mywalker->electronSize(); j++){ if (j!=plots(i)-1){ if (j<spin_up) os<<"Eu"; else os<<"Ed"; // mywalker->getElectronPos(j, pos); os<<" "<< oldpos(j,0)<<" "<<oldpos(j,1) <<" "<< oldpos(j,2)<<endl; } } os.close(); */ } } else { cout << "Using translation vector(s): "<<endl; for(int i=0;i<dxyz.GetDim(0);i++) cout<<"( "<<dxyz(i,0)<<" , "<<dxyz(i,1)<<" , "<<dxyz(i,2)<<" )"<<endl; for(int i=0; i<plots.GetSize(); i=i+2){ count=0; xyz(0)=minmax(0); xyz(1)=minmax(2); xyz(2)=minmax(4); //init elec probe to xmin ymin zmin //Array1 <doublevar> oldpos(3) cout.width(3); cout <<"============================="<<plots(i)<<" and "<<plots(i+1) <<"==============================" <<endl; for(int xx=0; xx<D_array1(0);xx++){ max_value=min_value=0.0; xyz(0)=minmax(0)+xx*resolution_array(0); xyz2(0)=xyz(0)+dxyz(i/2,0); cout << "x "; cout.precision(5); cout.width(8); cout<< xyz(0); for(int yy=0; yy<D_array1(1);yy++){ xyz(1)=minmax(2)+yy*resolution_array(1); xyz2(1)=xyz(1)+dxyz(i/2,1); for(int zz=0;zz<D_array1(2);zz++){ xyz(2)=minmax(4)+zz*resolution_array(2); xyz2(2)=xyz(2)+dxyz(i/2,2); // mywalker->getElectronPos(plots(i), oldpos); mywalker->setElectronPos(plots(i)-1,xyz);//move elec#plots(i) //to point specified by xyz mywalker->setElectronPos(plots(i+1)-1,xyz2);//move elec#plots(i) //to point specified by xyz wf->updateVal(wfdata, mywalker); //update wfdata wf->getVal(wfdata, 0, wfvals); //get wf value grid(i,count)=wfvals.sign(0)*exp(wfvals.amp(0,0)); //grid(i,count)=exp(2.0*wfvals(0,1));//!square of wavefunction // cout << "grid " << grid(i,count)<< " " << xyz(0) << endl; if (grid(i,count)>max_value) max_value=grid(i,count); if (grid(i,count)<min_value) min_value=grid(i,count); count++; //index for cycling through grid points } } cout.setf(ios::scientific| ios:: showpos); cout <<", max. value "<<max_value<<", min. value "<<min_value<< endl; cout.unsetf(ios::scientific| ios:: showpos); } mywalker->setElectronPos(plots(i)-1, oldpos(plots(i)-1)); mywalker->setElectronPos(plots(i+1)-1, oldpos(plots(i+1)-1)); } //Loop through and generate plot files for each orbital requested if(plots.GetSize()<=0) error("Number of requested plots is not a positive number"); cout<<"saving data for "<<plots.GetSize()<<" 3D projections of wavefunction"<<endl; for(int i=0; i<plots.GetSize(); i=i+2) { char strbuff2[40],strbuff[40]; //output to file with orbital number in it sprintf(strbuff, "%d", plots(i)); sprintf(strbuff2, "%d", plots(i+1)); confile=pltfile = options.runid; confile += ".orb."; pltfile += ".orb."; pltfile += strbuff; confile += strbuff; pltfile += "with"; confile += "with"; pltfile += strbuff2; confile += strbuff2; pltfile += ".cube"; /*FIGURE OUT HOW TO CONVERT INT TO STRING*/ confile += ".xyz"; os.open(pltfile.c_str()); cout<<"writing to "<<pltfile<<endl; os << "GOS nodes output\n"; os << "Wave function double scan with "<< plots(i) <<" & "<<plots(i+1)<<" electrons"<< endl; int natoms=sysprop->nIons(); os << " " << natoms + mywalker->electronSize()-2 << " " << minmax(0) << " " << minmax(2) << " " << minmax(4) << endl; os << D_array1(0) << " " << resolution_array(0) << " 0.0000 0.0000" << endl; os << D_array1(1) << " 0.0000 " << resolution_array(1) << " 0.0000" << endl; os << D_array1(2) << " 0.0000 0.0000 " << resolution_array(2) << endl; Array1 <doublevar> pos(3); for(int at=0; at< natoms; at++) { mywalker->getIonPos(at,pos); os << " " << mywalker->getIonCharge(at) << " 0.0000 " << pos(0) <<" " << pos(1) << " " << pos(2) << endl; } for(int j=0; j<mywalker->electronSize(); j++){ if ((j!=plots(i)-1)&&(j!=plots(i+1)-1)){ if (j<spin_up) os<<" 3 0.0000 "; else os<<" 3 0.0000 "; os<< oldpos(j,0)<<" "<<oldpos(j,1)<<" "<< oldpos(j,2)<<endl; } } os.setf(ios::scientific); for(int j=0; j< D_array1(0)*D_array1(1)*D_array1(2); j++) { os << setw(16) << setprecision(8) << grid(i,j); if(j%6 ==5) os << endl; } os << endl; os.unsetf(ios::scientific); os<<setprecision(6); os.close(); /* old plot to plt file version // http://www.csc.fi/gopenmol/developers/plt_format.phtml os<<"3 "; //rank=3 always os<<"2\n"; //dummy variable => "Orbital/density surface" //number of grid points for x, y, & z direction os <<D_array1(2)<<" "<<D_array1(1)<<" "<<D_array1(0)<<endl; os <<minmax(4)<<" "<<minmax(5)<<" "<<minmax(2)<<" "<<minmax(3) <<" "<<minmax(0)<<" "<<minmax(1)<<endl; for(int j=0; j<(D_array1(0)*D_array1(1)*D_array1(2)); j++) os<<grid(i,j)<<endl; os.close(); os.open(confile.c_str()); cout<<"writing to "<<confile<<endl; Array1 <doublevar> pos(3); sysprop->getAtomicLabels(atomlabels); os<<atomlabels.size()+ mywalker->electronSize()-2 <<endl; os << endl; for(unsigned int j=0; j<atomlabels.size();j++){ mywalker->getIonPos(j, pos); os<<atomlabels[j] <<" "<< pos(0) <<" "<<pos(1) <<" "<< pos(2)<<endl; } for(int j=0; j<mywalker->electronSize(); j++){ if ((j!=plots(i)-1)&&(j!=plots(i+1)-1)){ if (j<spin_up) os<<"Eu"; else os<<"Ed"; // mywalker->getElectronPos(j, pos); os<<" "<< oldpos(j,0)<<" "<<oldpos(j,1) <<" "<< oldpos(j,2)<<endl; } } os.close(); */ } } cout <<"End of Nodes Method"<<endl; }