Ignore:
Timestamp:
Apr 1, 2010, 1:49:25 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
6250e5
Parents:
768125
git-author:
Frederik Heber <heber@…> (04/01/10 12:42:07)
git-committer:
Frederik Heber <heber@…> (04/01/10 13:49:25)
Message:

Moved functions CountBondsOfTwo(), CountBondsOfThree() and CountHydrogenBridgeBonds() from bondgraph.cpp to analysis_bonds.cpp

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/bondgraph.cpp

    r768125 r794482  
    171171  }
    172172};
    173 
    174 /** Counts the number of hydrogen bridge bonds.
    175  * With \a *InterfaceElement an extra element can be specified that identifies some boundary.
    176  * Then, counting is for the h-bridges that connect to interface only.
    177  * \param *molecules molecules to count bonds
    178  * \param *InterfaceElement or NULL
    179  */
    180 int CountHydrogenBridgeBonds(MoleculeListClass *molecules, element * InterfaceElement = NULL)
    181 {
    182   Info FunctionInfo(__func__);
    183   atom *Walker = NULL;
    184   atom *Runner = NULL;
    185   Vector OHBond;
    186   Vector OOBond;
    187   int count = 0;
    188   bool InterfaceFlag = false;
    189   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
    190     Walker = (*MolWalker)->start;
    191     while (Walker->next != (*MolWalker)->end) {
    192       Walker = Walker->next;
    193       for (MoleculeList::const_iterator MolRunner = molecules->ListOfMolecules.begin();MolRunner != molecules->ListOfMolecules.end(); MolRunner++) {
    194         Runner = (*MolRunner)->start;
    195         while (Runner->next != (*MolRunner)->end) {
    196           Runner = Runner->next;
    197           if ((Runner != Walker) && (Walker->type->Z  == 8) && (Runner->type->Z  == 8)) {
    198             // check distance
    199             const double distance = Runner->x.DistanceSquared(&Walker->x);
    200             if ((distance > MYEPSILON) && (distance < HBRIDGEDISTANCE*HBRIDGEDISTANCE)) { // distance >0 means  different atoms
    201               InterfaceFlag = (InterfaceElement == NULL);
    202               // on other atom(Runner) we check for bond to interface element
    203               for (BondList::const_iterator BondRunner = Runner->ListOfBonds.begin(); ((!InterfaceFlag) && (BondRunner != Runner->ListOfBonds.end())); BondRunner++) {
    204                 atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Runner);
    205                 InterfaceFlag = InterfaceFlag || (OtherAtom->type == InterfaceElement);
    206               }
    207               if (InterfaceFlag) {
    208                 // on this element (Walker) we check for bond to hydrogen, i.e. part of water molecule
    209                 for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
    210                   atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
    211                   if (OtherAtom->type->Z == 1) {
    212                     // check angle
    213                     OHBond.CopyVector(&OtherAtom->x);
    214                     OHBond.SubtractVector(&Walker->x);
    215                     OOBond.CopyVector(&Runner->x);
    216                     OOBond.SubtractVector(&Walker->x);
    217                     const double angle = OHBond.Angle(&OOBond);
    218                     if (angle < M_PI*(30./180.)) {
    219                       DoLog(1) && (Log() << Verbose(1) << Walker->Name << ", " << OtherAtom->Name << " and " << Runner->Name << " have a hydrogen bridge bond with " << sqrt(distance) << " and at angle " << (180./M_PI)*angle << " degrees." << endl);
    220                       count++;
    221                       break;
    222                     }
    223                   }
    224                 }
    225               }
    226             }
    227           }
    228         }
    229       }
    230     }
    231   }
    232   return count;
    233 }
    234 
    235 /** Counts the number of bonds between two given elements.
    236  * \param *molecules list of molecules with all atoms
    237  * \param *first pointer to first element
    238  * \param *second pointer to second element
    239  * \return number of found bonds (\a *first-\a *second)
    240  */
    241 int CountBondsOfTwo(MoleculeListClass * const molecules, const element * const first, const element * const second)
    242 {
    243   atom *Walker = NULL;
    244   int count = 0;
    245 
    246   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
    247     Walker = (*MolWalker)->start;
    248     while (Walker->next != (*MolWalker)->end) {
    249       Walker = Walker->next;
    250       if ((Walker->type == first) || (Walker->type == second)) {  // first element matches
    251         for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
    252           atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
    253           if (((OtherAtom->type == first) || (OtherAtom->type == second)) && (Walker->nr < OtherAtom->nr)) {
    254             count++;
    255             DoLog(1) && (Log() << Verbose(1) << first->name << "-" << second->name << " bond found between " << *Walker << " and " << *OtherAtom << "." << endl);
    256           }
    257         }
    258       }
    259     }
    260   }
    261   return count;
    262 };
    263 
    264 /** Counts the number of bonds between three given elements.
    265  * Note that we do not look for arbitrary sequence of given bonds, but \a *second will be the central atom and we check
    266  * whether it has bonds to both \a *first and \a *third.
    267  * \param *molecules list of molecules with all atoms
    268  * \param *first pointer to first element
    269  * \param *second pointer to second element
    270  * \param *third pointer to third element
    271  * \return number of found bonds (\a *first-\a *second-\a *third, \a *third-\a *second-\a *first, respectively)
    272  */
    273 int CountBondsOfThree(MoleculeListClass * const molecules, const element * const first, const element * const second, const element * const third)
    274 {
    275   int count = 0;
    276   bool MatchFlag[2];
    277   bool result = false;
    278   atom *Walker = NULL;
    279   const element * ElementArray[2];
    280   ElementArray[0] = first;
    281   ElementArray[1] = third;
    282 
    283   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
    284     Walker = (*MolWalker)->start;
    285     while (Walker->next != (*MolWalker)->end) {
    286       Walker = Walker->next;
    287       if (Walker->type == second) {  // first element matches
    288         for (int i=0;i<2;i++)
    289           MatchFlag[i] = false;
    290         for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
    291           atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
    292           for (int i=0;i<2;i++)
    293             if ((!MatchFlag[i]) && (OtherAtom->type == ElementArray[i])) {
    294               MatchFlag[i] = true;
    295               break;  // each bonding atom can match at most one element we are looking for
    296             }
    297         }
    298         result = true;
    299         for (int i=0;i<2;i++) // gather results
    300           result = result && MatchFlag[i];
    301         if (result) { // check results
    302           count++;
    303           DoLog(1) && (Log() << Verbose(1) << first->name << "-" << second->name << "-" << third->name << " bond found at " << *Walker << "." << endl);
    304         }
    305       }
    306     }
    307   }
    308   return count;
    309 };
Note: See TracChangeset for help on using the changeset viewer.