| 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::rigidBodyAssign( event* the_event ){ |
| 227 |
|
| 228 |
switch( the_event->evt.asmt.asmt_type ){ |
| 229 |
|
| 230 |
case STRING: |
| 231 |
the_event->err_msg = |
| 232 |
current_rigidbody->assignString( the_event->evt.asmt.lhs, |
| 233 |
the_event->evt.asmt.rhs.sval ); |
| 234 |
if( the_event->err_msg != NULL ) return 0; |
| 235 |
return 1; |
| 236 |
break; |
| 237 |
|
| 238 |
case DOUBLE: |
| 239 |
the_event->err_msg = |
| 240 |
current_rigidbody->assignDouble( the_event->evt.asmt.lhs, |
| 241 |
the_event->evt.asmt.rhs.dval ); |
| 242 |
if( the_event->err_msg != NULL ) return 0; |
| 243 |
return 1; |
| 244 |
break; |
| 245 |
|
| 246 |
case INT: |
| 247 |
the_event->err_msg = |
| 248 |
current_rigidbody->assignInt( the_event->evt.asmt.lhs, |
| 249 |
the_event->evt.asmt.rhs.ival ); |
| 250 |
if( the_event->err_msg != NULL ) return 0; |
| 251 |
return 1; |
| 252 |
break; |
| 253 |
|
| 254 |
default: |
| 255 |
the_event->err_msg = strdup( "MakeStamp error. Invalid rigidBody" |
| 256 |
" assignment type" ); |
| 257 |
return 0; |
| 258 |
break; |
| 259 |
} |
| 260 |
return 0; |
| 261 |
} |
| 262 |
|
| 263 |
int MakeStamps::rigidBodyMembers( event* the_event ){ |
| 264 |
|
| 265 |
int i; |
| 266 |
|
| 267 |
if( the_event->evt.mbrs.nMembers > 0 ){ |
| 268 |
|
| 269 |
for (i = 0; i < the_event->evt.mbrs.nMembers; i++) { |
| 270 |
current_rigidbody->addMember(the_event->evt.mbrs.memberList[i]); |
| 271 |
} |
| 272 |
|
| 273 |
return 1; |
| 274 |
|
| 275 |
} else { |
| 276 |
the_event->err_msg = strdup( "MakeStamp error. No members in memberList " |
| 277 |
" for this rigidBody."); |
| 278 |
return 0; |
| 279 |
|
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
int MakeStamps::rigidBodyEnd( event* the_event ){ |
| 284 |
|
| 285 |
the_event->err_msg = current_rigidbody->checkMe(); |
| 286 |
if( the_event->err_msg != NULL ) return 0; |
| 287 |
|
| 288 |
return 1; |
| 289 |
} |
| 290 |
|
| 291 |
int MakeStamps::newAtom( event* the_event ){ |
| 292 |
|
| 293 |
current_atom = new AtomStamp; |
| 294 |
|
| 295 |
the_event->err_msg = current_mol->addAtom( current_atom, |
| 296 |
the_event->evt.blk_index ); |
| 297 |
|
| 298 |
if( the_event->err_msg != NULL ) return 0; |
| 299 |
return 1; |
| 300 |
} |
| 301 |
|
| 302 |
int MakeStamps::atomPosition( event* the_event ){ |
| 303 |
|
| 304 |
current_atom->setPosition( the_event->evt.pos.x, |
| 305 |
the_event->evt.pos.y, |
| 306 |
the_event->evt.pos.z ); |
| 307 |
return 1; |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
int MakeStamps::atomOrientation( event* the_event ){ |
| 312 |
|
| 313 |
current_atom->setOrientation( the_event->evt.ornt.phi, |
| 314 |
the_event->evt.ornt.theta, |
| 315 |
the_event->evt.ornt.psi ); |
| 316 |
return 1; |
| 317 |
} |
| 318 |
|
| 319 |
int MakeStamps::atomAssign( event* the_event ){ |
| 320 |
|
| 321 |
switch( the_event->evt.asmt.asmt_type ){ |
| 322 |
|
| 323 |
case STRING: |
| 324 |
the_event->err_msg = |
| 325 |
current_atom->assignString( the_event->evt.asmt.lhs, |
| 326 |
the_event->evt.asmt.rhs.sval ); |
| 327 |
if( the_event->err_msg != NULL ) return 0; |
| 328 |
return 1; |
| 329 |
break; |
| 330 |
|
| 331 |
case DOUBLE: |
| 332 |
the_event->err_msg = |
| 333 |
current_atom->assignDouble( the_event->evt.asmt.lhs, |
| 334 |
the_event->evt.asmt.rhs.dval ); |
| 335 |
if( the_event->err_msg != NULL ) return 0; |
| 336 |
return 1; |
| 337 |
break; |
| 338 |
|
| 339 |
case INT: |
| 340 |
the_event->err_msg = |
| 341 |
current_atom->assignInt( the_event->evt.asmt.lhs, |
| 342 |
the_event->evt.asmt.rhs.ival ); |
| 343 |
if( the_event->err_msg != NULL ) return 0; |
| 344 |
return 1; |
| 345 |
break; |
| 346 |
|
| 347 |
default: |
| 348 |
the_event->err_msg = strdup( "MakeStamp error. Invalid atom" |
| 349 |
" assignment type" ); |
| 350 |
return 0; |
| 351 |
break; |
| 352 |
} |
| 353 |
return 0; |
| 354 |
} |
| 355 |
|
| 356 |
int MakeStamps::atomEnd( event* the_event ){ |
| 357 |
|
| 358 |
the_event->err_msg = current_atom->checkMe(); |
| 359 |
if( the_event->err_msg != NULL ) return 0; |
| 360 |
|
| 361 |
return 1; |
| 362 |
} |
| 363 |
|
| 364 |
int MakeStamps::newBond( event* the_event ){ |
| 365 |
|
| 366 |
current_bond = new BondStamp; |
| 367 |
|
| 368 |
the_event->err_msg = current_mol->addBond( current_bond, |
| 369 |
the_event->evt.blk_index ); |
| 370 |
if( the_event->err_msg != NULL ) return 0; |
| 371 |
|
| 372 |
return 1; |
| 373 |
} |
| 374 |
|
| 375 |
int MakeStamps::bondAssign( event* the_event ){ |
| 376 |
|
| 377 |
switch( the_event->evt.asmt.asmt_type ){ |
| 378 |
|
| 379 |
case STRING: |
| 380 |
current_bond->assignString( the_event->evt.asmt.lhs, |
| 381 |
the_event->evt.asmt.rhs.sval ); |
| 382 |
return 1; |
| 383 |
break; |
| 384 |
|
| 385 |
case DOUBLE: |
| 386 |
current_bond->assignDouble( the_event->evt.asmt.lhs, |
| 387 |
the_event->evt.asmt.rhs.dval ); |
| 388 |
return 1; |
| 389 |
break; |
| 390 |
|
| 391 |
case INT: |
| 392 |
current_bond->assignInt( the_event->evt.asmt.lhs, |
| 393 |
the_event->evt.asmt.rhs.ival ); |
| 394 |
return 1; |
| 395 |
break; |
| 396 |
|
| 397 |
default: |
| 398 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bond" |
| 399 |
" assignment type" ); |
| 400 |
return 0; |
| 401 |
break; |
| 402 |
} |
| 403 |
return 0; |
| 404 |
} |
| 405 |
|
| 406 |
int MakeStamps::bondMembers( event* the_event ){ |
| 407 |
|
| 408 |
if( the_event->evt.mbrs.nMembers == 2 ){ |
| 409 |
|
| 410 |
current_bond->members( the_event->evt.mbrs.memberList[0], |
| 411 |
the_event->evt.mbrs.memberList[1] ); |
| 412 |
return 1; |
| 413 |
|
| 414 |
} else { |
| 415 |
the_event->err_msg = strdup( "MakeStamp error. Wrong number of members " |
| 416 |
" in bond"); |
| 417 |
return 0; |
| 418 |
|
| 419 |
} |
| 420 |
|
| 421 |
} |
| 422 |
|
| 423 |
int MakeStamps::bondConstraint( event* the_event ){ |
| 424 |
|
| 425 |
current_bond->constrain( the_event->evt.cnstr ); |
| 426 |
return 1; |
| 427 |
} |
| 428 |
|
| 429 |
int MakeStamps::bondEnd( event* the_event ){ |
| 430 |
|
| 431 |
the_event->err_msg = current_bond->checkMe(); |
| 432 |
if( the_event->err_msg != NULL ) return 0; |
| 433 |
|
| 434 |
return 1; |
| 435 |
} |
| 436 |
|
| 437 |
int MakeStamps::newBend( event* the_event ){ |
| 438 |
|
| 439 |
current_bend = new BendStamp; |
| 440 |
|
| 441 |
the_event->err_msg = current_mol->addBend( current_bend, |
| 442 |
the_event->evt.blk_index ); |
| 443 |
if( the_event->err_msg != NULL ) return 0; |
| 444 |
|
| 445 |
return 1; |
| 446 |
} |
| 447 |
|
| 448 |
int MakeStamps::bendAssign( event* the_event ){ |
| 449 |
|
| 450 |
switch( the_event->evt.asmt.asmt_type ){ |
| 451 |
|
| 452 |
case STRING: |
| 453 |
current_bend->assignString( the_event->evt.asmt.lhs, |
| 454 |
the_event->evt.asmt.rhs.sval ); |
| 455 |
return 1; |
| 456 |
break; |
| 457 |
|
| 458 |
case DOUBLE: |
| 459 |
current_bend->assignDouble( the_event->evt.asmt.lhs, |
| 460 |
the_event->evt.asmt.rhs.dval ); |
| 461 |
return 1; |
| 462 |
break; |
| 463 |
|
| 464 |
case INT: |
| 465 |
current_bend->assignInt( the_event->evt.asmt.lhs, |
| 466 |
the_event->evt.asmt.rhs.ival ); |
| 467 |
return 1; |
| 468 |
break; |
| 469 |
|
| 470 |
default: |
| 471 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bend" |
| 472 |
" assignment type" ); |
| 473 |
return 0; |
| 474 |
break; |
| 475 |
} |
| 476 |
return 0; |
| 477 |
} |
| 478 |
|
| 479 |
int MakeStamps::bendMembers( event* the_event ){ |
| 480 |
|
| 481 |
|
| 482 |
switch( the_event->evt.mbrs.nMembers ) { |
| 483 |
case 3: |
| 484 |
current_bend->members( the_event->evt.mbrs.memberList[0], |
| 485 |
the_event->evt.mbrs.memberList[1], |
| 486 |
the_event->evt.mbrs.memberList[2]); |
| 487 |
return 1; |
| 488 |
break; |
| 489 |
case 2: |
| 490 |
current_bend->members( the_event->evt.mbrs.memberList[0], |
| 491 |
the_event->evt.mbrs.memberList[1], |
| 492 |
0 ); |
| 493 |
return 1; |
| 494 |
break; |
| 495 |
default: |
| 496 |
the_event->err_msg = strdup( "MakeStamp error. Wrong number of members " |
| 497 |
"in bend."); |
| 498 |
return 0; |
| 499 |
break; |
| 500 |
} |
| 501 |
return 0; |
| 502 |
} |
| 503 |
|
| 504 |
int MakeStamps::bendConstraint( event* the_event ){ |
| 505 |
|
| 506 |
current_bend->constrain( the_event->evt.cnstr ); |
| 507 |
return 1; |
| 508 |
} |
| 509 |
|
| 510 |
int MakeStamps::bendEnd( event* the_event ){ |
| 511 |
|
| 512 |
the_event->err_msg = current_bend->checkMe(); |
| 513 |
if( the_event->err_msg != NULL ) return 0; |
| 514 |
|
| 515 |
return 1; |
| 516 |
} |
| 517 |
|
| 518 |
int MakeStamps::newTorsion( event* the_event ){ |
| 519 |
|
| 520 |
current_torsion = new TorsionStamp; |
| 521 |
|
| 522 |
the_event->err_msg = current_mol->addTorsion( current_torsion, |
| 523 |
the_event->evt.blk_index ); |
| 524 |
if( the_event->err_msg != NULL ) return 0; |
| 525 |
|
| 526 |
return 1; |
| 527 |
} |
| 528 |
|
| 529 |
int MakeStamps::torsionAssign( event* the_event ){ |
| 530 |
|
| 531 |
switch( the_event->evt.asmt.asmt_type ){ |
| 532 |
|
| 533 |
case STRING: |
| 534 |
current_torsion->assignString( the_event->evt.asmt.lhs, |
| 535 |
the_event->evt.asmt.rhs.sval ); |
| 536 |
return 1; |
| 537 |
break; |
| 538 |
|
| 539 |
case DOUBLE: |
| 540 |
current_torsion->assignDouble( the_event->evt.asmt.lhs, |
| 541 |
the_event->evt.asmt.rhs.dval ); |
| 542 |
return 1; |
| 543 |
break; |
| 544 |
|
| 545 |
case INT: |
| 546 |
current_torsion->assignInt( the_event->evt.asmt.lhs, |
| 547 |
the_event->evt.asmt.rhs.ival ); |
| 548 |
return 1; |
| 549 |
break; |
| 550 |
|
| 551 |
default: |
| 552 |
the_event->err_msg = strdup( "MakeStamp error. Invalid torsion" |
| 553 |
" assignment type" ); |
| 554 |
return 0; |
| 555 |
break; |
| 556 |
} |
| 557 |
return 0; |
| 558 |
} |
| 559 |
|
| 560 |
int MakeStamps::torsionMembers( event* the_event ){ |
| 561 |
|
| 562 |
if( the_event->evt.mbrs.nMembers == 4 ){ |
| 563 |
|
| 564 |
current_torsion->members( the_event->evt.mbrs.memberList[0], |
| 565 |
the_event->evt.mbrs.memberList[1], |
| 566 |
the_event->evt.mbrs.memberList[2], |
| 567 |
the_event->evt.mbrs.memberList[3]); |
| 568 |
return 1; |
| 569 |
|
| 570 |
} else { |
| 571 |
the_event->err_msg = strdup( "MakeStamp error. Wrong number of members " |
| 572 |
" in torsion"); |
| 573 |
return 0; |
| 574 |
|
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
int MakeStamps::torsionConstraint( event* the_event ){ |
| 579 |
|
| 580 |
current_torsion->constrain( the_event->evt.cnstr ); |
| 581 |
return 1; |
| 582 |
} |
| 583 |
|
| 584 |
int MakeStamps::torsionEnd( event* the_event ){ |
| 585 |
|
| 586 |
the_event->err_msg = current_torsion->checkMe(); |
| 587 |
if( the_event->err_msg != NULL ) return 0; |
| 588 |
|
| 589 |
return 1; |
| 590 |
} |