#include <iostream>
#include <fstream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <getopt.h>
#include <cstdio>
#include <cstdlib>
void writefile(ofstream& outf,
AtomVec& atoms,
Box& bx);
void writetcl(
const char *fname,
OriginBox& box, vector<flt> &atomsizes);
int main(int argc, char **argv){
int c;
int Natoms=40;
int tottime=2000000;
string outname = "hardspheres.msd";
opterr = 0;
while ((c = getopt (argc, argv, "n:f:s:d:t:o:")) != -1) switch (c){
case 'n':
Natoms = (int) atol(optarg);
break;
case 'f':
phi = atof(optarg);
break;
case 's':
sizeratio = atof(optarg);
break;
case 'd':
break;
case 't':
tottime = (int) atof(optarg);
break;
case 'o':
outname = optarg;
break;
default:
abort ();
}
ofstream myfile;
myfile.open(outname.c_str());
cout << "Running..." << endl;
string xyzname=outname.substr(0,outname.size()-4)+".xyz";
string tclname=outname.substr(0,outname.size()-4)+".tcl";
vector<flt> atomsizes(Natoms, sigma);
atomsizes[0] = sigma * sizeratio;
vector<flt> atommasses(Natoms, 1);
atommasses[0] = pow(sizeratio,
NDIM);
for(
uint i=0; i<atomsizes.size(); ++i){
Vs += pow(atomsizes[i],
NDIM) * M_PI / 2 /
NDIM;
};
assert(L > (atomsizes[0] + atomsizes[1]));
cout <<
"phi " << (Vs/pow(L,
NDIM)) <<
"\n";
boost::shared_ptr<OriginBox> obox(
new OriginBox(L));
boost::shared_ptr<Box> boxptr = boost::static_pointer_cast<
Box>(obox);
boost::shared_ptr<AtomVec> atomptr(
new AtomVec(atommasses));
boost::shared_ptr<AtomGroup> group(atomptr);
boost::shared_ptr<NListed<EpsSigExpAtom, RepulsionPair> > hertz(
boxptr, atomptr, 0.4*(sigcut*sigma)
));
boost::shared_ptr<NeighborList> nl = hertz->neighbor_list();
atoms[i].x = obox->rand_loc();
atoms[i].v = Vec::Zero();
atoms[i].f = Vec::Zero();
atoms[i].a = Vec::Zero();
if(i==0) (cursigma = sigma*sizeratio);
}
nl->update_list(true);
int swtch = 0;
cout << "Energy0: " << U << "\n";
while(swtch == 0){
if (U==0){
swtch=1;
}
else if (U<=U0){
U1=U;
cout << "Energy: " << U << "\n";
}
else if (U>.99*U1){
swtch=1;
}
}
cout << "Energyf: " << U << "\n";
if (U==0){
cout << "Equilibrating... \n";
for(
uint i=0; i<printn; ++i){
cout << (printn-i) << ", " << std::flush;
}
cout << "Done.\n";
set<uint> nset;
flt maxlog = log(tottime);
for(
uint n=0; n<nMSDs; n++){
flt newlog = (maxlog * n) / (nMSDs-1);
if(newn <= 0) newn = 1;
if(newn > (
uint)tottime) newn = tottime;
nset.insert(newn);
}
vector<long unsigned int> MSDns(nset.begin(), nset.end());
cout << "Using " << MSDns.size() << " MSDns, [" << MSDns.front() << "-" << MSDns.back() << "]\n";
boost::shared_ptr<RsqTracker> rsqtracker(
new RsqTracker(atomptr, MSDns));
boost::shared_ptr<StateTracker> rsqptr = boost::static_pointer_cast<
StateTracker>(rsqtracker);
ofstream xyzfile;
xyzfile.open(xyzname.c_str(), ios::out);
writefile(xyzfile, atoms, *obox);
writetcl(tclname.c_str(), *obox, atomsizes);
cout << "Running... \n";
for(
uint i=0; i<printn; ++i){
cout << (printn-i) << ", " << std::flush;
writefile(xyzfile, atoms, *obox);
}
cout << "Done, saving MSDs\n";
ofstream msdfile;
msdfile.open(outname.c_str(), ios::out);
vector<Eigen::Matrix<flt, Eigen::Dynamic, NDIM> > MSDmeans = rsqtracker->xyz2();
for(
uint i=0; i<MSDns.size(); i++){
msdfile << (((
flt) MSDns[i]) * dt);
for(
uint j=0; j<MSDmeans[i].rows(); j++){
Vec v = MSDmeans[i].row(j);
msdfile << '\t' << (v[0] + v[1] + v[2]);
}
msdfile << "\n";
}
cout << "Done." << endl;
return 0;
};
};
void writetcl(
const char *fname,
OriginBox& box, vector<flt> &atomsizes){
ofstream pbcfile;
pbcfile.open(fname, ios::out);
pbcfile << "set natoms [atomselect 0 \"name O\";];\n";
pbcfile << "$natoms set radius " << (atomsizes[0]/2.0) << ";\n";
pbcfile << "set natoms [atomselect 0 \"name C\";];\n";
pbcfile << "$natoms set radius " << (atomsizes[1]/2.0) << ";\n\n";
pbcfile << "set cell [pbc set {";
pbcfile << box.box_shape()[j] << " ";
}
pbcfile << "} -all];\n";
pbcfile << "pbc box -toggle -center origin -color red;\n";
};
void writefile(ofstream& outf,
AtomVec& atoms,
Box& bx){
outf << atoms.
size() << endl;
outf << endl;
if(i == 0){outf << "O";}
else{outf << "C";};
Vec normloc = bx.
diff(Vec::Zero(), atoms[i].x);
outf << "\t" << normloc[j];
}
outf << endl;
};
};