1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include "MakeStamps.hpp" |
6 |
#include "MoleculeStamp.hpp" |
7 |
#include "RigidBodyStamp.hpp" |
8 |
#include "CutoffGroupStamp.hpp" |
9 |
#include "simError.h" |
10 |
#ifdef IS_MPI |
11 |
#include "mpiBASS.h" |
12 |
#endif // is_mpi |
13 |
|
14 |
LinkedMolStamp::~LinkedMolStamp(){ |
15 |
if( mol_stamp != NULL ) delete mol_stamp; |
16 |
if( next != NULL ) delete next; |
17 |
} |
18 |
|
19 |
void LinkedMolStamp::add( LinkedMolStamp* newbie ){ |
20 |
|
21 |
if( next != NULL ) next->add( newbie ); |
22 |
else{ |
23 |
next = newbie; |
24 |
next->setPrev( this ); |
25 |
} |
26 |
} |
27 |
|
28 |
MoleculeStamp* LinkedMolStamp::match( char* id ){ |
29 |
|
30 |
if( mol_stamp != NULL ){ |
31 |
if(!strcmp( mol_stamp->getID(), id )){ |
32 |
|
33 |
// make sure we aren't hiding somebody else with the same name |
34 |
if(next != NULL ){ |
35 |
if( next->match( id ) != NULL){ |
36 |
sprintf( painCave.errMsg, |
37 |
"Molecule Stamp Error. Two separate of declarations of " |
38 |
"%s present.\n", |
39 |
id ); |
40 |
painCave.isFatal = 1; |
41 |
simError(); |
42 |
#ifdef IS_MPI |
43 |
if( painCave.isEventLoop ){ |
44 |
if( worldRank == 0 ) mpiInterfaceExit(); |
45 |
} |
46 |
#endif //is_mpi |
47 |
} |
48 |
else return mol_stamp; |
49 |
} |
50 |
else return mol_stamp; |
51 |
} |
52 |
} |
53 |
|
54 |
if( next != NULL ) return next->match( id ); |
55 |
|
56 |
return NULL; |
57 |
} |
58 |
|
59 |
LinkedMolStamp* LinkedMolStamp::extract( char* id ){ |
60 |
|
61 |
if( mol_stamp != NULL ){ |
62 |
if(!strcmp( mol_stamp->getID(), id )){ |
63 |
|
64 |
// make sure we aren't hiding somebody else with the same name |
65 |
if(next != NULL ){ |
66 |
if( next->match( id ) != NULL){ |
67 |
sprintf( painCave.errMsg, |
68 |
"Molecule Stamp Error. Two separate of declarations of " |
69 |
"%s present.\n", |
70 |
id ); |
71 |
painCave.isFatal = 1; |
72 |
simError(); |
73 |
#ifdef IS_MPI |
74 |
if( painCave.isEventLoop ){ |
75 |
if( worldRank == 0 ) mpiInterfaceExit(); |
76 |
} |
77 |
#endif //is_mpi |
78 |
} |
79 |
} |
80 |
|
81 |
prev->setNext( next ); |
82 |
if( next != NULL ) next->setPrev( prev ); |
83 |
return this; |
84 |
} |
85 |
} |
86 |
|
87 |
if( next != NULL ) return next->extract( id ); |
88 |
|
89 |
return NULL; |
90 |
} |
91 |
|
92 |
MakeStamps::MakeStamps(){ |
93 |
|
94 |
int i; |
95 |
|
96 |
hash_size = 47; |
97 |
hash_shift = 4; |
98 |
|
99 |
my_mols = new LinkedMolStamp*[hash_size]; |
100 |
for( i=0; i<hash_size; i++ ){ |
101 |
my_mols[i] = new LinkedMolStamp(); |
102 |
} |
103 |
|
104 |
} |
105 |
|
106 |
MakeStamps::~MakeStamps(){ |
107 |
|
108 |
int i; |
109 |
|
110 |
for( i=0; i<hash_size; i++ ){ |
111 |
if( my_mols[i] != NULL ) delete my_mols[i]; |
112 |
} |
113 |
delete[] my_mols; |
114 |
} |
115 |
|
116 |
int MakeStamps::hash( char* text ){ |
117 |
|
118 |
register unsigned short int i = 0; // loop counter |
119 |
int key = 0; // the hash key |
120 |
|
121 |
while( text[i] != '\0' ){ |
122 |
|
123 |
key = ( ( key << hash_shift ) + text[i] ) % hash_size; |
124 |
|
125 |
i++; |
126 |
} |
127 |
|
128 |
if( key < 0 ){ |
129 |
|
130 |
// if the key is less than zero, we've had an overflow error |
131 |
|
132 |
sprintf( painCave.errMsg, |
133 |
"There has been an overflow error in the MakeStamps hash key."); |
134 |
painCave.isFatal = 1; |
135 |
simError(); |
136 |
#ifdef IS_MPI |
137 |
if( painCave.isEventLoop ){ |
138 |
if( worldRank == 0 ) mpiInterfaceExit(); |
139 |
} |
140 |
#endif //is_mpi |
141 |
} |
142 |
|
143 |
return key; |
144 |
} |
145 |
|
146 |
LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){ |
147 |
int key; |
148 |
|
149 |
key = hash( the_id ); |
150 |
if( my_mols[key] != NULL ){ |
151 |
return my_mols[key]->extract( the_id ); |
152 |
} |
153 |
|
154 |
return NULL; |
155 |
} |
156 |
|
157 |
void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){ |
158 |
|
159 |
int key; |
160 |
LinkedMolStamp* linked_mol; |
161 |
|
162 |
key = hash( the_stamp->getID() ); |
163 |
|
164 |
linked_mol = new LinkedMolStamp; |
165 |
linked_mol->setStamp( the_stamp ); |
166 |
|
167 |
my_mols[key]->add( linked_mol ); |
168 |
|
169 |
} |
170 |
|
171 |
|
172 |
int MakeStamps::newMolecule( event* the_event ){ |
173 |
|
174 |
current_mol = new MoleculeStamp; |
175 |
return 1; |
176 |
} |
177 |
|
178 |
int MakeStamps::moleculeAssign( event* the_event ){ |
179 |
|
180 |
switch( the_event->evt.asmt.asmt_type ){ |
181 |
|
182 |
case STRING: |
183 |
the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs, |
184 |
the_event->evt.asmt.rhs.sval ); |
185 |
break; |
186 |
|
187 |
case DOUBLE: |
188 |
the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs, |
189 |
the_event->evt.asmt.rhs.dval ); |
190 |
break; |
191 |
|
192 |
case INT: |
193 |
the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs, |
194 |
the_event->evt.asmt.rhs.ival ); |
195 |
break; |
196 |
|
197 |
default: |
198 |
the_event->err_msg = strdup( "MakeStamp error. Invalid molecule" |
199 |
" assignment type" ); |
200 |
return 0; |
201 |
break; |
202 |
} |
203 |
if( the_event->err_msg != NULL ) return 0; |
204 |
return 1; |
205 |
} |
206 |
|
207 |
int MakeStamps::moleculeEnd( event* the_event ){ |
208 |
|
209 |
the_event->err_msg = current_mol->checkMe(); |
210 |
// if err_msg is set, then something is wrong |
211 |
if( the_event->err_msg != NULL ) return 0; |
212 |
|
213 |
addMolStamp( current_mol ); |
214 |
return 1; |
215 |
} |
216 |
|
217 |
int MakeStamps::newRigidBody( event* the_event ){ |
218 |
|
219 |
current_rigidbody = new RigidBodyStamp; |
220 |
|
221 |
printf("makeStamps rb index = %d\n", the_event->evt.blk_index); |
222 |
|
223 |
the_event->err_msg = current_mol->addRigidBody( current_rigidbody, |
224 |
the_event->evt.blk_index ); |
225 |
if( the_event->err_msg != NULL ) return 0; |
226 |
return 1; |
227 |
} |
228 |
|
229 |
int MakeStamps::rigidBodyAssign( event* the_event ){ |
230 |
|
231 |
switch( the_event->evt.asmt.asmt_type ){ |
232 |
|
233 |
case STRING: |
234 |
the_event->err_msg = |
235 |
current_rigidbody->assignString( the_event->evt.asmt.lhs, |
236 |
the_event->evt.asmt.rhs.sval ); |
237 |
if( the_event->err_msg != NULL ) return 0; |
238 |
return 1; |
239 |
break; |
240 |
|
241 |
case DOUBLE: |
242 |
the_event->err_msg = |
243 |
current_rigidbody->assignDouble( the_event->evt.asmt.lhs, |
244 |
the_event->evt.asmt.rhs.dval ); |
245 |
if( the_event->err_msg != NULL ) return 0; |
246 |
return 1; |
247 |
break; |
248 |
|
249 |
case INT: |
250 |
the_event->err_msg = |
251 |
current_rigidbody->assignInt( the_event->evt.asmt.lhs, |
252 |
the_event->evt.asmt.rhs.ival ); |
253 |
if( the_event->err_msg != NULL ) return 0; |
254 |
return 1; |
255 |
break; |
256 |
|
257 |
default: |
258 |
the_event->err_msg = strdup( "MakeStamp error. Invalid rigidBody" |
259 |
" assignment type" ); |
260 |
return 0; |
261 |
break; |
262 |
} |
263 |
return 0; |
264 |
} |
265 |
|
266 |
int MakeStamps::rigidBodyMembers( event* the_event ){ |
267 |
|
268 |
int i; |
269 |
|
270 |
if( the_event->evt.mbrs.nMembers > 0 ){ |
271 |
|
272 |
for (i = 0; i < the_event->evt.mbrs.nMembers; i++) { |
273 |
current_rigidbody->addMember(the_event->evt.mbrs.memberList[i]); |
274 |
} |
275 |
|
276 |
return 1; |
277 |
|
278 |
} else { |
279 |
the_event->err_msg = strdup( "MakeStamp error. No members in memberList " |
280 |
" for this rigidBody."); |
281 |
return 0; |
282 |
|
283 |
} |
284 |
} |
285 |
|
286 |
int MakeStamps::rigidBodyEnd( event* the_event ){ |
287 |
|
288 |
the_event->err_msg = current_rigidbody->checkMe(); |
289 |
if( the_event->err_msg != NULL ) return 0; |
290 |
|
291 |
return 1; |
292 |
} |
293 |
|
294 |
int MakeStamps::newCutoffGroup( event* the_event ){ |
295 |
|
296 |
current_cutoffgroup = new CutoffGroupStamp; |
297 |
|
298 |
the_event->err_msg = current_mol->addCutoffGroup( current_cutoffgroup, |
299 |
the_event->evt.blk_index ); |
300 |
if( the_event->err_msg != NULL ) return 0; |
301 |
return 1; |
302 |
} |
303 |
|
304 |
int MakeStamps::cutoffGroupAssign( event* the_event ){ |
305 |
|
306 |
switch( the_event->evt.asmt.asmt_type ){ |
307 |
|
308 |
case STRING: |
309 |
the_event->err_msg = |
310 |
current_cutoffgroup->assignString( the_event->evt.asmt.lhs, |
311 |
the_event->evt.asmt.rhs.sval ); |
312 |
if( the_event->err_msg != NULL ) return 0; |
313 |
return 1; |
314 |
break; |
315 |
|
316 |
case DOUBLE: |
317 |
the_event->err_msg = |
318 |
current_cutoffgroup->assignDouble( the_event->evt.asmt.lhs, |
319 |
the_event->evt.asmt.rhs.dval ); |
320 |
if( the_event->err_msg != NULL ) return 0; |
321 |
return 1; |
322 |
break; |
323 |
|
324 |
case INT: |
325 |
the_event->err_msg = |
326 |
current_cutoffgroup->assignInt( the_event->evt.asmt.lhs, |
327 |
the_event->evt.asmt.rhs.ival ); |
328 |
if( the_event->err_msg != NULL ) return 0; |
329 |
return 1; |
330 |
break; |
331 |
|
332 |
default: |
333 |
the_event->err_msg = strdup( "MakeStamp error. Invalid CutoffGroup" |
334 |
" assignment type" ); |
335 |
return 0; |
336 |
break; |
337 |
} |
338 |
return 0; |
339 |
} |
340 |
|
341 |
int MakeStamps::cutoffGroupMembers( event* the_event ){ |
342 |
|
343 |
int i; |
344 |
|
345 |
if( the_event->evt.mbrs.nMembers > 0 ){ |
346 |
|
347 |
for (i = 0; i < the_event->evt.mbrs.nMembers; i++) { |
348 |
current_cutoffgroup->addMember(the_event->evt.mbrs.memberList[i]); |
349 |
} |
350 |
|
351 |
return 1; |
352 |
|
353 |
} else { |
354 |
the_event->err_msg = strdup( "MakeStamp error. No members in memberList " |
355 |
" for this CutoffGroup."); |
356 |
return 0; |
357 |
|
358 |
} |
359 |
} |
360 |
|
361 |
int MakeStamps::cutoffGroupEnd( event* the_event ){ |
362 |
|
363 |
the_event->err_msg = current_cutoffgroup->checkMe(); |
364 |
if( the_event->err_msg != NULL ) return 0; |
365 |
|
366 |
return 1; |
367 |
} |
368 |
|
369 |
int MakeStamps::newAtom( event* the_event ){ |
370 |
|
371 |
current_atom = new AtomStamp; |
372 |
|
373 |
the_event->err_msg = current_mol->addAtom( current_atom, |
374 |
the_event->evt.blk_index ); |
375 |
|
376 |
if( the_event->err_msg != NULL ) return 0; |
377 |
return 1; |
378 |
} |
379 |
|
380 |
int MakeStamps::atomPosition( event* the_event ){ |
381 |
|
382 |
current_atom->setPosition( the_event->evt.pos.x, |
383 |
the_event->evt.pos.y, |
384 |
the_event->evt.pos.z ); |
385 |
return 1; |
386 |
} |
387 |
|
388 |
|
389 |
int MakeStamps::atomOrientation( event* the_event ){ |
390 |
|
391 |
current_atom->setOrientation( the_event->evt.ornt.phi, |
392 |
the_event->evt.ornt.theta, |
393 |
the_event->evt.ornt.psi ); |
394 |
return 1; |
395 |
} |
396 |
|
397 |
int MakeStamps::atomAssign( event* the_event ){ |
398 |
|
399 |
switch( the_event->evt.asmt.asmt_type ){ |
400 |
|
401 |
case STRING: |
402 |
the_event->err_msg = |
403 |
current_atom->assignString( the_event->evt.asmt.lhs, |
404 |
the_event->evt.asmt.rhs.sval ); |
405 |
if( the_event->err_msg != NULL ) return 0; |
406 |
return 1; |
407 |
break; |
408 |
|
409 |
case DOUBLE: |
410 |
the_event->err_msg = |
411 |
current_atom->assignDouble( the_event->evt.asmt.lhs, |
412 |
the_event->evt.asmt.rhs.dval ); |
413 |
if( the_event->err_msg != NULL ) return 0; |
414 |
return 1; |
415 |
break; |
416 |
|
417 |
case INT: |
418 |
the_event->err_msg = |
419 |
current_atom->assignInt( the_event->evt.asmt.lhs, |
420 |
the_event->evt.asmt.rhs.ival ); |
421 |
if( the_event->err_msg != NULL ) return 0; |
422 |
return 1; |
423 |
break; |
424 |
|
425 |
default: |
426 |
the_event->err_msg = strdup( "MakeStamp error. Invalid atom" |
427 |
" assignment type" ); |
428 |
return 0; |
429 |
break; |
430 |
} |
431 |
return 0; |
432 |
} |
433 |
|
434 |
int MakeStamps::atomEnd( event* the_event ){ |
435 |
|
436 |
the_event->err_msg = current_atom->checkMe(); |
437 |
if( the_event->err_msg != NULL ) return 0; |
438 |
|
439 |
return 1; |
440 |
} |
441 |
|
442 |
int MakeStamps::newBond( event* the_event ){ |
443 |
|
444 |
current_bond = new BondStamp; |
445 |
|
446 |
the_event->err_msg = current_mol->addBond( current_bond, |
447 |
the_event->evt.blk_index ); |
448 |
if( the_event->err_msg != NULL ) return 0; |
449 |
|
450 |
return 1; |
451 |
} |
452 |
|
453 |
int MakeStamps::bondAssign( event* the_event ){ |
454 |
|
455 |
switch( the_event->evt.asmt.asmt_type ){ |
456 |
|
457 |
case STRING: |
458 |
current_bond->assignString( the_event->evt.asmt.lhs, |
459 |
the_event->evt.asmt.rhs.sval ); |
460 |
return 1; |
461 |
break; |
462 |
|
463 |
case DOUBLE: |
464 |
current_bond->assignDouble( the_event->evt.asmt.lhs, |
465 |
the_event->evt.asmt.rhs.dval ); |
466 |
return 1; |
467 |
break; |
468 |
|
469 |
case INT: |
470 |
current_bond->assignInt( the_event->evt.asmt.lhs, |
471 |
the_event->evt.asmt.rhs.ival ); |
472 |
return 1; |
473 |
break; |
474 |
|
475 |
default: |
476 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bond" |
477 |
" assignment type" ); |
478 |
return 0; |
479 |
break; |
480 |
} |
481 |
return 0; |
482 |
} |
483 |
|
484 |
int MakeStamps::bondMembers( event* the_event ){ |
485 |
|
486 |
if( the_event->evt.mbrs.nMembers == 2 ){ |
487 |
|
488 |
current_bond->members( the_event->evt.mbrs.memberList[0], |
489 |
the_event->evt.mbrs.memberList[1] ); |
490 |
return 1; |
491 |
|
492 |
} else { |
493 |
the_event->err_msg = strdup( "MakeStamp error. Wrong number of members " |
494 |
" in bond"); |
495 |
return 0; |
496 |
|
497 |
} |
498 |
|
499 |
} |
500 |
|
501 |
int MakeStamps::bondConstraint( event* the_event ){ |
502 |
|
503 |
current_bond->constrain( the_event->evt.cnstr ); |
504 |
return 1; |
505 |
} |
506 |
|
507 |
int MakeStamps::bondEnd( event* the_event ){ |
508 |
|
509 |
the_event->err_msg = current_bond->checkMe(); |
510 |
if( the_event->err_msg != NULL ) return 0; |
511 |
|
512 |
return 1; |
513 |
} |
514 |
|
515 |
int MakeStamps::newBend( event* the_event ){ |
516 |
|
517 |
current_bend = new BendStamp; |
518 |
|
519 |
the_event->err_msg = current_mol->addBend( current_bend, |
520 |
the_event->evt.blk_index ); |
521 |
if( the_event->err_msg != NULL ) return 0; |
522 |
|
523 |
return 1; |
524 |
} |
525 |
|
526 |
int MakeStamps::bendAssign( event* the_event ){ |
527 |
|
528 |
switch( the_event->evt.asmt.asmt_type ){ |
529 |
|
530 |
case STRING: |
531 |
current_bend->assignString( the_event->evt.asmt.lhs, |
532 |
the_event->evt.asmt.rhs.sval ); |
533 |
return 1; |
534 |
break; |
535 |
|
536 |
case DOUBLE: |
537 |
current_bend->assignDouble( the_event->evt.asmt.lhs, |
538 |
the_event->evt.asmt.rhs.dval ); |
539 |
return 1; |
540 |
break; |
541 |
|
542 |
case INT: |
543 |
current_bend->assignInt( the_event->evt.asmt.lhs, |
544 |
the_event->evt.asmt.rhs.ival ); |
545 |
return 1; |
546 |
break; |
547 |
|
548 |
default: |
549 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bend" |
550 |
" assignment type" ); |
551 |
return 0; |
552 |
break; |
553 |
} |
554 |
return 0; |
555 |
} |
556 |
|
557 |
int MakeStamps::bendMembers( event* the_event ){ |
558 |
|
559 |
|
560 |
switch( the_event->evt.mbrs.nMembers ) { |
561 |
case 3: |
562 |
current_bend->members( the_event->evt.mbrs.memberList[0], |
563 |
the_event->evt.mbrs.memberList[1], |
564 |
the_event->evt.mbrs.memberList[2]); |
565 |
return 1; |
566 |
break; |
567 |
case 2: |
568 |
current_bend->members( the_event->evt.mbrs.memberList[0], |
569 |
the_event->evt.mbrs.memberList[1], |
570 |
0 ); |
571 |
return 1; |
572 |
break; |
573 |
default: |
574 |
the_event->err_msg = strdup( "MakeStamp error. Wrong number of members " |
575 |
"in bend."); |
576 |
return 0; |
577 |
break; |
578 |
} |
579 |
return 0; |
580 |
} |
581 |
|
582 |
int MakeStamps::bendConstraint( event* the_event ){ |
583 |
|
584 |
current_bend->constrain( the_event->evt.cnstr ); |
585 |
return 1; |
586 |
} |
587 |
|
588 |
int MakeStamps::bendEnd( event* the_event ){ |
589 |
|
590 |
the_event->err_msg = current_bend->checkMe(); |
591 |
if( the_event->err_msg != NULL ) return 0; |
592 |
|
593 |
return 1; |
594 |
} |
595 |
|
596 |
int MakeStamps::newTorsion( event* the_event ){ |
597 |
|
598 |
current_torsion = new TorsionStamp; |
599 |
|
600 |
the_event->err_msg = current_mol->addTorsion( current_torsion, |
601 |
the_event->evt.blk_index ); |
602 |
if( the_event->err_msg != NULL ) return 0; |
603 |
|
604 |
return 1; |
605 |
} |
606 |
|
607 |
int MakeStamps::torsionAssign( event* the_event ){ |
608 |
|
609 |
switch( the_event->evt.asmt.asmt_type ){ |
610 |
|
611 |
case STRING: |
612 |
current_torsion->assignString( the_event->evt.asmt.lhs, |
613 |
the_event->evt.asmt.rhs.sval ); |
614 |
return 1; |
615 |
break; |
616 |
|
617 |
case DOUBLE: |
618 |
current_torsion->assignDouble( the_event->evt.asmt.lhs, |
619 |
the_event->evt.asmt.rhs.dval ); |
620 |
return 1; |
621 |
break; |
622 |
|
623 |
case INT: |
624 |
current_torsion->assignInt( the_event->evt.asmt.lhs, |
625 |
the_event->evt.asmt.rhs.ival ); |
626 |
return 1; |
627 |
break; |
628 |
|
629 |
default: |
630 |
the_event->err_msg = strdup( "MakeStamp error. Invalid torsion" |
631 |
" assignment type" ); |
632 |
return 0; |
633 |
break; |
634 |
} |
635 |
return 0; |
636 |
} |
637 |
|
638 |
int MakeStamps::torsionMembers( event* the_event ){ |
639 |
|
640 |
if( the_event->evt.mbrs.nMembers == 4 ){ |
641 |
|
642 |
current_torsion->members( the_event->evt.mbrs.memberList[0], |
643 |
the_event->evt.mbrs.memberList[1], |
644 |
the_event->evt.mbrs.memberList[2], |
645 |
the_event->evt.mbrs.memberList[3]); |
646 |
return 1; |
647 |
|
648 |
} else { |
649 |
the_event->err_msg = strdup( "MakeStamp error. Wrong number of members " |
650 |
" in torsion"); |
651 |
return 0; |
652 |
|
653 |
} |
654 |
} |
655 |
|
656 |
int MakeStamps::torsionConstraint( event* the_event ){ |
657 |
|
658 |
current_torsion->constrain( the_event->evt.cnstr ); |
659 |
return 1; |
660 |
} |
661 |
|
662 |
int MakeStamps::torsionEnd( event* the_event ){ |
663 |
|
664 |
the_event->err_msg = current_torsion->checkMe(); |
665 |
if( the_event->err_msg != NULL ) return 0; |
666 |
|
667 |
return 1; |
668 |
} |