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