1 |
+ |
#include <iostream> |
2 |
+ |
|
3 |
|
#include <cstdlib> |
4 |
|
#include <cstring> |
5 |
|
#include <cmath> |
36 |
|
int buildRandomBilayer( void ){ |
37 |
|
|
38 |
|
int i,j,k; |
39 |
< |
int nAtoms, atomIndex; |
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; |
57 |
|
|
58 |
|
srand48( RAND_SEED ); |
59 |
|
molSeq = NULL; |
60 |
+ |
molStart = NULL; |
61 |
|
molMap = NULL; |
62 |
|
cardDeck = NULL; |
63 |
|
atoms = NULL; |
71 |
|
nSites = 0; |
72 |
|
while( nSites < bsInfo.totNmol ){ |
73 |
|
nCells++; |
74 |
< |
nSites = 4 * pow( nCells, 3 ); |
74 |
> |
nSites = 4.0 * pow( (double)nCells, 3.0 ); |
75 |
|
} |
76 |
|
|
77 |
|
|
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.compStamp[i]->getNAtoms(); |
116 |
> |
nAtoms += bsInfo.compStamps[i]->getNAtoms(); |
117 |
|
} |
118 |
|
} |
119 |
|
|
127 |
|
for(i=0; i<bsInfo.nComponents; i++){ |
128 |
|
if(cell < locate[i]->getMaxLength() ) cell = locate[i]->getMaxLength(); |
129 |
|
} |
130 |
< |
cell *= M_SQRT_2; |
130 |
> |
cell *= 1.2; // add a little buffer |
131 |
|
|
132 |
+ |
cell *= M_SQRT2; |
133 |
+ |
|
134 |
|
siteIndex = 0; |
127 |
– |
atomIndex = 0; |
135 |
|
for(i=0; i<nCells; i++){ |
136 |
|
for(j=0; j<nCells; j++){ |
137 |
|
for(k=0; k<nCells; k++){ |
143 |
|
|
144 |
|
getRandomRot( rot ); |
145 |
|
molID = molSeq[molMap[siteIndex]]; |
146 |
< |
locate[molID]->placeMol( pos, rot, &atoms[atomIndex] ); |
147 |
< |
|
141 |
< |
atomIndex += bsInfo.compStamps[molID]->getNatoms(); |
146 |
> |
atomIndex = molStart[ molMap[siteIndex] ]; |
147 |
> |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
148 |
|
} |
149 |
|
siteIndex++; |
150 |
|
|
152 |
|
pos[0] = i * cell + (0.5 * cell); |
153 |
|
pos[1] = j * cell; |
154 |
|
pos[2] = k * cell + (0.5 * cell); |
155 |
< |
|
155 |
> |
|
156 |
|
getRandomRot( rot ); |
157 |
|
molID = molSeq[molMap[siteIndex]]; |
158 |
< |
locate[molID]->placeMol( pos, rot, &atoms[atomIndex] ); |
159 |
< |
|
154 |
< |
atomIndex += bsInfo.compStamps[molID]->getNatoms(); |
158 |
> |
atomIndex = molStart[ molMap[siteIndex] ]; |
159 |
> |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
160 |
|
} |
161 |
|
siteIndex++; |
162 |
|
|
167 |
|
|
168 |
|
getRandomRot( rot ); |
169 |
|
molID = molSeq[molMap[siteIndex]]; |
170 |
< |
locate[molID]->placeMol( pos, rot, &atoms[atomIndex] ); |
171 |
< |
|
167 |
< |
atomIndex += bsInfo.compStamps[molID]->getNatoms(); |
170 |
> |
atomIndex = molStart[ molMap[siteIndex] ]; |
171 |
> |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
172 |
|
} |
173 |
|
siteIndex++; |
174 |
|
|
176 |
|
pos[0] = i * cell; |
177 |
|
pos[1] = j * cell + (0.5 * cell); |
178 |
|
pos[2] = k * cell + (0.5 * cell); |
179 |
< |
|
179 |
> |
|
180 |
|
getRandomRot( rot ); |
181 |
|
molID = molSeq[molMap[siteIndex]]; |
182 |
< |
locate[molID]->placeMol( pos, rot, &atoms[atomIndex] ); |
183 |
< |
|
180 |
< |
atomIndex += bsInfo.compStamps[molID]->getNatoms(); |
182 |
> |
atomIndex = molStart[ molMap[siteIndex] ]; |
183 |
> |
locate[molID]->placeMol( pos, rot, atoms, atomIndex ); |
184 |
|
} |
185 |
|
siteIndex++; |
186 |
|
} |
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; |
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.statusName, "%s.dump", bsInfo.outPrefix ); |
203 |
< |
sprintf( simnfo.finalName, "%s.init", bsInfo.outPrefix ); |
202 |
> |
sprintf( simnfo->sampleName, "%s.dump", bsInfo.outPrefix ); |
203 |
> |
sprintf( simnfo->finalName, "%s.init", bsInfo.outPrefix ); |
204 |
> |
|
205 |
> |
simnfo->atoms = atoms; |
206 |
|
|
202 |
– |
simnfo.atoms = atoms; |
203 |
– |
|
207 |
|
// set up the writer and write out |
208 |
|
|
209 |
< |
writer = new DumpWriter( &simnfo ); |
209 |
> |
writer = new DumpWriter( simnfo ); |
210 |
|
writer->writeFinal(); |
211 |
|
|
212 |
|
// clean up the memory |
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); |
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)); |