| 47 |
|
#include <string> |
| 48 |
|
#include <map> |
| 49 |
|
#include <fstream> |
| 50 |
+ |
#include <algorithm> |
| 51 |
|
|
| 52 |
|
#include "config.h" |
| 53 |
< |
|
| 53 |
> |
#include "shapedLatticeSpherical.hpp" |
| 54 |
|
#include "nanoparticleBuilderCmd.h" |
| 54 |
– |
#include "sphericalNanoparticle.hpp" |
| 55 |
|
#include "lattice/LatticeFactory.hpp" |
| 56 |
|
#include "utils/MoLocator.hpp" |
| 57 |
|
#include "lattice/Lattice.hpp" |
| 67 |
|
using namespace oopse; |
| 68 |
|
void createMdFile(const std::string&oldMdFileName, |
| 69 |
|
const std::string&newMdFileName, |
| 70 |
< |
int numMol); |
| 70 |
> |
int components,int* numMol); |
| 71 |
|
|
| 72 |
|
int main(int argc, char *argv []) { |
| 73 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
Lattice *simpleLat; |
| 88 |
< |
int numMol; |
| 88 |
> |
MoLocator* locator; |
| 89 |
> |
int* numMol; |
| 90 |
> |
int nComponents; |
| 91 |
|
double latticeConstant; |
| 92 |
|
std::vector<double> lc; |
| 93 |
|
double mass; |
| 94 |
|
const double rhoConvertConst = 1.661; |
| 95 |
|
double density; |
| 96 |
+ |
double particleRadius; |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
Mat3x3d hmat; |
| 98 |
– |
MoLocator *locator; |
| 99 |
– |
sphericalNanoparticle *nanoparticle; |
| 101 |
|
std::vector<Vector3d> latticePos; |
| 102 |
|
std::vector<Vector3d> latticeOrt; |
| 103 |
|
int numMolPerCell; |
| 128 |
|
SimCreator oldCreator; |
| 129 |
|
SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); |
| 130 |
|
|
| 130 |
– |
nShells = 0; |
| 131 |
– |
if (args_info.coreShellRadius_given){ |
| 132 |
– |
nShells = args_info.coreShellRadius_given; |
| 133 |
– |
} |
| 131 |
|
|
| 135 |
– |
nComponents = oldInfo->getNMoleculeStamp(); |
| 136 |
– |
|
| 137 |
– |
/* Check to see if we have enough components to build that many shells. */ |
| 138 |
– |
if (nShells){ |
| 139 |
– |
if (oldInfo->getNMoleculeStamp() != nShells) { |
| 140 |
– |
std::cerr << "Not enough components present in MD file to build specified number of shells" |
| 141 |
– |
<< std::endl; |
| 142 |
– |
exit(1); |
| 143 |
– |
} |
| 144 |
– |
} |
| 145 |
– |
|
| 146 |
– |
|
| 147 |
– |
//creat lattice |
| 148 |
– |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
| 149 |
– |
|
| 150 |
– |
if (simpleLat == NULL) { |
| 151 |
– |
std::cerr << "Error in creating lattice" << std::endl; |
| 152 |
– |
exit(1); |
| 153 |
– |
} |
| 154 |
– |
|
| 155 |
– |
numMolPerCell = simpleLat->getNumSitesPerCell(); |
| 156 |
– |
|
| 132 |
|
/*calculate lattice constant (in Angstrom) |
| 133 |
|
latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density, |
| 134 |
|
1.0 / 3.0);*/ |
| 135 |
|
|
| 136 |
|
latticeConstant = args_info.latticeCnst_arg; |
| 137 |
|
particleRadius = args_info.radius_arg; |
| 138 |
< |
particleDiameter = 2.0 * particleRadius; |
| 138 |
> |
Globals* simParams = oldInfo->getSimParams(); |
| 139 |
|
|
| 140 |
< |
/* set lattice constant */ |
| 141 |
< |
lc.push_back(latticeConstant); |
| 167 |
< |
simpleLat->setLatticeConstant(lc); |
| 140 |
> |
/* Find out how many different components in this simualtion */ |
| 141 |
> |
nComponents =simParams->getNComponents(); |
| 142 |
|
|
| 169 |
– |
|
| 143 |
|
/*determine the output file names*/ |
| 144 |
|
if (args_info.output_given){ |
| 145 |
|
outInitFileName = args_info.output_arg; |
| 146 |
|
}else{ |
| 147 |
|
outInitFileName = getPrefix(inputFileName.c_str()) + ".in"; |
| 148 |
|
} |
| 149 |
+ |
|
| 150 |
|
|
| 177 |
– |
|
| 151 |
|
|
| 179 |
– |
|
| 180 |
– |
|
| 152 |
|
/* create Molocators */ |
| 153 |
|
locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
| 154 |
|
|
| 155 |
< |
/* create a new spherical nanoparticle */ |
| 156 |
< |
nanoparticle = new sphericalNanoparticle(particleRadius,latticeConstant); |
| 157 |
< |
/* Build a nanoparticle to see how many sites are there */ |
| 158 |
< |
numSites = new int[nComponents] |
| 159 |
< |
int numSites = nanoparticle.getNMol(simpleLat); |
| 155 |
> |
/* Create nanoparticle */ |
| 156 |
> |
shapedLatticeSpherical nanoParticle(latticeConstant,latticeType,particleRadius); |
| 157 |
> |
/* Build a lattice and get lattice points for this lattice constant */ |
| 158 |
> |
vector<Vector3d> nanoParticleSites = nanoParticle.getPoints(); |
| 159 |
> |
/* Get number of lattice sites */ |
| 160 |
> |
numSites = nanoParticleSites.size(); |
| 161 |
> |
|
| 162 |
> |
numMol = new int[nComponents]; |
| 163 |
> |
|
| 164 |
|
|
| 190 |
– |
|
| 165 |
|
/* Random particle is the default case*/ |
| 166 |
|
if (!args_info.ShellRadius_given){ |
| 167 |
|
std::cout << "Creating a random nanoparticle" << std::endl; |
| 168 |
|
/* Check to see if we have enough components */ |
| 169 |
|
if (nComponents != args_info.molFraction_given + 1){ |
| 170 |
|
std::cerr << "Number of components does not equal molFraction occurances." << std::endl; |
| 171 |
< |
exit 1; |
| 171 |
> |
exit(1); |
| 172 |
|
} |
| 173 |
+ |
/* Build the mole fractions and number of molecules of each type */ |
| 174 |
|
int totComponents = 0; |
| 175 |
|
for (int i = 0;i<nComponents-2;i++){ /* Figure out Percent for each component */ |
| 176 |
|
numMol[i] = int((double)numSites * args_info.molFraction_arg[i]); |
| 177 |
|
totComponents += numMol[i]; |
| 178 |
|
} |
| 179 |
|
numMol[nComponents-1] = numSites - totComponents; |
| 180 |
< |
|
| 180 |
> |
/* do the iPod thing, Shuffle da vector */ |
| 181 |
> |
std::random_shuffle(nanoParticleSites.begin(), nanoParticleSites.end()); |
| 182 |
|
} else{ /*Handle core-shell with multiple components.*/ |
| 183 |
|
std::cout << "Creating a core-shell nanoparticle." << std::endl; |
| 184 |
|
if (nComponents != args_info.ShellRadius_given + 1){ |
| 185 |
|
std::cerr << "Number of components does not equal ShellRadius occurances." << std::endl; |
| 186 |
< |
exit 1; |
| 187 |
< |
} |
| 186 |
> |
exit(1); |
| 187 |
> |
} |
| 188 |
|
|
| 213 |
– |
|
| 214 |
– |
|
| 189 |
|
} |
| 190 |
|
|
| 191 |
+ |
|
| 192 |
|
//get the orientation of the cell sites |
| 193 |
|
//for the same type of molecule in same lattice, it will not change |
| 194 |
< |
latticeOrt = simpleLat->getLatticePointsOrt(); |
| 194 |
> |
latticeOrt = nanoParticle.getPointsOrt(); |
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 201 |
|
outMdFileName = outPrefix + ".md"; |
| 202 |
|
|
| 203 |
|
//creat new .md file on fly which corrects the number of molecule |
| 204 |
< |
createMdFile(inputFileName, outMdFileName, numcomponents,numMol); |
| 204 |
> |
createMdFile(inputFileName, outMdFileName, nComponents,numMol); |
| 205 |
|
|
| 206 |
|
if (oldInfo != NULL) |
| 207 |
|
delete oldInfo; |
| 213 |
|
|
| 214 |
|
SimInfo* NewInfo = oldCreator.createSim(outMdFileName, false); |
| 215 |
|
|
| 241 |
– |
// This was so much fun the first time, lets do it again. |
| 216 |
|
|
| 217 |
+ |
// Place molecules |
| 218 |
|
Molecule* mol; |
| 219 |
|
SimInfo::MoleculeIterator mi; |
| 220 |
|
mol = NewInfo->beginMolecule(mi); |
| 221 |
+ |
int l = 0; |
| 222 |
+ |
for (mol = NewInfo->beginMolecule(mi); mol != NULL; mol = NewInfo->nextMolecule(mi)) { |
| 223 |
+ |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
| 224 |
+ |
l++; |
| 225 |
+ |
} |
| 226 |
|
|
| 227 |
|
|
| 248 |
– |
for(int i = -nx; i < nx; i++) { |
| 249 |
– |
for(int j = -ny; j < ny; j++) { |
| 250 |
– |
for(int k = -nz; k < nz; k++) { |
| 251 |
– |
|
| 252 |
– |
//get the position of the cell sites |
| 253 |
– |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
| 254 |
– |
|
| 255 |
– |
for(int l = 0; l < numMolPerCell; l++) { |
| 256 |
– |
#ifdef HAVE_CGAL |
| 257 |
– |
if (myGeometry->isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
| 258 |
– |
#endif |
| 259 |
– |
if (mol != NULL) { |
| 260 |
– |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
| 261 |
– |
} else { |
| 262 |
– |
std::cerr<<"Error in placing molecule " << std::endl; |
| 263 |
– |
} |
| 264 |
– |
mol = NewInfo->nextMolecule(mi); |
| 265 |
– |
#ifdef HAVE_CGAL |
| 266 |
– |
} |
| 267 |
– |
#endif |
| 268 |
– |
} |
| 269 |
– |
} |
| 270 |
– |
} |
| 271 |
– |
} |
| 272 |
– |
|
| 228 |
|
|
| 229 |
+ |
|
| 230 |
+ |
|
| 231 |
|
|
| 232 |
|
//fill Hmat |
| 233 |
< |
hmat(0, 0)= nx * latticeConstant; |
| 233 |
> |
hmat(0, 0)= latticeConstant; |
| 234 |
|
hmat(0, 1) = 0.0; |
| 235 |
|
hmat(0, 2) = 0.0; |
| 236 |
|
|
| 237 |
|
hmat(1, 0) = 0.0; |
| 238 |
< |
hmat(1, 1) = ny * latticeConstant; |
| 238 |
> |
hmat(1, 1) = latticeConstant; |
| 239 |
|
hmat(1, 2) = 0.0; |
| 240 |
|
|
| 241 |
|
hmat(2, 0) = 0.0; |
| 242 |
|
hmat(2, 1) = 0.0; |
| 243 |
< |
hmat(2, 2) = nz * latticeConstant; |
| 243 |
> |
hmat(2, 2) = latticeConstant; |
| 244 |
|
|
| 245 |
|
//set Hmat |
| 246 |
|
NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat); |
| 267 |
|
delete NewInfo; |
| 268 |
|
|
| 269 |
|
if (writer != NULL) |
| 270 |
< |
delete writer; |
| 314 |
< |
delete simpleLat; |
| 270 |
> |
delete writer; |
| 271 |
|
cmdline_parser_free(&args_info); |
| 272 |
|
return 0; |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName, |
| 276 |
< |
int components,int &nummol) { |
| 276 |
> |
int components,int* numMol) { |
| 277 |
|
ifstream oldMdFile; |
| 278 |
|
ofstream newMdFile; |
| 279 |
|
const int MAXLEN = 65535; |
| 284 |
|
newMdFile.open(newMdFileName.c_str()); |
| 285 |
|
|
| 286 |
|
oldMdFile.getline(buffer, MAXLEN); |
| 287 |
< |
|
| 287 |
> |
|
| 288 |
> |
int i = 0; |
| 289 |
|
while (!oldMdFile.eof()) { |
| 290 |
|
|
| 291 |
|
//correct molecule number |
| 292 |
|
if (strstr(buffer, "nMol") != NULL) { |
| 293 |
< |
sprintf(buffer, "\tnMol = %i;", numMol); |
| 293 |
> |
if(i<components){ |
| 294 |
> |
sprintf(buffer, "\tnMol = %i;", numMol[i]); |
| 295 |
|
newMdFile << buffer << std::endl; |
| 296 |
+ |
i++; |
| 297 |
+ |
} |
| 298 |
|
} else |
| 299 |
|
newMdFile << buffer << std::endl; |
| 300 |
|
|