ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/utils/sysbuilder/bilayerSys.cpp
(Generate patch)

Comparing trunk/OOPSE/utils/sysbuilder/bilayerSys.cpp (file contents):
Revision 678 by chuckv, Mon Aug 11 22:12:31 2003 UTC vs.
Revision 821 by mmeineke, Fri Oct 24 22:17:45 2003 UTC

# Line 1 | Line 1
1 +
2   #include <iostream>
3 + #include <vector>
4 + #include <algorithm>
5  
6   #include <cstdlib>
7   #include <cstring>
8   #include <cmath>
9  
10 +
11   #include "simError.h"
12   #include "SimInfo.hpp"
13   #include "ReadWrite.hpp"
# Line 12 | Line 16
16   #include "sysBuild.hpp"
17   #include "bilayerSys.hpp"
18  
19 + #include "latticeBuilder.hpp"
20  
21 + class SortCond{
22 +  
23 + public:
24 +  bool operator()(const pair<int, double>& p1, const pair<int, double>& p2){
25 +    return p1.second < p2.second;
26 +  }
27 +  
28 +  
29 + };
30  
31 +
32   void buildMap( double &x, double &y, double &z,
33 <          double boxX, double boxY, double boxZ );
33 >               double boxX, double boxY, double boxZ );
34  
35   int buildRandomBilayer( void );
36  
22 void getRandomRot( double rot[3][3] );
23
37   int buildBilayer( int isRandom ){
38    
39    if( isRandom ){
40      return buildRandomBilayer();
41    }
42    else{
43 <    sprintf( painCave.errMsg,
44 <             "Cannot currently create a non-random bilayer.\n" );
32 <    painCave.isFatal = 1;
33 <    simError();
43 >
44 >    std::cerr << "unsupported feature\n";
45      return 0;
46    }
47   }
# Line 44 | Line 55 | int buildRandomBilayer( void ){
55    } coord;
56  
57  
58 +
59    const double waterRho = 0.0334; // number density per cubic angstrom
60    const double waterVol = 4.0 / waterRho; // volume occupied by 4 waters
61    const double waterCell = 4.929; // fcc unit cell length
62  
63 +  Lattice myFCC( FCC_LATTICE_TYPE, waterCell );
64 +  double *posX, *posY, *posZ;
65 +  double pos[3], posA[3], posB[3];
66 +
67    const double water_padding = 6.0;
68    const double lipid_spaceing = 8.0;
69  
70  
71 <  int i,j,k, l;
71 >  int i,j,k, l, m;
72    int nAtoms, atomIndex, molIndex, molID;
73    int* molSeq;
74    int* molMap;
# Line 67 | Line 83 | int buildRandomBilayer( void ){
83  
84    Atom** atoms;
85    SimInfo* simnfo;
86 +  SimState* theConfig;
87    DumpWriter* writer;
88  
89    MoleculeStamp* lipidStamp;
# Line 91 | Line 108 | int buildRandomBilayer( void ){
108    foundWater = 0;
109    for(i=0; i<bsInfo.nComponents; i++){
110      if( !strcmp( bsInfo.compStamps[i]->getID(), bsInfo.lipidName ) ){
111 <      
111 >          
112        foundLipid = 1;
113        lipidStamp = bsInfo.compStamps[i];
114        nLipids = bsInfo.componentsNmol[i];
115      }
116      if( !strcmp( bsInfo.compStamps[i]->getID(), bsInfo.waterName ) ){
117 <      
117 >          
118        foundWater = 1;
119 <      
119 >          
120        waterStamp = bsInfo.compStamps[i];
121        nWaters = bsInfo.componentsNmol[i];
122      }
# Line 112 | Line 129 | int buildRandomBilayer( void ){
129      simError();
130    }
131    if( !foundWater ){
132 <        sprintf(painCave.errMsg,
133 <                "Could not find solvent \"%s\" in the bass file.\n",
132 >    sprintf(painCave.errMsg,
133 >            "Could not find solvent \"%s\" in the bass file.\n",
134              bsInfo.waterName );
135      painCave.isFatal = 1;
136      simError();
# Line 128 | Line 145 | int buildRandomBilayer( void ){
145    waterLocate = new MoLocator( waterStamp );
146    waterNatoms = waterStamp->getNAtoms();
147    
148 <  nAtoms = nLipids * lipidNatoms;
148 >  nAtoms = lipidNatoms;
149  
150 < simnfo[0].n_atoms = nAtoms;
151 < simnfo[0].atoms=new Atom*[nAtoms];
150 >  simnfo[0].n_atoms = nAtoms;
151 >  simnfo[0].atoms=new Atom*[nAtoms];
152  
153 < (simnfo[0]->getConfiguration())->createArrays( simnfo[0].n_atoms );
154 < for(i=0; i<simnfo[0].n_atoms; i++) simnfo[0].atoms[i]->setCoords();
153 >  theConfig = simnfo[0].getConfiguration();
154 >  theConfig->createArrays( simnfo[0].n_atoms );
155  
156 < atoms=simnfo[0].atoms;
156 >  atoms=simnfo[0].atoms;
157          
158  
159    // create the test box for initial water displacement
# Line 160 | Line 177 | int buildRandomBilayer( void ){
177    for( i=0; i < nCells; i++ ){
178      for( j=0; j < nCells; j++ ){
179        for( k=0; k < nCells; k++ ){
180 <        
181 <        waterX[ndx] = i * waterCell + x0;
182 <        waterY[ndx] = j * waterCell + y0;
183 <        waterZ[ndx] = k * waterCell + z0;
184 <        ndx++;
185 <        
186 <        waterX[ndx] = i * waterCell + 0.5 * waterCell + x0;
187 <        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++;
180 >
181 >        myFCC.getLatticePoints(&posX, &posY, &posZ, i, j, k);
182 >        for(l=0; l<4; l++){
183 >          waterX[ndx]=posX[l];
184 >          waterY[ndx]=posY[l];
185 >          waterZ[ndx]=posZ[l];
186 >          ndx++;
187 >        }
188        }
189      }
190    }
# Line 202 | Line 207 | int buildRandomBilayer( void ){
207    testSite.pos[1] = 0.0;
208    testSite.pos[2] = 0.0;
209  
210 <  lipidLocate->placeMol( testSite.pos, testSite.rot, atoms, 0 );
210 >  lipidLocate->placeMol( testSite.pos, testSite.rot, atoms, 0, theConfig );
211  
212    int *isActive = new int[testWaters];
213    for(i=0; i<testWaters; i++) isActive[i] = 1;
# Line 214 | Line 219 | int buildRandomBilayer( void ){
219    
220    for(i=0; ( (i<testWaters) && isActive[i] ); i++){
221      for(j=0; ( (j<lipidNatoms) && isActive[i] ); j++){
222 +      
223 +      atoms[j]->getPos( pos );
224  
225 <      dx = waterX[i] - atoms[j]->getX();
226 <      dy = waterY[i] - atoms[j]->getY();
227 <      dz = waterZ[i] - atoms[j]->getZ();
225 >      dx = waterX[i] - pos[0];
226 >      dy = waterY[i] - pos[1];
227 >      dz = waterZ[i] - pos[2];
228  
229        buildMap( dx, dy, dz, testBox, testBox, testBox );
230  
231        dx2 = dx * dx;
232        dy2 = dy * dy;
233        dz2 = dz * dz;
234 <      
234 >          
235        dSqr = dx2 + dy2 + dz2;
236        if( dSqr < rCutSqr ){
237          isActive[i] = 0;
# Line 239 | Line 246 | int buildRandomBilayer( void ){
246  
247    // find the best box size for the sim
248  
249 +  int nCellsX, nCellsY, nCellsZ;
250 +
251 +  const double boxTargetX = 66.22752;
252 +  const double boxTargetY = 60.53088;
253 +
254 +  nCellsX = (int)ceil(boxTargetX / waterCell);
255 +  nCellsY = (int)ceil(boxTargetY / waterCell);
256 +  
257    int testTot;
258    int done = 0;
259 <  ndx = 0;
259 >  nCellsZ = 0;
260    while( !done ){
261 <    
262 <    ndx++;
263 <    testTot = 4 * ndx * ndx * ndx;
264 <    
261 >        
262 >    nCellsZ++;
263 >    testTot = 4 * nCellsX * nCellsY * nCellsZ;
264 >        
265      if( testTot >= targetWaters ) done = 1;
266    }
267  
253  nCells = ndx;
254    
255    
268    // create the new water box to the new specifications
269    
270 <  int newWaters = nCells * nCells * nCells * 4;
270 >  int newWaters = nCellsX * nCellsY * nCellsZ * 4;
271    
272    delete[] waterX;
273    delete[] waterY;
# Line 263 | Line 275 | int buildRandomBilayer( void ){
275    
276    coord* waterSites = new coord[newWaters];
277    
278 <  double box_x = waterCell * nCells;
279 <  double box_y = waterCell * nCells;
280 <  double box_z = waterCell * nCells;
281 <    
278 >  double box_x = waterCell * nCellsX;
279 >  double box_y = waterCell * nCellsY;
280 >  double box_z = waterCell * nCellsZ;
281 >        
282    // create an fcc lattice in the water box.
283    
284    ndx = 0;
285 <  for( i=0; i < nCells; i++ ){
286 <    for( j=0; j < nCells; j++ ){
287 <      for( k=0; k < nCells; k++ ){
288 <        
289 <        waterSites[ndx].pos[0] = i * waterCell;
290 <        waterSites[ndx].pos[1] = j * waterCell;
291 <        waterSites[ndx].pos[2] = k * waterCell;
292 <        ndx++;
293 <        
294 <        waterSites[ndx].pos[0] = i * waterCell + 0.5 * waterCell;
295 <        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++;
285 >  for( i=0; i < nCellsX; i++ ){
286 >    for( j=0; j < nCellsY; j++ ){
287 >      for( k=0; k < nCellsZ; k++ ){
288 >
289 >        myFCC.getLatticePoints(&posX, &posY, &posZ, i, j, k);
290 >        for(l=0; l<4; l++){
291 >          waterSites[ndx].pos[0] = posX[l];
292 >          waterSites[ndx].pos[1] = posY[l];
293 >          waterSites[ndx].pos[2] = posZ[l];
294 >          ndx++;
295 >        }
296        }
297      }
298    }  
# Line 305 | Line 305 | int buildRandomBilayer( void ){
305    int reject;
306    int testDX, acceptedDX;
307  
308 +  nAtoms = nLipids * lipidNatoms;
309 +
310 +  simnfo[1].n_atoms = nAtoms;
311 +  simnfo[1].atoms=new Atom*[nAtoms];
312 +
313 +  theConfig = simnfo[1].getConfiguration();
314 +  theConfig->createArrays( simnfo[1].n_atoms );
315 +
316 +  atoms=simnfo[1].atoms;
317 +
318    rCutSqr = lipid_spaceing * lipid_spaceing;
319  
320    for(i=0; i<nLipids; i++ ){
321      done = 0;
322      while( !done ){
323 <      
323 >          
324        lipidSites[i].pos[0] = drand48() * box_x;
325        lipidSites[i].pos[1] = drand48() * box_y;
326        lipidSites[i].pos[2] = drand48() * box_z;
327 <      
327 >          
328        getRandomRot( lipidSites[i].rot );
329 <      
329 >          
330        ndx = i * lipidNatoms;
331  
332        lipidLocate->placeMol( lipidSites[i].pos, lipidSites[i].rot, atoms,
333 <                             ndx );
334 <      
333 >                             ndx, theConfig );
334 >          
335        reject = 0;
336        for( j=0; !reject && j<i; j++){
337          for(k=0; !reject && k<lipidNatoms; k++){
338            
339            acceptedDX = j*lipidNatoms + k;
340            for(l=0; !reject && l<lipidNatoms; l++){
341 <            
341 >                
342              testDX = ndx + l;
343  
344 <            dx = atoms[testDX]->getX() - atoms[acceptedDX]->getX();
345 <            dy = atoms[testDX]->getY() - atoms[acceptedDX]->getY();
336 <            dz = atoms[testDX]->getZ() - atoms[acceptedDX]->getZ();
344 >            atoms[testDX]->getPos( posA );
345 >            atoms[acceptedDX]->getPos( posB );
346              
347 +            dx = posA[0] - posB[0];
348 +            dy = posA[1] - posB[1];
349 +            dz = posA[2] - posB[2];
350 +                
351              buildMap( dx, dy, dz, box_x, box_y, box_z );
352 <            
352 >                
353              dx2 = dx * dx;
354              dy2 = dy * dy;
355              dz2 = dz * dz;
356 <            
356 >                
357              dSqr = dx2 + dy2 + dz2;
358              if( dSqr < rCutSqr ) reject = 1;
359            }
# Line 353 | Line 366 | int buildRandomBilayer( void ){
366        }
367        else{
368          done = 1;
369 <        std::cout << i << " has been accepted\n";
369 >        std::cout << (i+1) << " has been accepted\n";
370        }
371      }
372    }
373          
374 +
375 +  // zSort of the lipid positions
376 +
377 +
378 +  vector< pair<int,double> >zSortArray;
379 +  for(i=0;i<nLipids;i++)
380 +    zSortArray.push_back( make_pair(i, lipidSites[i].pos[2]) );
381 +
382 +  sort(zSortArray.begin(),zSortArray.end(),SortCond());
383 +
384 +  ofstream outFile( "./zipper.bass", ios::app);
385 +
386 +  for(i=0; i<nLipids; i++){
387 +    outFile << "zConstraint[" << i << "]{\n"
388 +            << "  molIndex = " << zSortArray[i].first <<  ";\n"
389 +            << "  zPos = ";
390 +
391 +    if(i<32) outFile << "60.0;\n";
392 +    else outFile << "100.0;\n";
393 +
394 +    outFile << "  kRatio = 0.5;\n"
395 +            << "}\n";
396 +  }
397 +  
398 +  outFile.close();
399 +
400 +
401    // cut out the waters that overlap with the lipids.
402    
403 +
404    delete[] isActive;
405    isActive = new int[newWaters];
406    for(i=0; i<newWaters; i++) isActive[i] = 1;
# Line 369 | Line 410 | int buildRandomBilayer( void ){
410    for(i=0; ( (i<newWaters) && isActive[i] ); i++){
411      for(j=0; ( (j<nAtoms) && isActive[i] ); j++){
412  
413 <      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();
413 >      atoms[j]->getPos( pos );
414  
415 +      dx = waterSites[i].pos[0] - pos[0];
416 +      dy = waterSites[i].pos[1] - pos[1];
417 +      dz = waterSites[i].pos[2] - pos[2];
418 +
419        buildMap( dx, dy, dz, box_x, box_y, box_z );
420  
421        dx2 = dx * dx;
422        dy2 = dy * dy;
423        dz2 = dz * dz;
424 <      
424 >          
425        dSqr = dx2 + dy2 + dz2;
426        if( dSqr < rCutSqr ){
427          isActive[i] = 0;
428          n_active--;
429 +
430 +
431        }
432      }
433    }
434  
435 +
436 +
437 +
438    if( n_active < nWaters ){
439 <    
439 >        
440      sprintf( painCave.errMsg,
441               "Too many waters were removed, edit code and try again.\n" );
442 <    
442 >        
443      painCave.isFatal = 1;
444      simError();
445    }
# Line 404 | Line 452 | int buildRandomBilayer( void ){
452      if( isActive[quickKill] ){
453        isActive[quickKill] = 0;
454        n_active--;
455 +
456      }
457    }
458  
459    if( n_active != nWaters ){
460 <    
460 >        
461      sprintf( painCave.errMsg,
462               "QuickKill didn't work right. n_active = %d, and nWaters = %d\n",
463               n_active, nWaters );
# Line 418 | Line 467 | int buildRandomBilayer( void ){
467  
468    // clean up our messes before building the final system.
469  
470 <  for(i=0; i<nAtoms; i++){
471 <    
423 <    delete atoms[i];
424 <  }
425 <  Atom::destroyArrays();
426 <  
470 >  simnfo[0].getConfiguration()->destroyArrays();
471 >  simnfo[1].getConfiguration()->destroyArrays();
472  
473    // create the real Atom arrays
474    
# Line 443 | Line 488 | int buildRandomBilayer( void ){
488      nAtoms += waterNatoms;
489    }
490    
491 +  theConfig = simnfo[2].getConfiguration();
492 +  theConfig->createArrays( nAtoms );
493 +  simnfo[2].atoms = new Atom*[nAtoms];
494 +  atoms = simnfo[2].atoms;
495 +  simnfo[2].n_atoms = nAtoms;
496    
447  Atom::createArrays( nAtoms );
448  atoms = new Atom*[nAtoms];
449
450  
497    // initialize lipid positions
498  
499    molIndex = 0;
500    for(i=0; i<nLipids; i++ ){
501      lipidLocate->placeMol( lipidSites[i].pos, lipidSites[i].rot, atoms,
502 <                           molStart[molIndex] );
502 >                           molStart[molIndex], theConfig );
503      molIndex++;
504    }
505  
506    // initialize the water positions
507  
508    for(i=0; i<newWaters; i++){
509 <    
509 >        
510      if( isActive[i] ){
511 <      
511 >          
512        getRandomRot( waterSites[i].rot );
513        waterLocate->placeMol( waterSites[i].pos, waterSites[i].rot, atoms,
514 <                             molStart[molIndex] );
514 >                             molStart[molIndex], theConfig );
515        molIndex++;
516      }
517    }  
518  
519    // set up the SimInfo object
520    
521 +  double Hmat[3][3];
522 +
523 +  Hmat[0][0] = box_x;
524 +  Hmat[0][1] = 0.0;
525 +  Hmat[0][2] = 0.0;
526 +
527 +  Hmat[1][0] = 0.0;
528 +  Hmat[1][1] = box_y;
529 +  Hmat[1][2] = 0.0;
530 +
531 +  Hmat[2][0] = 0.0;
532 +  Hmat[2][1] = 0.0;
533 +  Hmat[2][2] = box_z;
534 +  
535 +
536    bsInfo.boxX = box_x;
537    bsInfo.boxY = box_y;
538    bsInfo.boxZ = box_z;
539    
540 <  double boxVector[3];
480 <
481 <  boxVector[0] = bsInfo.boxX;
482 <  boxVector[1] = bsInfo.boxY;
483 <  boxVector[2] = bsInfo.boxZ;
484 <  simnfo->setBox( boxVector );
540 >  simnfo[2].setBoxM( Hmat );
541  
542 <  sprintf( simnfo->sampleName, "%s.dump", bsInfo.outPrefix );
543 <  sprintf( simnfo->finalName, "%s.init", bsInfo.outPrefix );
542 >  sprintf( simnfo[2].sampleName, "%s.dump", bsInfo.outPrefix );
543 >  sprintf( simnfo[2].finalName, "%s.init", bsInfo.outPrefix );
544  
489  simnfo->atoms = atoms;
490  
545    // set up the writer and write out
546    
547 <  writer = new DumpWriter( simnfo );
547 >  writer = new DumpWriter( &simnfo[2] );
548    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++){
549          
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    
550    // clean up the memory
551    
552 <  if( molMap != NULL )   delete[] molMap;
553 <  if( cardDeck != NULL ) delete[] cardDeck;
554 <  if( locate != NULL ){
555 <    for(i=0; i<bsInfo.nComponents; i++){
556 <      delete locate[i];
557 <    }
558 <    delete[] locate;
559 <  }
560 <  if( atoms != NULL ){
561 <    for(i=0; i<nAtoms; i++){
562 <      delete atoms[i];
563 <    }
564 <    Atom::destroyArrays();
565 <    delete[] atoms;
566 <  }
567 <  if( molSeq != NULL ) delete[] molSeq;
568 <  if( simnfo != NULL ) delete simnfo;
569 <  if( writer != NULL ) delete writer;
552 >  //     if( molMap != NULL )   delete[] molMap;
553 >  //     if( cardDeck != NULL ) delete[] cardDeck;
554 >  //     if( locate != NULL ){
555 >  //       for(i=0; i<bsInfo.nComponents; i++){
556 >  //             delete locate[i];
557 >  //       }
558 >  //       delete[] locate;
559 >  //     }
560 >  //     if( atoms != NULL ){
561 >  //       for(i=0; i<nAtoms; i++){
562 >  //             delete atoms[i];
563 >  //       }
564 >  //       Atom::destroyArrays();
565 >  //       delete[] atoms;
566 >  //     }
567 >  //     if( molSeq != NULL ) delete[] molSeq;
568 >  //     if( simnfo != NULL ) delete simnfo;
569 >  //     if( writer != NULL ) delete writer;
570  
571    return 1;
572   }
573  
724
725 void getRandomRot( double rot[3][3] ){
726
727  double theta, phi, psi;
728  double cosTheta;
729
730  // select random phi, psi, and cosTheta
731
732  phi = 2.0 * M_PI * drand48();
733  psi = 2.0 * M_PI * drand48();
734  cosTheta = (2.0 * drand48()) - 1.0; // sample cos -1 to 1
735
736  theta = acos( cosTheta );
737
738  rot[0][0] = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi));
739  rot[0][1] = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi));
740  rot[0][2] = sin(theta) * sin(psi);
741  
742  rot[1][0] = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi));
743  rot[1][1] = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi));
744  rot[1][2] = sin(theta) * cos(psi);
745
746  rot[2][0] = sin(phi) * sin(theta);
747  rot[2][1] = -cos(phi) * sin(theta);
748  rot[2][2] = cos(theta);  
749 }
750                        
751
752
574   void buildMap( double &x, double &y, double &z,
575 <          double boxX, double boxY, double boxZ ){
575 >               double boxX, double boxY, double boxZ ){
576    
577    if(x < 0) x -= boxX * (double)( (int)( (x / boxX)  - 0.5 ) );
578    else x -= boxX * (double)( (int)( (x / boxX ) + 0.5));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines