ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/MoleculeStamp.cpp
(Generate patch)

Comparing trunk/OOPSE/libBASS/MoleculeStamp.cpp (file contents):
Revision 988 by gezelter, Tue Jan 27 19:37:48 2004 UTC vs.
Revision 1256 by gezelter, Thu Jun 10 14:59:14 2004 UTC

# Line 14 | Line 14 | MoleculeStamp::MoleculeStamp(){
14    n_bends = 0;
15    n_torsions = 0;
16    n_rigidbodies = 0;
17 +  n_cutoffgroups = 0;
18 +  n_integrable = 0;
19  
20    unhandled = NULL;
21    atoms = NULL;
# Line 21 | Line 23 | MoleculeStamp::MoleculeStamp(){
23    bends = NULL;
24    torsions = NULL;
25    rigidBodies = NULL;
26 +  cutoffGroups = NULL;
27  
28    have_name = 0;
29    have_atoms = 0;
# Line 28 | Line 31 | MoleculeStamp::MoleculeStamp(){
31    have_bends = 0;
32    have_torsions = 0;
33    have_rigidbodies = 0;
34 +  have_cutoffgroups = 0;
35  
36   }
37  
# Line 39 | Line 43 | MoleculeStamp::~MoleculeStamp(){
43    if( rigidBodies != NULL ) {
44      for( i=0; i<n_rigidbodies; i++ ) delete rigidBodies[i];
45    }
46 +  delete[] rigidBodies;
47 +
48 +  if( cutoffGroups != NULL ) {
49 +    for( i=0; i<n_cutoffgroups; i++ ) delete cutoffGroups[i];
50 +  }
51 +  delete[] cutoffGroups;
52    
53    if( atoms != NULL ){
54      for( i=0; i<n_atoms; i++ ) delete atoms[i];
55    }
56 +  delete[] atoms;
57    
58    if( bonds != NULL ){
59      for( i=0; i<n_bonds; i++ ) delete bonds[i];
60    }
61 +  delete[] bonds;
62    
63    if( bends != NULL ){
64      for( i=0; i<n_bends; i++ ) delete bends[i];
65    }
66 +  delete[] bends;
67    
68    if( torsions != NULL ){
69      for( i=0; i<n_torsions; i++ ) delete torsions[i];
70    }
71 +  delete[] torsions;
72    
73 +
74 +
75 +
76   }
77  
78   char* MoleculeStamp::assignString( char* lhs, char* rhs ){
# Line 150 | Line 167 | char* MoleculeStamp::assignDouble( char* lhs, double r
167      for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
168    }
169  
170 +  else if( !strcmp( lhs, "nCutoffGroups" ) ){
171 +    n_cutoffgroups = (int)rhs;
172 +
173 +    if( have_cutoffgroups ){
174 +      sprintf( errMsg,
175 +               "MoleculeStamp error, n_cutoffgroups already declared for"
176 +               " molecule: %s\n",
177 +               name );
178 +      return strdup( errMsg );
179 +    }
180 +    have_cutoffgroups = 1;
181 +    cutoffGroups = new CutoffGroupStamp*[n_cutoffgroups];
182 +    for( i=0; i<n_cutoffgroups; i++ ) cutoffGroups[i] = NULL;
183 +  }
184 +  
185    else{
186      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
187      else unhandled->add( lhs, rhs );
# Line 226 | Line 258 | char*  MoleculeStamp::assignInt( char* lhs, int rhs ){
258  
259      if( have_rigidbodies ){
260        sprintf( errMsg,
261 <               "RigidBodyStamp error, n_rigidbodies already declared for"
261 >               "MoleculeStamp error, n_rigidbodies already declared for"
262                 " molecule: %s\n",
263                 name);
264        return strdup( errMsg );
# Line 235 | Line 267 | char*  MoleculeStamp::assignInt( char* lhs, int rhs ){
267      rigidBodies = new RigidBodyStamp*[n_rigidbodies];
268      for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
269    }
270 +  else if( !strcmp( lhs, "nCutoffGroups" ) ){
271 +    n_cutoffgroups = rhs;
272 +
273 +    if( have_cutoffgroups ){
274 +      sprintf( errMsg,
275 +               "MoleculeStamp error, n_cutoffgroups already declared for"
276 +               " molecule: %s\n",
277 +               name);
278 +      return strdup( errMsg );
279 +    }
280 +    have_cutoffgroups = 1;
281 +    cutoffGroups = new CutoffGroupStamp*[n_cutoffgroups];
282 +    for( i=0; i<n_cutoffgroups; i++ ) cutoffGroups[i] = NULL;
283 +  }
284    else{
285      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
286      else unhandled->add( lhs, rhs );
# Line 246 | Line 292 | char* MoleculeStamp::addAtom( AtomStamp* the_atom, int
292   char* MoleculeStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
293    
294    if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
295 <  else{
295 >  else {
296      if( have_atoms ){
297        sprintf( errMsg, "MoleculeStamp error, %d out of nAtoms range",
298                 atomIndex );
# Line 262 | Line 308 | char* MoleculeStamp::addRigidBody( RigidBodyStamp* the
308   char* MoleculeStamp::addRigidBody( RigidBodyStamp* the_rigidbody,
309                                     int rigidBodyIndex ){
310    
311 +
312 +  printf("rigidBodyIndex = %d\n", rigidBodyIndex);
313    if( have_rigidbodies && rigidBodyIndex < n_rigidbodies )
314      rigidBodies[rigidBodyIndex] = the_rigidbody;
315 <  else{
315 >  else {
316      if( have_rigidbodies ){
317        sprintf( errMsg, "MoleculeStamp error, %d out of nRigidBodies range",
318                 rigidBodyIndex );
# Line 277 | Line 325 | char* MoleculeStamp::addBond( BondStamp* the_bond, int
325    return NULL;
326   }
327  
328 + char* MoleculeStamp::addCutoffGroup( CutoffGroupStamp* the_cutoffgroup,
329 +                                     int cutoffGroupIndex ){
330 +  
331 +  if( have_cutoffgroups && cutoffGroupIndex < n_cutoffgroups )
332 +    cutoffGroups[cutoffGroupIndex] = the_cutoffgroup;
333 +  else {
334 +    if( have_cutoffgroups ){
335 +      sprintf( errMsg, "MoleculeStamp error, %d out of nCutoffGroups range",
336 +               cutoffGroupIndex );
337 +      return strdup( errMsg );
338 +    }
339 +    else return strdup("MoleculeStamp error, nCutoffGroups not given before"
340 +                       " first CutoffGroup declaration." );
341 +  }
342 +  
343 +  return NULL;
344 + }
345 +
346   char* MoleculeStamp::addBond( BondStamp* the_bond, int bondIndex ){
347    
348    
# Line 332 | Line 398 | char* MoleculeStamp::checkMe( void ){
398   char* MoleculeStamp::checkMe( void ){
399    
400    int i;
401 <  short int no_atom, no_rigidbody;
401 >  short int no_atom, no_rigidbody, no_cutoffgroup;
402  
403    if( !have_name ) return strdup( "MoleculeStamp error. Molecule's name"
404                                    " was not given.\n" );
# Line 353 | Line 419 | char* MoleculeStamp::checkMe( void ){
419      return strdup( errMsg );
420    }
421  
422 +  no_cutoffgroup = 0;
423 +  for( i=0; i<n_cutoffgroups; i++ ){
424 +    if( cutoffGroups[i] == NULL ) no_cutoffgroup = 1;
425 +  }
426 +
427 +  if( no_cutoffgroup ){
428 +    sprintf( errMsg,
429 +             "MoleculeStamp error. Not all of the CutoffGroups were"
430 +             " declared in molecule \"%s\".\n", name );
431 +    return strdup( errMsg );
432 +  }
433 +  
434    no_atom = 0;
435    for( i=0; i<n_atoms; i++ ){
436      if( atoms[i] == NULL ) no_atom = 1;
# Line 365 | Line 443 | char* MoleculeStamp::checkMe( void ){
443      return strdup( errMsg );
444    }
445  
446 +  n_integrable = n_atoms;
447 +  for (i = 0; i < n_rigidbodies; i++)
448 +    n_integrable = n_integrable - rigidBodies[i]->getNMembers() + 1; //rigidbody is an integrable object
449 +  
450 +  if (n_integrable <= 0 || n_integrable > n_atoms) {
451 +    sprintf( errMsg,
452 +             "MoleculeStamp error. n_integrable is either <= 0 or"
453 +             " greater than n_atoms in molecule \"%s\".\n", name );
454 +    return strdup( errMsg );
455 +  }
456 +
457    return NULL;
458   }  
459 +
460 +
461 + //Function Name: isBondInSameRigidBody
462 + //Return true is both atoms of the bond belong to the same rigid body, otherwise return false
463 + bool MoleculeStamp::isBondInSameRigidBody(BondStamp* bond){
464 +  int rbA;
465 +  int rbB;
466 +  int consAtomA;
467 +  int consAtomB;
468 +
469 +  return isAtomInRigidBody(bond->getA(),rbA, consAtomA) &&
470 +                isAtomInRigidBody(bond->getB(),rbB, consAtomB);
471 + }
472 +
473 +
474 + // Function Name isAtomInRigidBody
475 + //return false if atom does not belong to a rigid body otherwise return true and set whichRigidBody
476 + //and consAtomIndex
477 + //atomIndex : the index of atom in component
478 + //whichRigidBody: the index of rigidbody in component
479 + //consAtomIndex:  the position of joint atom apears in  rigidbody's definition
480 + bool MoleculeStamp::isAtomInRigidBody(int atomIndex, int& whichRigidBody, int& consAtomIndex){
481 +  RigidBodyStamp* rbStamp;
482 +  int numRb;
483 +  int numAtom;
484 +
485 +  numRb = this->getNRigidBodies();
486 +  
487 +  for(int i = 0 ; i < numRb; i++){
488 +    rbStamp = this->getRigidBody(i);
489 +    numAtom = rbStamp->getNMembers();
490 +    for(int j = 0; j < numAtom; j++)
491 +      if (rbStamp->getMember(j) == atomIndex){
492 +        whichRigidBody = i;
493 +        consAtomIndex = j;
494 +        return true;
495 +      }
496 +  }
497 +
498 +  return false;
499 +  
500 + }
501 +
502 + //return the position of joint atom apears in  rigidbody's definition
503 + //for the time being, we will use the most inefficient algorithm, the complexity is O(N2)
504 + //actually we could improve the complexity to O(NlgN) by sorting the atom index in rigid body first
505 + vector<pair<int, int> > MoleculeStamp::getJointAtoms(int rb1, int rb2){
506 +  RigidBodyStamp* rbStamp1;
507 +  RigidBodyStamp* rbStamp2;
508 +  int natomInRb1;
509 +  int natomInRb2;
510 +  int atomIndex1;
511 +  int atomIndex2;
512 +  vector<pair<int, int> > jointAtomIndexPair;
513 +  
514 +  rbStamp1 = this->getRigidBody(rb1);
515 +  natomInRb1 =rbStamp1->getNMembers();
516 +
517 +  rbStamp2 = this->getRigidBody(rb2);
518 +  natomInRb2 =rbStamp2->getNMembers();
519 +
520 +  for(int i = 0; i < natomInRb1; i++){
521 +    atomIndex1 = rbStamp1->getMember(i);
522 +      
523 +    for(int j= 0; j < natomInRb1; j++){
524 +      atomIndex2 = rbStamp2->getMember(j);
525 +
526 +      if(atomIndex1 == atomIndex2){
527 +        jointAtomIndexPair.push_back(make_pair(i, j));
528 +        break;
529 +      }
530 +      
531 +    }//end for(j =0)
532 +
533 +  }//end for (i = 0)
534 +
535 +  return jointAtomIndexPair;
536 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines