ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/MakeStamps.cpp
Revision: 981
Committed: Mon Jan 26 18:52:42 2004 UTC (21 years, 3 months ago) by gezelter
File size: 12361 byte(s)
Log Message:
Fix broken atom assignment for rigid bodies

File Contents

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