Ignore:
Timestamp:
Mar 19, 2010, 3:42:58 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
32526c
Parents:
ac86192
git-author:
Frederik Heber <heber@…> (03/19/10 14:03:54)
git-committer:
Frederik Heber <heber@…> (03/19/10 15:42:58)
Message:

Implemented counting of bonds over all atoms.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/bondgraph.cpp

    rac86192 r7e4dc3f  
    209209              // on other atom(Runner) we check for bond to interface element
    210210              for (BondList::const_iterator BondRunner = Runner->ListOfBonds.begin(); BondRunner != Runner->ListOfBonds.end(); BondRunner++) {
    211                 atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     211                atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Runner);
    212212                if (!OtherHydrogenFlag && (OtherAtom->type->Z == 1)) {
    213213                  OtherHydrogen = OtherAtom;
    214                   OtherHydrogen = true;
     214                  OtherHydrogenFlag = true;
    215215                }
    216216                InterfaceFlag = InterfaceFlag || (OtherAtom->type == InterfaceElement);
     
    227227                if ((Walker->nr < Runner->nr) || (!OtherHydrogenFlag)) {
    228228                  // check angle
    229                   OHBond.CopyVector(&Walker->x);
    230                   OHBond.SubtractVector(&Hydrogen->x);
     229                  OHBond.CopyVector(&Hydrogen->x);
     230                  OHBond.SubtractVector(&Walker->x);
    231231                  OOBond.CopyVector(&Runner->x);
    232232                  OOBond.SubtractVector(&Walker->x);
     
    246246  return count;
    247247}
     248
     249/** Counts the number of bonds between two given elements.
     250 * \param *molecules list of molecules with all atoms
     251 * \param *first pointer to first element
     252 * \param *second pointer to second element
     253 * \return number of found bonds (\a *first-\a *second)
     254 */
     255int CountBondsOfTwo(MoleculeListClass * const molecules, const element * const first, const element * const second)
     256{
     257  atom *Walker = NULL;
     258  int count = 0;
     259
     260  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
     261    Walker = (*MolWalker)->start;
     262    while (Walker->next != (*MolWalker)->end) {
     263      Walker = Walker->next;
     264      if ((Walker->type == first) || (Walker->type == second)) {  // first element matches
     265        for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
     266          atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     267          if (((OtherAtom->type == first) || (OtherAtom->type == second)) && (Walker->nr < OtherAtom->nr)) {
     268            count++;
     269            DoLog(1) && (Log() << Verbose(1) << first->name << "-" << second->name << " bond found between " << *Walker << " and " << *OtherAtom << "." << endl);
     270          }
     271        }
     272      }
     273    }
     274  }
     275  return count;
     276};
     277
     278/** Counts the number of bonds between three given elements.
     279 * Note that we do not look for arbitrary sequence of given bonds, but \a *second will be the central atom and we check
     280 * whether it has bonds to both \a *first and \a *third.
     281 * \param *molecules list of molecules with all atoms
     282 * \param *first pointer to first element
     283 * \param *second pointer to second element
     284 * \param *third pointer to third element
     285 * \return number of found bonds (\a *first-\a *second-\a *third, \a *third-\a *second-\a *first, respectively)
     286 */
     287int CountBondsOfThree(MoleculeListClass * const molecules, const element * const first, const element * const second, const element * const third)
     288{
     289  int count = 0;
     290  bool MatchFlag[2];
     291  bool result = false;
     292  atom *Walker = NULL;
     293  const element * ElementArray[2];
     294  ElementArray[0] = first;
     295  ElementArray[1] = third;
     296
     297  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
     298    Walker = (*MolWalker)->start;
     299    while (Walker->next != (*MolWalker)->end) {
     300      Walker = Walker->next;
     301      if (Walker->type == second) {  // first element matches
     302        for (int i=0;i<2;i++)
     303          MatchFlag[i] = false;
     304        for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
     305          atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     306          for (int i=0;i<2;i++)
     307            MatchFlag[i] = MatchFlag[i] || (OtherAtom->type == ElementArray[i]);
     308        }
     309        result = true;
     310        for (int i=0;i<2;i++)
     311          result = result && MatchFlag[i];
     312        if (result) {
     313          count++;
     314          DoLog(1) && (Log() << Verbose(1) << first->name << "-" << second->name << "-" << third->name << " bond found at " << *Walker << "." << endl);
     315        }
     316      }
     317    }
     318  }
     319  return count;
     320};
Note: See TracChangeset for help on using the changeset viewer.