ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/MakeStamps.cpp
Revision: 957
Committed: Mon Jan 19 16:08:21 2004 UTC (20 years, 6 months ago) by gezelter
File size: 12017 byte(s)
Log Message:
BASS changes to add RigidBodies and LJrcut

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 "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
94 hash_size = 47;
95 hash_shift = 4;
96
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::newRigidBody( event* the_event ){
216
217 current_rigidbody = new RigidBodyStamp;
218
219 the_event->err_msg = current_mol->addRigidBody( current_rigidbody,
220 the_event->evt.blk_index );
221 if( the_event->err_msg != NULL ) return 0;
222 return 1;
223 }
224
225 int MakeStamps::rigidBodyPosition( event* the_event ){
226
227 current_rigidbody->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::rigidBodyOrientation( event* the_event ){
235
236 current_rigidbody->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::rigidBodyAssign( event* the_event ){
243
244 switch( the_event->evt.asmt.asmt_type ){
245
246 case STRING:
247 the_event->err_msg =
248 current_rigidbody->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_rigidbody->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_rigidbody->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 rigidBody"
272 " assignment type" );
273 return 0;
274 break;
275 }
276 return 0;
277 }
278
279 int MakeStamps::rigidBodyEnd( event* the_event ){
280
281 the_event->err_msg = current_rigidbody->checkMe();
282 if( the_event->err_msg != NULL ) return 0;
283
284 return 1;
285 }
286
287 int MakeStamps::newAtom( event* the_event ){
288
289 current_atom = new AtomStamp;
290
291 the_event->err_msg = current_mol->addAtom( current_atom,
292 the_event->evt.blk_index );
293 if( the_event->err_msg != NULL ) return 0;
294 return 1;
295 }
296
297 int MakeStamps::atomPosition( event* the_event ){
298
299 current_atom->setPosition( the_event->evt.pos.x,
300 the_event->evt.pos.y,
301 the_event->evt.pos.z );
302 return 1;
303 }
304
305
306 int MakeStamps::atomOrientation( event* the_event ){
307
308 current_atom->setOrientation( the_event->evt.ornt.x,
309 the_event->evt.ornt.y,
310 the_event->evt.ornt.z );
311 return 1;
312 }
313
314 int MakeStamps::atomAssign( event* the_event ){
315
316 switch( the_event->evt.asmt.asmt_type ){
317
318 case STRING:
319 the_event->err_msg =
320 current_atom->assignString( the_event->evt.asmt.lhs,
321 the_event->evt.asmt.rhs.sval );
322 if( the_event->err_msg != NULL ) return 0;
323 return 1;
324 break;
325
326 case DOUBLE:
327 the_event->err_msg =
328 current_atom->assignDouble( the_event->evt.asmt.lhs,
329 the_event->evt.asmt.rhs.dval );
330 if( the_event->err_msg != NULL ) return 0;
331 return 1;
332 break;
333
334 case INT:
335 the_event->err_msg =
336 current_atom->assignInt( the_event->evt.asmt.lhs,
337 the_event->evt.asmt.rhs.ival );
338 if( the_event->err_msg != NULL ) return 0;
339 return 1;
340 break;
341
342 default:
343 the_event->err_msg = strdup( "MakeStamp error. Invalid atom"
344 " assignment type" );
345 return 0;
346 break;
347 }
348 return 0;
349 }
350
351 int MakeStamps::atomEnd( event* the_event ){
352
353 the_event->err_msg = current_atom->checkMe();
354 if( the_event->err_msg != NULL ) return 0;
355
356 return 1;
357 }
358
359 int MakeStamps::newBond( event* the_event ){
360
361 current_bond = new BondStamp;
362
363 the_event->err_msg = current_mol->addBond( current_bond,
364 the_event->evt.blk_index );
365 if( the_event->err_msg != NULL ) return 0;
366
367 return 1;
368 }
369
370 int MakeStamps::bondAssign( event* the_event ){
371
372 switch( the_event->evt.asmt.asmt_type ){
373
374 case STRING:
375 current_bond->assignString( the_event->evt.asmt.lhs,
376 the_event->evt.asmt.rhs.sval );
377 return 1;
378 break;
379
380 case DOUBLE:
381 current_bond->assignDouble( the_event->evt.asmt.lhs,
382 the_event->evt.asmt.rhs.dval );
383 return 1;
384 break;
385
386 case INT:
387 current_bond->assignInt( the_event->evt.asmt.lhs,
388 the_event->evt.asmt.rhs.ival );
389 return 1;
390 break;
391
392 default:
393 the_event->err_msg = strdup( "MakeStamp error. Invalid bond"
394 " assignment type" );
395 return 0;
396 break;
397 }
398 return 0;
399 }
400
401 int MakeStamps::bondMember( event* the_event ){
402
403 current_bond->members( the_event->evt.mbr.a,
404 the_event->evt.mbr.b );
405 return 1;
406 }
407
408 int MakeStamps::bondConstraint( event* the_event ){
409
410 current_bond->constrain( the_event->evt.cnstr );
411 return 1;
412 }
413
414 int MakeStamps::bondEnd( event* the_event ){
415
416 the_event->err_msg = current_bond->checkMe();
417 if( the_event->err_msg != NULL ) return 0;
418
419 return 1;
420 }
421
422 int MakeStamps::newBend( event* the_event ){
423
424 current_bend = new BendStamp;
425
426 the_event->err_msg = current_mol->addBend( current_bend,
427 the_event->evt.blk_index );
428 if( the_event->err_msg != NULL ) return 0;
429
430 return 1;
431 }
432
433 int MakeStamps::bendAssign( event* the_event ){
434
435 switch( the_event->evt.asmt.asmt_type ){
436
437 case STRING:
438 current_bend->assignString( the_event->evt.asmt.lhs,
439 the_event->evt.asmt.rhs.sval );
440 return 1;
441 break;
442
443 case DOUBLE:
444 current_bend->assignDouble( the_event->evt.asmt.lhs,
445 the_event->evt.asmt.rhs.dval );
446 return 1;
447 break;
448
449 case INT:
450 current_bend->assignInt( the_event->evt.asmt.lhs,
451 the_event->evt.asmt.rhs.ival );
452 return 1;
453 break;
454
455 default:
456 the_event->err_msg = strdup( "MakeStamp error. Invalid bend"
457 " assignment type" );
458 return 0;
459 break;
460 }
461 return 0;
462 }
463
464 int MakeStamps::bendMember( event* the_event ){
465
466 current_bend->members( the_event->evt.mbr.a,
467 the_event->evt.mbr.b,
468 the_event->evt.mbr.c );
469 return 1;
470 }
471
472 int MakeStamps::bendConstraint( event* the_event ){
473
474 current_bend->constrain( the_event->evt.cnstr );
475 return 1;
476 }
477
478 int MakeStamps::bendEnd( event* the_event ){
479
480 the_event->err_msg = current_bend->checkMe();
481 if( the_event->err_msg != NULL ) return 0;
482
483 return 1;
484 }
485
486 int MakeStamps::newTorsion( event* the_event ){
487
488 current_torsion = new TorsionStamp;
489
490 the_event->err_msg = current_mol->addTorsion( current_torsion,
491 the_event->evt.blk_index );
492 if( the_event->err_msg != NULL ) return 0;
493
494 return 1;
495 }
496
497 int MakeStamps::torsionAssign( event* the_event ){
498
499 switch( the_event->evt.asmt.asmt_type ){
500
501 case STRING:
502 current_torsion->assignString( the_event->evt.asmt.lhs,
503 the_event->evt.asmt.rhs.sval );
504 return 1;
505 break;
506
507 case DOUBLE:
508 current_torsion->assignDouble( the_event->evt.asmt.lhs,
509 the_event->evt.asmt.rhs.dval );
510 return 1;
511 break;
512
513 case INT:
514 current_torsion->assignInt( the_event->evt.asmt.lhs,
515 the_event->evt.asmt.rhs.ival );
516 return 1;
517 break;
518
519 default:
520 the_event->err_msg = strdup( "MakeStamp error. Invalid torsion"
521 " assignment type" );
522 return 0;
523 break;
524 }
525 return 0;
526 }
527
528 int MakeStamps::torsionMember( event* the_event ){
529
530 current_torsion->members( the_event->evt.mbr.a,
531 the_event->evt.mbr.b,
532 the_event->evt.mbr.c,
533 the_event->evt.mbr.d );
534 return 1;
535 }
536
537 int MakeStamps::torsionConstraint( event* the_event ){
538
539 current_torsion->constrain( the_event->evt.cnstr );
540 return 1;
541 }
542
543 int MakeStamps::torsionEnd( event* the_event ){
544
545 the_event->err_msg = current_torsion->checkMe();
546 if( the_event->err_msg != NULL ) return 0;
547
548 return 1;
549 }