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

Comparing trunk/OOPSE/utils/bilayerSys.cpp (file contents):
Revision 498 by mmeineke, Mon Apr 14 21:22:54 2003 UTC vs.
Revision 501 by mmeineke, Tue Apr 15 21:20:35 2003 UTC

# Line 3 | Line 3
3   #include <cmath>
4  
5   #include "simError.h"
6 #include "parse_me.h"
7 #include "MakeStamps.hpp"
8 #include "Globals.hpp"
6   #include "SimInfo.hpp"
7   #include "ReadWrite.hpp"
8  
9 <
9 > #include "MoLocator.hpp"
10   #include "sysBuild.hpp"
11   #include "bilayerSys.hpp"
12  
13  
14 < // this routine is defined in BASS_interface.cpp
18 < extern void set_interface_stamps( MakeStamps* ms, Globals* g );
14 > int buildRandomBilayer( void );
15  
16 < void buildRandomBilayer( sysBuildInfo info );
16 > void getRandomRot( double rot[3][3] );
17  
18 <
23 < void buildBilayer( sysBuildInfo info ){
18 > int buildBilayer( int isRandom ){
19    
20 <  if( info.isRandom ){
21 <    buildRandomBilayer( info );
20 >  if( isRandom ){
21 >    return buildRandomBilayer();
22    }
23    else{
29
24      sprintf( painCave.errMsg,
25               "Cannot currently create a non-random bilayer.\n" );
26      painCave.isFatal = 1;
27      simError();
28 +    return 0;
29    }
30   }
31  
32  
33  
34 < void buildRandomBilayer( sysBuildInfo info ){
34 > int buildRandomBilayer( void ){
35  
36 <  MakeStamps* the_stamps;
37 <  Globals* the_globals;
36 >  int i,j,k;
37 >  int nAtoms, atomIndex;
38 >  int* molSeq;
39 >  int* molMap;
40 >  int* cardDeck;
41 >  int deckSize;
42 >  int rSite, rCard;
43 >  double cell;
44 >  int nCells, nSites, siteIndex;
45 >  double rot[3][3];
46 >  double pos[3];
47 >
48 >  Atom** atoms;
49    SimInfo* simnfo;
50 <  bwMolLinked bwInfo;
50 >  DumpWriter* writer;
51 >  MoLocator** locate;
52 >
53 >  // initialize functions and variables
54    
55 <  // init the bwInfo
55 >  srand48( RAND_SEED );
56 >  molSeq = NULL;
57 >  molMap = NULL;
58 >  cardDeck = NULL;
59 >  atoms = NULL;
60 >  locate = NULL;
61 >  simnfo = NULL;
62 >  writer = NULL;
63 >
64 >  // calculate the number of cells in the fcc box
65 >
66 >  nCells = 0;
67 >  nSites = 0;
68 >  while( nSites < bsInfo.totNmol ){
69 >    nCells++;
70 >    nSites = 4 * pow( nCells, 3 );
71 >  }
72 >
73 >
74 >  // create the molMap and cardDeck arrays
75    
76 <  bwinfo.components = NULL;
76 >  molMap = new int[nSites];
77 >  cardDeck = new int[nSites];
78    
79 <  bwInfo.havePressure = 0;
80 <  bwInfo.haveTauBarrostat = 0;
81 <  bwInfo.haveTauTemp = 0;
82 <  bwInfo.haveQmass = 0;
79 >  for(i=0; i<nSites; i++){
80 >    molMap[i] = -1;
81 >    cardDeck[i] = i;
82 >  }
83 >
84 >  // randomly place the molecules on the sites
85    
86 +  deckSize = nSites;
87 +  for(i=0; i<bsInfo.totNmol; i++){
88 +    rCard = (int)( deckSize * drand48() );
89 +    rSite = cardDeck[rCard];
90 +    molMap[rSite] = i;
91 +
92 +    // book keep the card deck;
93 +    
94 +    deckSize--;
95 +    cardDeck[rCard] = cardDeck[deckSize];
96 +  }
97    
56  // create parser and read the Bas file
98    
99 <  simnfo = new SimInfo();
100 <  the_stamps = new MakeStamps();
101 <  the_globals = new Globals();
102 <  set_interface_stamps( the_stamps, the_globals );
99 >  // create the MoLocator and Atom arrays
100 >  
101 >  nAtoms = 0;
102 >  molIndex = 0;
103 >  locate = new MoLocator*[bsInfo.nComponents];
104 >  molSeq = new int[bsInfo.totNmol];
105 >  for(i=0; i<bsInfo.nComponents; i++){
106 >    locate[i] = new MoLocator( bsInfo.compStamps[i] );
107 >    for(j=0; j<bsInfo.componentsNmol[i]; j++){
108 >      molSeq[molIndex] = i;
109 >      molIndex++;
110 >      nAtoms += bsInfo.compStamp[i]->getNAtoms();
111 >    }
112 >  }
113 >  
114 >  Atom::createArrays( nAtoms );
115 >  atoms = new Atom*[nAtoms];
116 >  
117 >  
118 >  // place the molecules at each FCC site
119 >  
120 >  cell = 5.0;
121 >  for(i=0; i<bsInfo.nComponents; i++){
122 >    if(cell < locate[i]->getMaxLength() ) cell = locate[i]->getMaxLength();
123 >  }
124 >  cell *= M_SQRT_2;
125  
126 <  yacc_BASS( info.in_name );  
126 >  siteIndex = 0;
127 >  atomIndex = 0;
128 >  for(i=0; i<nCells; i++){
129 >    for(j=0; j<nCells; j++){
130 >      for(k=0; k<nCells; k++){
131 >        
132 >        if( molMap[siteIndex] >= 0 ){
133 >          pos[0] = i * cell;
134 >          pos[1] = j * cell;
135 >          pos[2] = k * cell;
136 >          
137 >          getRandomRot( rot );
138 >          molID = molSeq[molMap[siteIndex]];
139 >          locate[molID]->placeMol( pos, rot, &atoms[atomIndex] );
140 >          
141 >          atomIndex += bsInfo.compStamps[molID]->getNatoms();
142 >        }
143 >        siteIndex++;
144  
145 +        if( molMap[siteIndex] >= 0 ){
146 +          pos[0] = i * cell + (0.5 * cell);
147 +          pos[1] = j * cell;
148 +          pos[2] = k * cell + (0.5 * cell);
149 +          
150 +          getRandomRot( rot );
151 +          molID = molSeq[molMap[siteIndex]];
152 +          locate[molID]->placeMol( pos, rot, &atoms[atomIndex] );
153 +          
154 +          atomIndex += bsInfo.compStamps[molID]->getNatoms();
155 +        }
156 +        siteIndex++;
157  
158 +        if( molMap[siteIndex] >= 0 ){
159 +          pos[0] = i * cell + (0.5 * cell);
160 +          pos[1] = j * cell + (0.5 * cell);
161 +          pos[2] = k * cell;
162 +          
163 +          getRandomRot( rot );
164 +          molID = molSeq[molMap[siteIndex]];
165 +          locate[molID]->placeMol( pos, rot, &atoms[atomIndex] );
166 +          
167 +          atomIndex += bsInfo.compStamps[molID]->getNatoms();
168 +        }
169 +        siteIndex++;
170  
171 <  // set the easy ones first
172 <  bwInfo.targetTemp = the_globals->getTargetTemp();
173 <  bwInfo.dt = the_globals->getDt();
174 <  bwInfo.runTime = the_globals->getRunTime();
171 >        if( molMap[siteIndex] >= 0 ){
172 >          pos[0] = i * cell;
173 >          pos[1] = j * cell + (0.5 * cell);
174 >          pos[2] = k * cell + (0.5 * cell);
175 >          
176 >          getRandomRot( rot );
177 >          molID = molSeq[molMap[siteIndex]];
178 >          locate[molID]->placeMol( pos, rot, &atoms[atomIndex] );
179 >          
180 >          atomIndex += bsInfo.compStamps[molID]->getNatoms();
181 >        }
182 >        siteIndex++;
183 >      }
184 >    }
185 >  }
186  
187 <  // get the ones we know are there, yet still may need some work.
188 <  bwInfo.nComponents = the_globals->getNComponents();
189 <  strcpy( bwInfo.forceField, the_globals->getForceField() );
190 <
191 <  // get the ensemble:
192 <  strcpy( bwInfo.ensemble, the_globals->getEnsemble() );
193 <  if( !strcasecmp( bwInfo.ensemble, "NPT" ) ) {
187 >  // set up the SimInfo object
188 >  
189 >  bsInfo.boxX = nCells * cell;
190 >  bsInfo.boxY = nCells * cell;
191 >  bsInfo.boxZ = nCells * cell;
192 >  
193 >  simnfo = new SimInfo();
194 >  simnfo.n_atoms = nAtoms;
195 >  simnfo.box_x = bsInfo.boxX;
196 >  simnfo.box_y = bsInfo.boxY;
197 >  simnfo.box_z = bsInfo.boxZ;
198 >  
199 >  sprintf( simnfo.statusName, "%s.dump", bsInfo.outPrefix );
200 >  sprintf( simnfo.finalName, "%s.init", bsInfo.outPrefix );
201 >  
202 >  simnfo.atoms = atoms;
203 >  
204 >  // set up the writer and write out
205 >  
206 >  writer = new DumpWriter( &simnfo );
207 >  writer->writeFinal();
208      
209 <    if (the_globals->haveTargetPressure()){
210 <      bwInfo.targetPressure = the_globals->getTargetPressure();
211 <      bwInfo.havePressure = 1;
209 >  // clean up the memory
210 >  
211 >  if( molMap != NULL )   delete[] molMap;
212 >  if( cardDeck != NULL ) delete[] cardDeck;
213 >  if( locate != NULL ){
214 >    for(i=0; i<bsInfo.nComponents; i++){
215 >      delete locate[i];
216      }
217 <    else {
218 <      sprintf( painCave.errMsg,
219 <               "buildBilayer error: If you use the constant pressure\n"
220 <               "    ensemble, you must set targetPressure.\n"
221 <               "    This was found in the BASS file.\n");
89 <      painCave.isFatal = 1;
90 <      simError();
217 >    delete[] locate;
218 >  }
219 >  if( atoms != NULL ){
220 >    for(i=0; i<nAtoms; i++){
221 >      delete atoms[i];
222      }
223 +    Atom::destroyArrays();
224 +    delete[] atoms;
225 +  }
226 +  if( molSeq != NULL ) delete[] molSeq;
227 +  if( simnfo != NULL ) delete simnfo;
228 +  if( writer != NULL ) delete writer;
229  
230 <    if (the_globals->haveTauThermostat()){
231 <      bwInfo.tauThermostat = the_globals->getTauThermostat();
95 <      bwInfo.haveTauThermostat = 1;;
96 <    }
97 <    else if (the_globals->haveQmass()){
98 <      bwinfo.Qmass = the_globals->getQmass();
99 <      bwInfo.haveQmass = 1;
100 <    }
101 <    else {
102 <      sprintf( painCave.errMsg,
103 <               "buildBilayer error: If you use one of the constant temperature\n"
104 <               "    ensembles, you must set either tauThermostat or qMass.\n"
105 <               "    Neither of these was found in the BASS file.\n");
106 <      painCave.isFatal = 1;
107 <      simError();
108 <    }
230 >  return 1;
231 > }
232  
110    if (the_globals->haveTauBarostat()){
111      bwInfo.tauBarostat = the_globals->getTauBarostat();
112      bwInfo.haveTauBarostat = 1;
113    }                                    
114    else {
115      sprintf( painCave.errMsg,
116               "SimSetup error: If you use the constant pressure\n"
117               "    ensemble, you must set tauBarostat.\n"
118               "    This was found in the BASS file.\n");
119      painCave.isFatal = 1;
120      simError();
121    }
233  
234 <  } else if ( !strcasecmp( ensemble, "NVT") ) {
124 <    the_extendedsystem = new ExtendedSystem( simnfo );
125 <    the_extendedsystem->setTargetTemp(the_globals->getTargetTemp());
234 > void getRandomRot( double rot[3][3] ){
235  
236 <    if (the_globals->haveTauThermostat())
237 <      the_extendedsystem->setTauThermostat(the_globals->getTauThermostat());
129 <    else if (the_globals->haveQmass())
130 <      the_extendedsystem->setQmass(the_globals->getQmass());
131 <    else {
132 <      sprintf( painCave.errMsg,
133 <               "SimSetup error: If you use one of the constant temperature\n"
134 <               "    ensembles, you must set either tauThermostat or qMass.\n"
135 <               "    Neither of these was found in the BASS file.\n");
136 <      painCave.isFatal = 1;
137 <      simError();
138 <    }
236 >  double theta, phi, psi;
237 >  double cosTheta;
238  
239 <  } else if ( !strcasecmp( ensemble, "NVE") ) {
141 <  } else {
142 <    sprintf( painCave.errMsg,
143 <             "SimSetup Warning. Unrecognized Ensemble -> %s, "
144 <             "reverting to NVE for this simulation.\n",
145 <             ensemble );
146 <    painCave.isFatal = 0;
147 <    simError();
148 <    strcpy( ensemble, "NVE" );
149 <  }  
150 <  strcpy( simnfo->ensemble, ensemble );
239 >  // select random phi, psi, and cosTheta
240  
241 +  phi = 2.0 * M_PI * drand48();
242 +  psi = 2.0 * M_PI * drand48();
243 +  cosTheta = (2.0 * drand48()) - 1.0; // sample cos -1 to 1
244  
245 +  theta = acos( cosTheta );
246  
247 <  delete stamps;
248 <  delete globals;
247 >  rot[0][0] = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi));
248 >  rot[0][1] = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi));
249 >  rot[0][2[ = sin(theta) * sin(psi);
250 >  
251 >  rot[1][0] = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi));
252 >  rot[1][1] = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi));
253 >  rot[1][2] = sin(theta) * cos(psi);
254 >
255 >  rot[2][0] = sin(phi) * sin(theta);
256 >  rot[2][1] = -cos(phi) * sin(theta);
257 >  rot[2][2] = cos(theta);  
258   }
259 +                        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines