| 12 |
|
#include "sysBuild.hpp" |
| 13 |
|
#include "bilayerSys.hpp" |
| 14 |
|
|
| 15 |
+ |
#include "latticeBuilder.hpp" |
| 16 |
|
|
| 16 |
– |
|
| 17 |
|
void buildMap( double &x, double &y, double &z, |
| 18 |
< |
double boxX, double boxY, double boxZ ); |
| 18 |
> |
double boxX, double boxY, double boxZ ); |
| 19 |
|
|
| 20 |
|
int buildRandomBilayer( void ); |
| 21 |
|
|
| 44 |
|
} coord; |
| 45 |
|
|
| 46 |
|
|
| 47 |
+ |
|
| 48 |
|
const double waterRho = 0.0334; // number density per cubic angstrom |
| 49 |
|
const double waterVol = 4.0 / waterRho; // volume occupied by 4 waters |
| 50 |
|
const double waterCell = 4.929; // fcc unit cell length |
| 51 |
|
|
| 52 |
+ |
Lattice myFCC( FCC_LATTICE_TYPE, waterCell ); |
| 53 |
+ |
double *posX, *posY, *posZ; |
| 54 |
+ |
double pos[3], posA[3], posB[3]; |
| 55 |
+ |
|
| 56 |
|
const double water_padding = 6.0; |
| 57 |
|
const double lipid_spaceing = 8.0; |
| 58 |
|
|
| 59 |
|
|
| 60 |
< |
int i,j,k, l; |
| 60 |
> |
int i,j,k, l, m; |
| 61 |
|
int nAtoms, atomIndex, molIndex, molID; |
| 62 |
|
int* molSeq; |
| 63 |
|
int* molMap; |
| 72 |
|
|
| 73 |
|
Atom** atoms; |
| 74 |
|
SimInfo* simnfo; |
| 75 |
+ |
SimState* theConfig; |
| 76 |
|
DumpWriter* writer; |
| 77 |
|
|
| 78 |
|
MoleculeStamp* lipidStamp; |
| 97 |
|
foundWater = 0; |
| 98 |
|
for(i=0; i<bsInfo.nComponents; i++){ |
| 99 |
|
if( !strcmp( bsInfo.compStamps[i]->getID(), bsInfo.lipidName ) ){ |
| 100 |
< |
|
| 100 |
> |
|
| 101 |
|
foundLipid = 1; |
| 102 |
|
lipidStamp = bsInfo.compStamps[i]; |
| 103 |
|
nLipids = bsInfo.componentsNmol[i]; |
| 104 |
|
} |
| 105 |
|
if( !strcmp( bsInfo.compStamps[i]->getID(), bsInfo.waterName ) ){ |
| 106 |
< |
|
| 106 |
> |
|
| 107 |
|
foundWater = 1; |
| 108 |
< |
|
| 108 |
> |
|
| 109 |
|
waterStamp = bsInfo.compStamps[i]; |
| 110 |
|
nWaters = bsInfo.componentsNmol[i]; |
| 111 |
|
} |
| 118 |
|
simError(); |
| 119 |
|
} |
| 120 |
|
if( !foundWater ){ |
| 121 |
< |
sprintf(painCave.errMsg, |
| 122 |
< |
"Could not find solvent \"%s\" in the bass file.\n", |
| 121 |
> |
sprintf(painCave.errMsg, |
| 122 |
> |
"Could not find solvent \"%s\" in the bass file.\n", |
| 123 |
|
bsInfo.waterName ); |
| 124 |
|
painCave.isFatal = 1; |
| 125 |
|
simError(); |
| 134 |
|
waterLocate = new MoLocator( waterStamp ); |
| 135 |
|
waterNatoms = waterStamp->getNAtoms(); |
| 136 |
|
|
| 137 |
< |
nAtoms = nLipids * lipidNatoms; |
| 137 |
> |
nAtoms = lipidNatoms; |
| 138 |
|
|
| 139 |
< |
simnfo[0].n_atoms = nAtoms; |
| 140 |
< |
simnfo[0].atoms=new Atom*[nAtoms]; |
| 139 |
> |
simnfo[0].n_atoms = nAtoms; |
| 140 |
> |
simnfo[0].atoms=new Atom*[nAtoms]; |
| 141 |
|
|
| 142 |
< |
(simnfo[0]->getConfiguration())->createArrays( simnfo[0].n_atoms ); |
| 143 |
< |
for(i=0; i<simnfo[0].n_atoms; i++) simnfo[0].atoms[i]->setCoords(); |
| 142 |
> |
theConfig = simnfo[0].getConfiguration(); |
| 143 |
> |
theConfig->createArrays( simnfo[0].n_atoms ); |
| 144 |
|
|
| 145 |
< |
atoms=simnfo[0].atoms; |
| 145 |
> |
atoms=simnfo[0].atoms; |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
// create the test box for initial water displacement |
| 166 |
|
for( i=0; i < nCells; i++ ){ |
| 167 |
|
for( j=0; j < nCells; j++ ){ |
| 168 |
|
for( k=0; k < nCells; k++ ){ |
| 169 |
< |
|
| 170 |
< |
waterX[ndx] = i * waterCell + x0; |
| 171 |
< |
waterY[ndx] = j * waterCell + y0; |
| 172 |
< |
waterZ[ndx] = k * waterCell + z0; |
| 173 |
< |
ndx++; |
| 174 |
< |
|
| 175 |
< |
waterX[ndx] = i * waterCell + 0.5 * waterCell + x0; |
| 176 |
< |
waterY[ndx] = j * waterCell + 0.5 * waterCell + y0; |
| 171 |
< |
waterZ[ndx] = k * waterCell + z0; |
| 172 |
< |
ndx++; |
| 173 |
< |
|
| 174 |
< |
waterX[ndx] = i * waterCell + x0; |
| 175 |
< |
waterY[ndx] = j * waterCell + 0.5 * waterCell + y0; |
| 176 |
< |
waterZ[ndx] = k * waterCell + 0.5 * waterCell + z0; |
| 177 |
< |
ndx++; |
| 178 |
< |
|
| 179 |
< |
waterX[ndx] = i * waterCell + 0.5 * waterCell + x0; |
| 180 |
< |
waterY[ndx] = j * waterCell + y0; |
| 181 |
< |
waterZ[ndx] = k * waterCell + 0.5 * waterCell + z0; |
| 182 |
< |
ndx++; |
| 169 |
> |
|
| 170 |
> |
myFCC.getLatticePoints(&posX, &posY, &posZ, i, j, k); |
| 171 |
> |
for(l=0; l<4; l++){ |
| 172 |
> |
waterX[ndx]=posX[l]; |
| 173 |
> |
waterY[ndx]=posY[l]; |
| 174 |
> |
waterZ[ndx]=posZ[l]; |
| 175 |
> |
ndx++; |
| 176 |
> |
} |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
|
} |
| 196 |
|
testSite.pos[1] = 0.0; |
| 197 |
|
testSite.pos[2] = 0.0; |
| 198 |
|
|
| 199 |
< |
lipidLocate->placeMol( testSite.pos, testSite.rot, atoms, 0 ); |
| 199 |
> |
lipidLocate->placeMol( testSite.pos, testSite.rot, atoms, 0, theConfig ); |
| 200 |
|
|
| 201 |
|
int *isActive = new int[testWaters]; |
| 202 |
|
for(i=0; i<testWaters; i++) isActive[i] = 1; |
| 208 |
|
|
| 209 |
|
for(i=0; ( (i<testWaters) && isActive[i] ); i++){ |
| 210 |
|
for(j=0; ( (j<lipidNatoms) && isActive[i] ); j++){ |
| 211 |
+ |
|
| 212 |
+ |
atoms[j]->getPos( pos ); |
| 213 |
|
|
| 214 |
< |
dx = waterX[i] - atoms[j]->getX(); |
| 215 |
< |
dy = waterY[i] - atoms[j]->getY(); |
| 216 |
< |
dz = waterZ[i] - atoms[j]->getZ(); |
| 214 |
> |
dx = waterX[i] - pos[0]; |
| 215 |
> |
dy = waterY[i] - pos[1]; |
| 216 |
> |
dz = waterZ[i] - pos[2]; |
| 217 |
|
|
| 218 |
|
buildMap( dx, dy, dz, testBox, testBox, testBox ); |
| 219 |
|
|
| 220 |
|
dx2 = dx * dx; |
| 221 |
|
dy2 = dy * dy; |
| 222 |
|
dz2 = dz * dz; |
| 223 |
< |
|
| 223 |
> |
|
| 224 |
|
dSqr = dx2 + dy2 + dz2; |
| 225 |
|
if( dSqr < rCutSqr ){ |
| 226 |
|
isActive[i] = 0; |
| 239 |
|
int done = 0; |
| 240 |
|
ndx = 0; |
| 241 |
|
while( !done ){ |
| 242 |
< |
|
| 242 |
> |
|
| 243 |
|
ndx++; |
| 244 |
|
testTot = 4 * ndx * ndx * ndx; |
| 245 |
< |
|
| 245 |
> |
|
| 246 |
|
if( testTot >= targetWaters ) done = 1; |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
nCells = ndx; |
| 250 |
< |
|
| 251 |
< |
|
| 250 |
> |
|
| 251 |
> |
|
| 252 |
|
// create the new water box to the new specifications |
| 253 |
|
|
| 254 |
|
int newWaters = nCells * nCells * nCells * 4; |
| 262 |
|
double box_x = waterCell * nCells; |
| 263 |
|
double box_y = waterCell * nCells; |
| 264 |
|
double box_z = waterCell * nCells; |
| 265 |
< |
|
| 265 |
> |
|
| 266 |
|
// create an fcc lattice in the water box. |
| 267 |
|
|
| 268 |
|
ndx = 0; |
| 269 |
|
for( i=0; i < nCells; i++ ){ |
| 270 |
|
for( j=0; j < nCells; j++ ){ |
| 271 |
|
for( k=0; k < nCells; k++ ){ |
| 272 |
< |
|
| 273 |
< |
waterSites[ndx].pos[0] = i * waterCell; |
| 274 |
< |
waterSites[ndx].pos[1] = j * waterCell; |
| 275 |
< |
waterSites[ndx].pos[2] = k * waterCell; |
| 276 |
< |
ndx++; |
| 277 |
< |
|
| 278 |
< |
waterSites[ndx].pos[0] = i * waterCell + 0.5 * waterCell; |
| 279 |
< |
waterSites[ndx].pos[1] = j * waterCell + 0.5 * waterCell; |
| 284 |
< |
waterSites[ndx].pos[2] = k * waterCell; |
| 285 |
< |
ndx++; |
| 286 |
< |
|
| 287 |
< |
waterSites[ndx].pos[0] = i * waterCell; |
| 288 |
< |
waterSites[ndx].pos[1] = j * waterCell + 0.5 * waterCell; |
| 289 |
< |
waterSites[ndx].pos[2] = k * waterCell + 0.5 * waterCell; |
| 290 |
< |
ndx++; |
| 291 |
< |
|
| 292 |
< |
waterSites[ndx].pos[0] = i * waterCell + 0.5 * waterCell; |
| 293 |
< |
waterSites[ndx].pos[1] = j * waterCell; |
| 294 |
< |
waterSites[ndx].pos[2] = k * waterCell + 0.5 * waterCell; |
| 295 |
< |
ndx++; |
| 272 |
> |
|
| 273 |
> |
myFCC.getLatticePoints(&posX, &posY, &posZ, i, j, k); |
| 274 |
> |
for(l=0; l<4; l++){ |
| 275 |
> |
waterSites[ndx].pos[0] = posX[l]; |
| 276 |
> |
waterSites[ndx].pos[1] = posY[l]; |
| 277 |
> |
waterSites[ndx].pos[2] = posZ[l]; |
| 278 |
> |
ndx++; |
| 279 |
> |
} |
| 280 |
|
} |
| 281 |
|
} |
| 282 |
|
} |
| 289 |
|
int reject; |
| 290 |
|
int testDX, acceptedDX; |
| 291 |
|
|
| 292 |
+ |
nAtoms = nLipids * lipidNatoms; |
| 293 |
+ |
|
| 294 |
+ |
simnfo[1].n_atoms = nAtoms; |
| 295 |
+ |
simnfo[1].atoms=new Atom*[nAtoms]; |
| 296 |
+ |
|
| 297 |
+ |
theConfig = simnfo[1].getConfiguration(); |
| 298 |
+ |
theConfig->createArrays( simnfo[1].n_atoms ); |
| 299 |
+ |
|
| 300 |
+ |
atoms=simnfo[1].atoms; |
| 301 |
+ |
|
| 302 |
|
rCutSqr = lipid_spaceing * lipid_spaceing; |
| 303 |
|
|
| 304 |
|
for(i=0; i<nLipids; i++ ){ |
| 305 |
|
done = 0; |
| 306 |
|
while( !done ){ |
| 307 |
< |
|
| 307 |
> |
|
| 308 |
|
lipidSites[i].pos[0] = drand48() * box_x; |
| 309 |
|
lipidSites[i].pos[1] = drand48() * box_y; |
| 310 |
|
lipidSites[i].pos[2] = drand48() * box_z; |
| 311 |
< |
|
| 311 |
> |
|
| 312 |
|
getRandomRot( lipidSites[i].rot ); |
| 313 |
< |
|
| 313 |
> |
|
| 314 |
|
ndx = i * lipidNatoms; |
| 315 |
|
|
| 316 |
|
lipidLocate->placeMol( lipidSites[i].pos, lipidSites[i].rot, atoms, |
| 317 |
< |
ndx ); |
| 318 |
< |
|
| 317 |
> |
ndx, theConfig ); |
| 318 |
> |
|
| 319 |
|
reject = 0; |
| 320 |
|
for( j=0; !reject && j<i; j++){ |
| 321 |
|
for(k=0; !reject && k<lipidNatoms; k++){ |
| 322 |
|
|
| 323 |
|
acceptedDX = j*lipidNatoms + k; |
| 324 |
|
for(l=0; !reject && l<lipidNatoms; l++){ |
| 325 |
< |
|
| 325 |
> |
|
| 326 |
|
testDX = ndx + l; |
| 327 |
|
|
| 328 |
< |
dx = atoms[testDX]->getX() - atoms[acceptedDX]->getX(); |
| 329 |
< |
dy = atoms[testDX]->getY() - atoms[acceptedDX]->getY(); |
| 336 |
< |
dz = atoms[testDX]->getZ() - atoms[acceptedDX]->getZ(); |
| 328 |
> |
atoms[testDX]->getPos( posA ); |
| 329 |
> |
atoms[acceptedDX]->getPos( posB ); |
| 330 |
|
|
| 331 |
+ |
dx = posA[0] - posB[0]; |
| 332 |
+ |
dy = posA[1] - posB[1]; |
| 333 |
+ |
dz = posA[2] - posB[2]; |
| 334 |
+ |
|
| 335 |
|
buildMap( dx, dy, dz, box_x, box_y, box_z ); |
| 336 |
< |
|
| 336 |
> |
|
| 337 |
|
dx2 = dx * dx; |
| 338 |
|
dy2 = dy * dy; |
| 339 |
|
dz2 = dz * dz; |
| 340 |
< |
|
| 340 |
> |
|
| 341 |
|
dSqr = dx2 + dy2 + dz2; |
| 342 |
|
if( dSqr < rCutSqr ) reject = 1; |
| 343 |
|
} |
| 350 |
|
} |
| 351 |
|
else{ |
| 352 |
|
done = 1; |
| 353 |
< |
std::cout << i << " has been accepted\n"; |
| 353 |
> |
std::cout << (i+1) << " has been accepted\n"; |
| 354 |
|
} |
| 355 |
|
} |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
// cut out the waters that overlap with the lipids. |
| 359 |
|
|
| 360 |
+ |
|
| 361 |
|
delete[] isActive; |
| 362 |
|
isActive = new int[newWaters]; |
| 363 |
|
for(i=0; i<newWaters; i++) isActive[i] = 1; |
| 367 |
|
for(i=0; ( (i<newWaters) && isActive[i] ); i++){ |
| 368 |
|
for(j=0; ( (j<nAtoms) && isActive[i] ); j++){ |
| 369 |
|
|
| 370 |
< |
dx = waterSites[i].pos[0] - atoms[j]->getX(); |
| 373 |
< |
dy = waterSites[i].pos[1] - atoms[j]->getY(); |
| 374 |
< |
dz = waterSites[i].pos[2] - atoms[j]->getZ(); |
| 370 |
> |
atoms[j]->getPos( pos ); |
| 371 |
|
|
| 372 |
+ |
dx = waterSites[i].pos[0] - pos[0]; |
| 373 |
+ |
dy = waterSites[i].pos[1] - pos[1]; |
| 374 |
+ |
dz = waterSites[i].pos[2] - pos[2]; |
| 375 |
+ |
|
| 376 |
|
buildMap( dx, dy, dz, box_x, box_y, box_z ); |
| 377 |
|
|
| 378 |
|
dx2 = dx * dx; |
| 379 |
|
dy2 = dy * dy; |
| 380 |
|
dz2 = dz * dz; |
| 381 |
< |
|
| 381 |
> |
|
| 382 |
|
dSqr = dx2 + dy2 + dz2; |
| 383 |
|
if( dSqr < rCutSqr ){ |
| 384 |
|
isActive[i] = 0; |
| 385 |
|
n_active--; |
| 386 |
+ |
|
| 387 |
+ |
|
| 388 |
|
} |
| 389 |
|
} |
| 390 |
|
} |
| 391 |
|
|
| 392 |
+ |
|
| 393 |
+ |
|
| 394 |
+ |
|
| 395 |
|
if( n_active < nWaters ){ |
| 396 |
< |
|
| 396 |
> |
|
| 397 |
|
sprintf( painCave.errMsg, |
| 398 |
|
"Too many waters were removed, edit code and try again.\n" ); |
| 399 |
< |
|
| 399 |
> |
|
| 400 |
|
painCave.isFatal = 1; |
| 401 |
|
simError(); |
| 402 |
|
} |
| 409 |
|
if( isActive[quickKill] ){ |
| 410 |
|
isActive[quickKill] = 0; |
| 411 |
|
n_active--; |
| 412 |
+ |
|
| 413 |
|
} |
| 414 |
|
} |
| 415 |
|
|
| 416 |
|
if( n_active != nWaters ){ |
| 417 |
< |
|
| 417 |
> |
|
| 418 |
|
sprintf( painCave.errMsg, |
| 419 |
|
"QuickKill didn't work right. n_active = %d, and nWaters = %d\n", |
| 420 |
|
n_active, nWaters ); |
| 424 |
|
|
| 425 |
|
// clean up our messes before building the final system. |
| 426 |
|
|
| 427 |
< |
for(i=0; i<nAtoms; i++){ |
| 428 |
< |
|
| 423 |
< |
delete atoms[i]; |
| 424 |
< |
} |
| 425 |
< |
Atom::destroyArrays(); |
| 426 |
< |
|
| 427 |
> |
simnfo[0].getConfiguration()->destroyArrays(); |
| 428 |
> |
simnfo[1].getConfiguration()->destroyArrays(); |
| 429 |
|
|
| 430 |
|
// create the real Atom arrays |
| 431 |
|
|
| 445 |
|
nAtoms += waterNatoms; |
| 446 |
|
} |
| 447 |
|
|
| 448 |
+ |
theConfig = simnfo[2].getConfiguration(); |
| 449 |
+ |
theConfig->createArrays( nAtoms ); |
| 450 |
+ |
simnfo[2].atoms = new Atom*[nAtoms]; |
| 451 |
+ |
atoms = simnfo[2].atoms; |
| 452 |
+ |
simnfo[2].n_atoms = nAtoms; |
| 453 |
|
|
| 447 |
– |
Atom::createArrays( nAtoms ); |
| 448 |
– |
atoms = new Atom*[nAtoms]; |
| 449 |
– |
|
| 450 |
– |
|
| 454 |
|
// initialize lipid positions |
| 455 |
|
|
| 456 |
|
molIndex = 0; |
| 457 |
|
for(i=0; i<nLipids; i++ ){ |
| 458 |
|
lipidLocate->placeMol( lipidSites[i].pos, lipidSites[i].rot, atoms, |
| 459 |
< |
molStart[molIndex] ); |
| 459 |
> |
molStart[molIndex], theConfig ); |
| 460 |
|
molIndex++; |
| 461 |
|
} |
| 462 |
|
|
| 463 |
|
// initialize the water positions |
| 464 |
|
|
| 465 |
|
for(i=0; i<newWaters; i++){ |
| 466 |
< |
|
| 466 |
> |
|
| 467 |
|
if( isActive[i] ){ |
| 468 |
< |
|
| 468 |
> |
|
| 469 |
|
getRandomRot( waterSites[i].rot ); |
| 470 |
|
waterLocate->placeMol( waterSites[i].pos, waterSites[i].rot, atoms, |
| 471 |
< |
molStart[molIndex] ); |
| 471 |
> |
molStart[molIndex], theConfig ); |
| 472 |
|
molIndex++; |
| 473 |
|
} |
| 474 |
|
} |
| 475 |
|
|
| 476 |
|
// set up the SimInfo object |
| 477 |
|
|
| 478 |
+ |
double Hmat[3][3]; |
| 479 |
+ |
|
| 480 |
+ |
Hmat[0][0] = box_x; |
| 481 |
+ |
Hmat[0][1] = 0.0; |
| 482 |
+ |
Hmat[0][2] = 0.0; |
| 483 |
+ |
|
| 484 |
+ |
Hmat[1][0] = 0.0; |
| 485 |
+ |
Hmat[1][1] = box_y; |
| 486 |
+ |
Hmat[1][2] = 0.0; |
| 487 |
+ |
|
| 488 |
+ |
Hmat[2][0] = 0.0; |
| 489 |
+ |
Hmat[2][1] = 0.0; |
| 490 |
+ |
Hmat[2][2] = box_z; |
| 491 |
+ |
|
| 492 |
+ |
|
| 493 |
|
bsInfo.boxX = box_x; |
| 494 |
|
bsInfo.boxY = box_y; |
| 495 |
|
bsInfo.boxZ = box_z; |
| 496 |
|
|
| 497 |
< |
double boxVector[3]; |
| 480 |
< |
|
| 481 |
< |
boxVector[0] = bsInfo.boxX; |
| 482 |
< |
boxVector[1] = bsInfo.boxY; |
| 483 |
< |
boxVector[2] = bsInfo.boxZ; |
| 484 |
< |
simnfo->setBox( boxVector ); |
| 497 |
> |
simnfo[2].setBoxM( Hmat ); |
| 498 |
|
|
| 499 |
< |
sprintf( simnfo->sampleName, "%s.dump", bsInfo.outPrefix ); |
| 500 |
< |
sprintf( simnfo->finalName, "%s.init", bsInfo.outPrefix ); |
| 499 |
> |
sprintf( simnfo[2].sampleName, "%s.dump", bsInfo.outPrefix ); |
| 500 |
> |
sprintf( simnfo[2].finalName, "%s.init", bsInfo.outPrefix ); |
| 501 |
|
|
| 489 |
– |
simnfo->atoms = atoms; |
| 490 |
– |
|
| 502 |
|
// set up the writer and write out |
| 503 |
|
|
| 504 |
< |
writer = new DumpWriter( simnfo ); |
| 504 |
> |
writer = new DumpWriter( &simnfo[2] ); |
| 505 |
|
writer->writeFinal( 0.0 ); |
| 495 |
– |
|
| 496 |
– |
// clean up the memory |
| 497 |
– |
|
| 498 |
– |
// if( molMap != NULL ) delete[] molMap; |
| 499 |
– |
// if( cardDeck != NULL ) delete[] cardDeck; |
| 500 |
– |
// if( locate != NULL ){ |
| 501 |
– |
// for(i=0; i<bsInfo.nComponents; i++){ |
| 502 |
– |
// delete locate[i]; |
| 503 |
– |
// } |
| 504 |
– |
// delete[] locate; |
| 505 |
– |
// } |
| 506 |
– |
// if( atoms != NULL ){ |
| 507 |
– |
// for(i=0; i<nAtoms; i++){ |
| 508 |
– |
// delete atoms[i]; |
| 509 |
– |
// } |
| 510 |
– |
// Atom::destroyArrays(); |
| 511 |
– |
// delete[] atoms; |
| 512 |
– |
// } |
| 513 |
– |
// if( molSeq != NULL ) delete[] molSeq; |
| 514 |
– |
// if( simnfo != NULL ) delete simnfo; |
| 515 |
– |
// if( writer != NULL ) delete writer; |
| 516 |
– |
|
| 517 |
– |
return 1; |
| 518 |
– |
} |
| 519 |
– |
|
| 520 |
– |
|
| 521 |
– |
|
| 522 |
– |
int Old_buildRandomBilayer( void ){ |
| 523 |
– |
|
| 524 |
– |
int i,j,k; |
| 525 |
– |
int nAtoms, atomIndex, molIndex, molID; |
| 526 |
– |
int* molSeq; |
| 527 |
– |
int* molMap; |
| 528 |
– |
int* molStart; |
| 529 |
– |
int* cardDeck; |
| 530 |
– |
int deckSize; |
| 531 |
– |
int rSite, rCard; |
| 532 |
– |
double cell; |
| 533 |
– |
int nCells, nSites, siteIndex; |
| 534 |
– |
double rot[3][3]; |
| 535 |
– |
double pos[3]; |
| 536 |
– |
|
| 537 |
– |
Atom** atoms; |
| 538 |
– |
SimInfo* simnfo; |
| 539 |
– |
DumpWriter* writer; |
| 540 |
– |
MoLocator** locate; |
| 541 |
– |
|
| 542 |
– |
// initialize functions and variables |
| 543 |
– |
|
| 544 |
– |
srand48( RAND_SEED ); |
| 545 |
– |
molSeq = NULL; |
| 546 |
– |
molStart = NULL; |
| 547 |
– |
molMap = NULL; |
| 548 |
– |
cardDeck = NULL; |
| 549 |
– |
atoms = NULL; |
| 550 |
– |
locate = NULL; |
| 551 |
– |
simnfo = NULL; |
| 552 |
– |
writer = NULL; |
| 553 |
– |
|
| 554 |
– |
// calculate the number of cells in the fcc box |
| 555 |
– |
|
| 556 |
– |
nCells = 0; |
| 557 |
– |
nSites = 0; |
| 558 |
– |
while( nSites < bsInfo.totNmol ){ |
| 559 |
– |
nCells++; |
| 560 |
– |
nSites = 4.0 * pow( (double)nCells, 3.0 ); |
| 561 |
– |
} |
| 562 |
– |
|
| 563 |
– |
|
| 564 |
– |
// create the molMap and cardDeck arrays |
| 565 |
– |
|
| 566 |
– |
molMap = new int[nSites]; |
| 567 |
– |
cardDeck = new int[nSites]; |
| 568 |
– |
|
| 569 |
– |
for(i=0; i<nSites; i++){ |
| 570 |
– |
molMap[i] = -1; |
| 571 |
– |
cardDeck[i] = i; |
| 572 |
– |
} |
| 573 |
– |
|
| 574 |
– |
// randomly place the molecules on the sites |
| 575 |
– |
|
| 576 |
– |
deckSize = nSites; |
| 577 |
– |
for(i=0; i<bsInfo.totNmol; i++){ |
| 578 |
– |
rCard = (int)( deckSize * drand48() ); |
| 579 |
– |
rSite = cardDeck[rCard]; |
| 580 |
– |
molMap[rSite] = i; |
| 581 |
– |
|
| 582 |
– |
// book keep the card deck; |
| 583 |
– |
|
| 584 |
– |
deckSize--; |
| 585 |
– |
cardDeck[rCard] = cardDeck[deckSize]; |
| 586 |
– |
} |
| 587 |
– |
|
| 588 |
– |
|
| 589 |
– |
// create the MoLocator and Atom arrays |
| 590 |
– |
|
| 591 |
– |
nAtoms = 0; |
| 592 |
– |
molIndex = 0; |
| 593 |
– |
locate = new MoLocator*[bsInfo.nComponents]; |
| 594 |
– |
molSeq = new int[bsInfo.totNmol]; |
| 595 |
– |
molStart = new int[bsInfo.totNmol]; |
| 596 |
– |
for(i=0; i<bsInfo.nComponents; i++){ |
| 597 |
– |
locate[i] = new MoLocator( bsInfo.compStamps[i] ); |
| 598 |
– |
for(j=0; j<bsInfo.componentsNmol[i]; j++){ |
| 599 |
– |
molSeq[molIndex] = i; |
| 600 |
– |
molStart[molIndex] = nAtoms; |
| 601 |
– |
molIndex++; |
| 602 |
– |
nAtoms += bsInfo.compStamps[i]->getNAtoms(); |
| 603 |
– |
} |
| 604 |
– |
} |
| 605 |
– |
|
| 606 |
– |
Atom::createArrays( nAtoms ); |
| 607 |
– |
atoms = new Atom*[nAtoms]; |
| 608 |
– |
|
| 609 |
– |
|
| 610 |
– |
// place the molecules at each FCC site |
| 611 |
– |
|
| 612 |
– |
cell = 5.0; |
| 613 |
– |
for(i=0; i<bsInfo.nComponents; i++){ |
| 614 |
– |
if(cell < locate[i]->getMaxLength() ) cell = locate[i]->getMaxLength(); |
| 615 |
– |
} |
| 616 |
– |
cell *= 1.2; // add a little buffer |
| 617 |
– |
|
| 618 |
– |
cell *= M_SQRT2; |
| 619 |
– |
|
| 620 |
– |
siteIndex = 0; |
| 621 |
– |
for(i=0; i<nCells; i++){ |
| 622 |
– |
for(j=0; j<nCells; j++){ |
| 623 |
– |
for(k=0; k<nCells; k++){ |
| 506 |
|
|
| 625 |
– |
if( molMap[siteIndex] >= 0 ){ |
| 626 |
– |
pos[0] = i * cell; |
| 627 |
– |
pos[1] = j * cell; |
| 628 |
– |
pos[2] = k * cell; |
| 629 |
– |
|
| 630 |
– |
getRandomRot( rot ); |
| 631 |
– |
molID = molSeq[molMap[siteIndex]]; |
| 632 |
– |
atomIndex = molStart[ molMap[siteIndex] ]; |
| 633 |
– |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
| 634 |
– |
} |
| 635 |
– |
siteIndex++; |
| 636 |
– |
|
| 637 |
– |
if( molMap[siteIndex] >= 0 ){ |
| 638 |
– |
pos[0] = i * cell + (0.5 * cell); |
| 639 |
– |
pos[1] = j * cell; |
| 640 |
– |
pos[2] = k * cell + (0.5 * cell); |
| 641 |
– |
|
| 642 |
– |
getRandomRot( rot ); |
| 643 |
– |
molID = molSeq[molMap[siteIndex]]; |
| 644 |
– |
atomIndex = molStart[ molMap[siteIndex] ]; |
| 645 |
– |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
| 646 |
– |
} |
| 647 |
– |
siteIndex++; |
| 648 |
– |
|
| 649 |
– |
if( molMap[siteIndex] >= 0 ){ |
| 650 |
– |
pos[0] = i * cell + (0.5 * cell); |
| 651 |
– |
pos[1] = j * cell + (0.5 * cell); |
| 652 |
– |
pos[2] = k * cell; |
| 653 |
– |
|
| 654 |
– |
getRandomRot( rot ); |
| 655 |
– |
molID = molSeq[molMap[siteIndex]]; |
| 656 |
– |
atomIndex = molStart[ molMap[siteIndex] ]; |
| 657 |
– |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
| 658 |
– |
} |
| 659 |
– |
siteIndex++; |
| 660 |
– |
|
| 661 |
– |
if( molMap[siteIndex] >= 0 ){ |
| 662 |
– |
pos[0] = i * cell; |
| 663 |
– |
pos[1] = j * cell + (0.5 * cell); |
| 664 |
– |
pos[2] = k * cell + (0.5 * cell); |
| 665 |
– |
|
| 666 |
– |
getRandomRot( rot ); |
| 667 |
– |
molID = molSeq[molMap[siteIndex]]; |
| 668 |
– |
atomIndex = molStart[ molMap[siteIndex] ]; |
| 669 |
– |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
| 670 |
– |
} |
| 671 |
– |
siteIndex++; |
| 672 |
– |
} |
| 673 |
– |
} |
| 674 |
– |
} |
| 675 |
– |
|
| 676 |
– |
// set up the SimInfo object |
| 677 |
– |
|
| 678 |
– |
bsInfo.boxX = nCells * cell; |
| 679 |
– |
bsInfo.boxY = nCells * cell; |
| 680 |
– |
bsInfo.boxZ = nCells * cell; |
| 681 |
– |
|
| 682 |
– |
double boxVector[3]; |
| 683 |
– |
simnfo = new SimInfo(); |
| 684 |
– |
simnfo->n_atoms = nAtoms; |
| 685 |
– |
boxVector[0] = bsInfo.boxX; |
| 686 |
– |
boxVector[1] = bsInfo.boxY; |
| 687 |
– |
boxVector[2] = bsInfo.boxZ; |
| 688 |
– |
simnfo->setBox( boxVector ); |
| 689 |
– |
|
| 690 |
– |
sprintf( simnfo->sampleName, "%s.dump", bsInfo.outPrefix ); |
| 691 |
– |
sprintf( simnfo->finalName, "%s.init", bsInfo.outPrefix ); |
| 692 |
– |
|
| 693 |
– |
simnfo->atoms = atoms; |
| 694 |
– |
|
| 695 |
– |
// set up the writer and write out |
| 696 |
– |
|
| 697 |
– |
writer = new DumpWriter( simnfo ); |
| 698 |
– |
writer->writeFinal(0.0); |
| 699 |
– |
|
| 507 |
|
// clean up the memory |
| 508 |
|
|
| 509 |
< |
if( molMap != NULL ) delete[] molMap; |
| 510 |
< |
if( cardDeck != NULL ) delete[] cardDeck; |
| 511 |
< |
if( locate != NULL ){ |
| 512 |
< |
for(i=0; i<bsInfo.nComponents; i++){ |
| 513 |
< |
delete locate[i]; |
| 514 |
< |
} |
| 515 |
< |
delete[] locate; |
| 516 |
< |
} |
| 517 |
< |
if( atoms != NULL ){ |
| 518 |
< |
for(i=0; i<nAtoms; i++){ |
| 519 |
< |
delete atoms[i]; |
| 520 |
< |
} |
| 521 |
< |
Atom::destroyArrays(); |
| 522 |
< |
delete[] atoms; |
| 523 |
< |
} |
| 524 |
< |
if( molSeq != NULL ) delete[] molSeq; |
| 525 |
< |
if( simnfo != NULL ) delete simnfo; |
| 526 |
< |
if( writer != NULL ) delete writer; |
| 509 |
> |
// if( molMap != NULL ) delete[] molMap; |
| 510 |
> |
// if( cardDeck != NULL ) delete[] cardDeck; |
| 511 |
> |
// if( locate != NULL ){ |
| 512 |
> |
// for(i=0; i<bsInfo.nComponents; i++){ |
| 513 |
> |
// delete locate[i]; |
| 514 |
> |
// } |
| 515 |
> |
// delete[] locate; |
| 516 |
> |
// } |
| 517 |
> |
// if( atoms != NULL ){ |
| 518 |
> |
// for(i=0; i<nAtoms; i++){ |
| 519 |
> |
// delete atoms[i]; |
| 520 |
> |
// } |
| 521 |
> |
// Atom::destroyArrays(); |
| 522 |
> |
// delete[] atoms; |
| 523 |
> |
// } |
| 524 |
> |
// if( molSeq != NULL ) delete[] molSeq; |
| 525 |
> |
// if( simnfo != NULL ) delete simnfo; |
| 526 |
> |
// if( writer != NULL ) delete writer; |
| 527 |
|
|
| 528 |
|
return 1; |
| 529 |
|
} |
| 530 |
|
|
| 724 |
– |
|
| 531 |
|
void getRandomRot( double rot[3][3] ){ |
| 532 |
|
|
| 533 |
|
double theta, phi, psi; |
| 557 |
|
|
| 558 |
|
|
| 559 |
|
void buildMap( double &x, double &y, double &z, |
| 560 |
< |
double boxX, double boxY, double boxZ ){ |
| 560 |
> |
double boxX, double boxY, double boxZ ){ |
| 561 |
|
|
| 562 |
|
if(x < 0) x -= boxX * (double)( (int)( (x / boxX) - 0.5 ) ); |
| 563 |
|
else x -= boxX * (double)( (int)( (x / boxX ) + 0.5)); |