1 |
#include <cstdlib> |
2 |
#include <cstdio> |
3 |
|
4 |
#include "MakeStamps.hpp" |
5 |
#include "MoleculeStamp.hpp" |
6 |
#include "simError.h" |
7 |
#include "mpiBASS.h" |
8 |
|
9 |
LinkedMolStamp::~LinkedMolStamp(){ |
10 |
if( mol_stamp != NULL ) delete mol_stamp; |
11 |
if( next != NULL ) delete next; |
12 |
} |
13 |
|
14 |
MoleculeStamp* LinkedMolStamp::match( char* id ){ |
15 |
|
16 |
if( mol_stamp != NULL ){ |
17 |
|
18 |
if(!strcmp( mol_stamp->getID(), id )) return mol_stamp; |
19 |
|
20 |
if( next != NULL ) return next->match( id ); |
21 |
} |
22 |
|
23 |
return NULL; |
24 |
} |
25 |
|
26 |
MakeStamps::MakeStamps(){ |
27 |
|
28 |
int i; |
29 |
|
30 |
my_mols = new LinkedMolStamp*[hash_size]; |
31 |
for( i=0; i<hash_size; i++ ){ |
32 |
my_mols[i] = NULL; |
33 |
} |
34 |
|
35 |
} |
36 |
|
37 |
MakeStamps::~MakeStamps(){ |
38 |
|
39 |
int i; |
40 |
|
41 |
for( i=0; i<hash_size; i++ ){ |
42 |
if( my_mols[i] != NULL ) delete my_mols[i]; |
43 |
} |
44 |
delete[] my_mols; |
45 |
} |
46 |
|
47 |
int MakeStamps::hash( char* text ){ |
48 |
|
49 |
register unsigned short int i = 0; // loop counter |
50 |
int key = 0; // the hash key |
51 |
|
52 |
while( text[i] != '\0' ){ |
53 |
|
54 |
key = ( ( key << hash_shift ) + text[i] ) % hash_size; |
55 |
|
56 |
i++; |
57 |
} |
58 |
|
59 |
if( key < 0 ){ |
60 |
|
61 |
// if the key is less than zero, we've had an overflow error |
62 |
|
63 |
sprintf( painCave.errMsg, |
64 |
"There has been an overflow error in the MakeStamps hash key."); |
65 |
painCave.isFatal = 1; |
66 |
simError(); |
67 |
#ifdef IS_MPI |
68 |
if( painCave.isEventLoop ){ |
69 |
if( worldRank == 0 ) mpiInterfaceExit(); |
70 |
} |
71 |
#endif //is_mpi |
72 |
} |
73 |
|
74 |
return key; |
75 |
} |
76 |
|
77 |
MoleculeStamp* MakeStamps::getMolecule( char* the_id ){ |
78 |
int key; |
79 |
|
80 |
key = hash( the_id ); |
81 |
if( my_mols[key] != NULL ){ |
82 |
return my_mols[key]->match( the_id ); |
83 |
} |
84 |
|
85 |
return NULL; |
86 |
} |
87 |
|
88 |
void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){ |
89 |
|
90 |
int key; |
91 |
LinkedMolStamp* linked_mol; |
92 |
|
93 |
key = hash( the_stamp->getID() ); |
94 |
|
95 |
linked_mol = new LinkedMolStamp; |
96 |
linked_mol->setStamp( the_stamp ); |
97 |
linked_mol->setNext( my_mols[key] ); |
98 |
|
99 |
my_mols[key] = linked_mol; |
100 |
} |
101 |
|
102 |
|
103 |
int MakeStamps::newMolecule( event* the_event ){ |
104 |
|
105 |
current_mol = new MoleculeStamp; |
106 |
return 1; |
107 |
} |
108 |
|
109 |
int MakeStamps::moleculeAssign( event* the_event ){ |
110 |
|
111 |
switch( the_event->evt.asmt.asmt_type ){ |
112 |
|
113 |
case STRING: |
114 |
return current_mol->assignString( the_event->evt.asmt.lhs, |
115 |
the_event->evt.asmt.rhs.sval ); |
116 |
break; |
117 |
|
118 |
case DOUBLE: |
119 |
return current_mol->assignDouble( the_event->evt.asmt.lhs, |
120 |
the_event->evt.asmt.rhs.dval ); |
121 |
break; |
122 |
|
123 |
case INT: |
124 |
return current_mol->assignInt( the_event->evt.asmt.lhs, |
125 |
the_event->evt.asmt.rhs.ival ); |
126 |
break; |
127 |
|
128 |
default: |
129 |
the_event->err_msg = strdup( "MakeStamp error. Invalid molecule" |
130 |
" assignment type" ); |
131 |
return 0; |
132 |
break; |
133 |
} |
134 |
return 0; |
135 |
} |
136 |
|
137 |
int MakeStamps::moleculeEnd( event* the_event ){ |
138 |
|
139 |
the_event->err_msg = current_mol->checkMe(); |
140 |
// if err_msg is set, then something is wrong |
141 |
if( the_event->err_msg != NULL ) return 0; |
142 |
|
143 |
addMolStamp( current_mol ); |
144 |
return 1; |
145 |
} |
146 |
|
147 |
int MakeStamps::newAtom( event* the_event ){ |
148 |
|
149 |
current_atom = new AtomStamp; |
150 |
|
151 |
the_event->err_msg = current_mol->addAtom( current_atom, |
152 |
the_event->evt.blk_index ); |
153 |
if( the_event->err_msg != NULL ) return 0; |
154 |
return 1; |
155 |
} |
156 |
|
157 |
int MakeStamps::atomPosition( event* the_event ){ |
158 |
|
159 |
current_atom->setPosition( the_event->evt.pos.x, |
160 |
the_event->evt.pos.y, |
161 |
the_event->evt.pos.z ); |
162 |
return 1; |
163 |
} |
164 |
|
165 |
|
166 |
int MakeStamps::atomOrientation( event* the_event ){ |
167 |
|
168 |
current_atom->setOrientation( the_event->evt.ornt.x, |
169 |
the_event->evt.ornt.y, |
170 |
the_event->evt.ornt.z ); |
171 |
return 1; |
172 |
} |
173 |
|
174 |
int MakeStamps::atomAssign( event* the_event ){ |
175 |
|
176 |
switch( the_event->evt.asmt.asmt_type ){ |
177 |
|
178 |
case STRING: |
179 |
the_event->err_msg = current_atom->assignString( the_event->evt.asmt.lhs, |
180 |
the_event->evt.asmt.rhs.sval ); |
181 |
if( the_event->err_msg != NULL ) return 0; |
182 |
return 1; |
183 |
break; |
184 |
|
185 |
case DOUBLE: |
186 |
the_event->err_msg = current_atom->assignDouble( the_event->evt.asmt.lhs, |
187 |
the_event->evt.asmt.rhs.dval ); |
188 |
if( the_event->err_msg != NULL ) return 0; |
189 |
return 1; |
190 |
break; |
191 |
|
192 |
case INT: |
193 |
the_event->err_msg = current_atom->assignInt( the_event->evt.asmt.lhs, |
194 |
the_event->evt.asmt.rhs.ival ); |
195 |
if( the_event->err_msg != NULL ) return 0; |
196 |
return 1; |
197 |
break; |
198 |
|
199 |
default: |
200 |
the_event->err_msg = strdup( "MakeStamp error. Invalid atom" |
201 |
" assignment type" ); |
202 |
return 0; |
203 |
break; |
204 |
} |
205 |
return 0; |
206 |
} |
207 |
|
208 |
int MakeStamps::atomEnd( event* the_event ){ |
209 |
|
210 |
the_event->err_msg = current_atom->checkMe(); |
211 |
if( the_event->err_msg != NULL ) return 0; |
212 |
|
213 |
return 1; |
214 |
} |
215 |
|
216 |
int MakeStamps::newBond( event* the_event ){ |
217 |
|
218 |
current_bond = new BondStamp; |
219 |
|
220 |
the_event->err_msg = current_mol->addBond( current_bond, |
221 |
the_event->evt.blk_index ); |
222 |
if( the_event->err_msg != NULL ) return 0; |
223 |
|
224 |
return 1; |
225 |
} |
226 |
|
227 |
int MakeStamps::bondAssign( event* the_event ){ |
228 |
|
229 |
switch( the_event->evt.asmt.asmt_type ){ |
230 |
|
231 |
case STRING: |
232 |
current_bond->assignString( the_event->evt.asmt.lhs, |
233 |
the_event->evt.asmt.rhs.sval ); |
234 |
return 1; |
235 |
break; |
236 |
|
237 |
case DOUBLE: |
238 |
current_bond->assignDouble( the_event->evt.asmt.lhs, |
239 |
the_event->evt.asmt.rhs.dval ); |
240 |
return 1; |
241 |
break; |
242 |
|
243 |
case INT: |
244 |
current_bond->assignInt( the_event->evt.asmt.lhs, |
245 |
the_event->evt.asmt.rhs.ival ); |
246 |
return 1; |
247 |
break; |
248 |
|
249 |
default: |
250 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bond" |
251 |
" assignment type" ); |
252 |
return 0; |
253 |
break; |
254 |
} |
255 |
return 0; |
256 |
} |
257 |
|
258 |
int MakeStamps::bondMember( event* the_event ){ |
259 |
|
260 |
current_bond->members( the_event->evt.mbr.a, |
261 |
the_event->evt.mbr.b ); |
262 |
return 1; |
263 |
} |
264 |
|
265 |
int MakeStamps::bondConstraint( event* the_event ){ |
266 |
|
267 |
current_bond->constrain( the_event->evt.cnstr ); |
268 |
return 1; |
269 |
} |
270 |
|
271 |
int MakeStamps::bondEnd( event* the_event ){ |
272 |
|
273 |
the_event->err_msg = current_bond->checkMe(); |
274 |
if( the_event->err_msg != NULL ) return 0; |
275 |
|
276 |
return 1; |
277 |
} |
278 |
|
279 |
int MakeStamps::newBend( event* the_event ){ |
280 |
|
281 |
current_bend = new BendStamp; |
282 |
|
283 |
the_event->err_msg = current_mol->addBend( current_bend, |
284 |
the_event->evt.blk_index ); |
285 |
if( the_event->err_msg != NULL ) return 0; |
286 |
|
287 |
return 1; |
288 |
} |
289 |
|
290 |
int MakeStamps::bendAssign( event* the_event ){ |
291 |
|
292 |
switch( the_event->evt.asmt.asmt_type ){ |
293 |
|
294 |
case STRING: |
295 |
current_bend->assignString( the_event->evt.asmt.lhs, |
296 |
the_event->evt.asmt.rhs.sval ); |
297 |
return 1; |
298 |
break; |
299 |
|
300 |
case DOUBLE: |
301 |
current_bend->assignDouble( the_event->evt.asmt.lhs, |
302 |
the_event->evt.asmt.rhs.dval ); |
303 |
return 1; |
304 |
break; |
305 |
|
306 |
case INT: |
307 |
current_bend->assignInt( the_event->evt.asmt.lhs, |
308 |
the_event->evt.asmt.rhs.ival ); |
309 |
return 1; |
310 |
break; |
311 |
|
312 |
default: |
313 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bend" |
314 |
" assignment type" ); |
315 |
return 0; |
316 |
break; |
317 |
} |
318 |
return 0; |
319 |
} |
320 |
|
321 |
int MakeStamps::bendMember( event* the_event ){ |
322 |
|
323 |
current_bend->members( the_event->evt.mbr.a, |
324 |
the_event->evt.mbr.b, |
325 |
the_event->evt.mbr.c ); |
326 |
return 1; |
327 |
} |
328 |
|
329 |
int MakeStamps::bendConstraint( event* the_event ){ |
330 |
|
331 |
current_bend->constrain( the_event->evt.cnstr ); |
332 |
return 1; |
333 |
} |
334 |
|
335 |
int MakeStamps::bendEnd( event* the_event ){ |
336 |
|
337 |
the_event->err_msg = current_bend->checkMe(); |
338 |
if( the_event->err_msg != NULL ) return 0; |
339 |
|
340 |
return 1; |
341 |
} |
342 |
|
343 |
int MakeStamps::newTorsion( event* the_event ){ |
344 |
|
345 |
current_torsion = new TorsionStamp; |
346 |
|
347 |
the_event->err_msg = current_mol->addTorsion( current_torsion, |
348 |
the_event->evt.blk_index ); |
349 |
if( the_event->err_msg != NULL ) return 0; |
350 |
|
351 |
return 1; |
352 |
} |
353 |
|
354 |
int MakeStamps::torsionAssign( event* the_event ){ |
355 |
|
356 |
switch( the_event->evt.asmt.asmt_type ){ |
357 |
|
358 |
case STRING: |
359 |
current_torsion->assignString( the_event->evt.asmt.lhs, |
360 |
the_event->evt.asmt.rhs.sval ); |
361 |
return 1; |
362 |
break; |
363 |
|
364 |
case DOUBLE: |
365 |
current_torsion->assignDouble( the_event->evt.asmt.lhs, |
366 |
the_event->evt.asmt.rhs.dval ); |
367 |
return 1; |
368 |
break; |
369 |
|
370 |
case INT: |
371 |
current_torsion->assignInt( the_event->evt.asmt.lhs, |
372 |
the_event->evt.asmt.rhs.ival ); |
373 |
return 1; |
374 |
break; |
375 |
|
376 |
default: |
377 |
the_event->err_msg = strdup( "MakeStamp error. Invalid torsion" |
378 |
" assignment type" ); |
379 |
return 0; |
380 |
break; |
381 |
} |
382 |
return 0; |
383 |
} |
384 |
|
385 |
int MakeStamps::torsionMember( event* the_event ){ |
386 |
|
387 |
current_torsion->members( the_event->evt.mbr.a, |
388 |
the_event->evt.mbr.b, |
389 |
the_event->evt.mbr.c, |
390 |
the_event->evt.mbr.d ); |
391 |
return 1; |
392 |
} |
393 |
|
394 |
int MakeStamps::torsionConstraint( event* the_event ){ |
395 |
|
396 |
current_torsion->constrain( the_event->evt.cnstr ); |
397 |
return 1; |
398 |
} |
399 |
|
400 |
int MakeStamps::torsionEnd( event* the_event ){ |
401 |
|
402 |
the_event->err_msg = current_torsion->checkMe(); |
403 |
if( the_event->err_msg != NULL ) return 0; |
404 |
|
405 |
return 1; |
406 |
} |