454 |
|
|
455 |
|
return NULL; |
456 |
|
} |
457 |
+ |
|
458 |
+ |
|
459 |
+ |
//Function Name: isBondInSameRigidBody |
460 |
+ |
//Return true is both atoms of the bond belong to the same rigid body, otherwise return false |
461 |
+ |
bool MoleculeStamp::isBondInSameRigidBody(BondStamp* bond){ |
462 |
+ |
int rbA; |
463 |
+ |
int rbB; |
464 |
+ |
int consAtomA; |
465 |
+ |
int consAtomB; |
466 |
+ |
|
467 |
+ |
return isAtomInRigidBody(bond->getA(),rbA, consAtomA) && |
468 |
+ |
isAtomInRigidBody(bond->getB(),rbB, consAtomB); |
469 |
+ |
} |
470 |
+ |
|
471 |
+ |
|
472 |
+ |
// Function Name isAtomInRigidBody |
473 |
+ |
//return false if atom does not belong to a rigid body otherwise return true and set whichRigidBody |
474 |
+ |
//and consAtomIndex |
475 |
+ |
//atomIndex : the index of atom in component |
476 |
+ |
//whichRigidBody: the index of rigidbody in component |
477 |
+ |
//consAtomIndex: the position of joint atom apears in rigidbody's definition |
478 |
+ |
bool MoleculeStamp::isAtomInRigidBody(int atomIndex, int& whichRigidBody, int& consAtomIndex){ |
479 |
+ |
RigidBodyStamp* rbStamp; |
480 |
+ |
int numRb; |
481 |
+ |
int numAtom; |
482 |
+ |
|
483 |
+ |
numRb = this->getNRigidBodies(); |
484 |
+ |
|
485 |
+ |
for(int i = 0 ; i < numRb; i++){ |
486 |
+ |
rbStamp = this->getRigidBody(i); |
487 |
+ |
numAtom = rbStamp->getNMembers(); |
488 |
+ |
for(int j = 0; j < numAtom; j++) |
489 |
+ |
if (rbStamp->getMember(j) == atomIndex){ |
490 |
+ |
whichRigidBody = i; |
491 |
+ |
consAtomIndex = j; |
492 |
+ |
return true; |
493 |
+ |
} |
494 |
+ |
} |
495 |
+ |
|
496 |
+ |
return false; |
497 |
+ |
|
498 |
+ |
} |
499 |
+ |
|
500 |
+ |
//return the position of joint atom apears in rigidbody's definition |
501 |
+ |
//for the time being, we will use the most inefficient algorithm, the complexity is O(N2) |
502 |
+ |
//actually we could improve the complexity to O(NlgN) by sorting the atom index in rigid body first |
503 |
+ |
vector<pair<int, int> > MoleculeStamp::getJointAtoms(int rb1, int rb2){ |
504 |
+ |
RigidBodyStamp* rbStamp1; |
505 |
+ |
RigidBodyStamp* rbStamp2; |
506 |
+ |
int natomInRb1; |
507 |
+ |
int natomInRb2; |
508 |
+ |
int atomIndex1; |
509 |
+ |
int atomIndex2; |
510 |
+ |
vector<pair<int, int> > jointAtomIndexPair; |
511 |
+ |
|
512 |
+ |
rbStamp1 = this->getRigidBody(rb1); |
513 |
+ |
natomInRb1 =rbStamp1->getNMembers(); |
514 |
+ |
|
515 |
+ |
rbStamp2 = this->getRigidBody(rb2); |
516 |
+ |
natomInRb2 =rbStamp2->getNMembers(); |
517 |
+ |
|
518 |
+ |
for(int i = 0; i < natomInRb1; i++){ |
519 |
+ |
atomIndex1 = rbStamp1->getMember(i); |
520 |
+ |
|
521 |
+ |
for(int j= 0; j < natomInRb1; j++){ |
522 |
+ |
atomIndex2 = rbStamp2->getMember(j); |
523 |
+ |
|
524 |
+ |
if(atomIndex1 == atomIndex2){ |
525 |
+ |
jointAtomIndexPair.push_back(make_pair(i, j)); |
526 |
+ |
break; |
527 |
+ |
} |
528 |
+ |
|
529 |
+ |
}//end for(j =0) |
530 |
+ |
|
531 |
+ |
}//end for (i = 0) |
532 |
+ |
|
533 |
+ |
return jointAtomIndexPair; |
534 |
+ |
} |