Changeset 7e4dc3f for molecuilder/src


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@…>

Location:
molecuilder/src
Files:
3 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};
  • molecuilder/src/bondgraph.hpp

    rac86192 r7e4dc3f  
    5656
    5757int CountHydrogenBridgeBonds(MoleculeListClass * const molecules, element * InterfaceElement);
     58int CountBondsOfTwo(MoleculeListClass * const molecules, const element * const first, const element * const second);
     59int CountBondsOfThree(MoleculeListClass * const molecules, const element * const first, const element * const second, const element * const third);
    5860
    5961#endif /* BONDGRAPH_HPP_ */
  • molecuilder/src/builder.cpp

    rac86192 r7e4dc3f  
    10891089  Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
    10901090  Log() << Verbose(0) << "a - simple add of one molecule to another" << endl;
     1091  Log() << Verbose(0) << "b - count the number of bonds of two elements" << endl;
     1092  Log() << Verbose(0) << "B - count the number of bonds of three elements " << endl;
    10911093  Log() << Verbose(0) << "e - embedding merge of two molecules" << endl;
    10921094  Log() << Verbose(0) << "h - count the number of hydrogen bonds" << endl;
     1095  Log() << Verbose(0) << "b - count the number of hydrogen bonds" << endl;
    10931096  Log() << Verbose(0) << "m - multi-merge of all molecules" << endl;
    10941097  Log() << Verbose(0) << "s - scatter merge of two molecules" << endl;
     
    11241127      }
    11251128      break;
     1129
     1130    case 'b':
     1131      {
     1132        const int nr = 2;
     1133        char *names[nr] = {"first", "second"};
     1134        int Z[nr];
     1135        element *elements[nr];
     1136        for (int i=0;i<nr;i++) {
     1137          Z[i] = 0;
     1138          do {
     1139            cout << "Enter " << names[i] << " element: ";
     1140            cin >> Z[i];
     1141          } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
     1142          elements[i] = periode->FindElement(Z[i]);
     1143        }
     1144        const int count = CountBondsOfTwo(molecules, elements[0], elements[1]);
     1145        cout << endl << "There are " << count << " ";
     1146        for (int i=0;i<nr;i++) {
     1147          if (i==0)
     1148            cout << elements[i]->symbol;
     1149          else
     1150            cout << "-" << elements[i]->symbol;
     1151        }
     1152        cout << " bonds." << endl;
     1153      }
     1154    break;
     1155
     1156    case 'B':
     1157      {
     1158        const int nr = 3;
     1159        char *names[nr] = {"first", "second", "third"};
     1160        int Z[nr];
     1161        element *elements[nr];
     1162        for (int i=0;i<nr;i++) {
     1163          Z[i] = 0;
     1164          do {
     1165            cout << "Enter " << names[i] << " element: ";
     1166            cin >> Z[i];
     1167          } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
     1168          elements[i] = periode->FindElement(Z[i]);
     1169        }
     1170        const int count = CountBondsOfThree(molecules, elements[0], elements[1], elements[2]);
     1171        cout << endl << "There are " << count << " ";
     1172        for (int i=0;i<nr;i++) {
     1173          if (i==0)
     1174            cout << elements[i]->symbol;
     1175          else
     1176            cout << "-" << elements[i]->symbol;
     1177        }
     1178        cout << " bonds." << endl;
     1179      }
     1180    break;
    11261181
    11271182    case 'e':
Note: See TracChangeset for help on using the changeset viewer.