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