Ignore:
Timestamp:
Mar 18, 2010, 3:38:56 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
7e4dc3f
Parents:
800dc3
git-author:
Frederik Heber <heber@…> (03/18/10 15:29:54)
git-committer:
Frederik Heber <heber@…> (03/18/10 15:38:56)
Message:

Introduced CountHydrogenBridgeBonds() function.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/bondgraph.cpp

    r800dc3 rac86192  
    99
    1010#include "atom.hpp"
     11#include "bond.hpp"
    1112#include "bondgraph.hpp"
    1213#include "element.hpp"
     
    8687bool BondGraph::ConstructBondGraph(molecule * const mol)
    8788{
    88   bool status = true;
     89  Info FunctionInfo(__func__);
     90bool status = true;
    8991
    9092  if (mol->start->next == mol->end) // only construct if molecule is not empty
     
    119121double BondGraph::SetMaxDistanceToMaxOfCovalentRadii(const molecule * const mol)
    120122{
     123  Info FunctionInfo(__func__);
    121124  max_distance = 0.;
    122125
     
    169172};
    170173
     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 */
     180int CountHydrogenBridgeBonds(MoleculeListClass *molecules, element * InterfaceElement = NULL)
     181{
     182  Info FunctionInfo(__func__);
     183  atom *Walker = NULL;
     184  atom *Runner = NULL;
     185  atom *Hydrogen = NULL;
     186  atom *OtherHydrogen = NULL;
     187  Vector OHBond;
     188  Vector OOBond;
     189  int count = 0;
     190  bool HydrogenFlag = false;
     191  bool OtherHydrogenFlag = false;
     192  bool InterfaceFlag = false;
     193  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
     194    Walker = (*MolWalker)->start;
     195    while (Walker->next != (*MolWalker)->end) {
     196      Walker = Walker->next;
     197      for (MoleculeList::const_iterator MolRunner = molecules->ListOfMolecules.begin();MolRunner != molecules->ListOfMolecules.end(); MolRunner++) {
     198        Runner = (*MolRunner)->start;
     199        while (Runner->next != (*MolRunner)->end) {
     200          Runner = Runner->next;
     201          if ((Runner != Walker) && (Walker->type->Z  == 8) && (Runner->type->Z  == 8)) {
     202            // check distance
     203            const double distance = Runner->x.DistanceSquared(&Walker->x);
     204            if (distance < HBRIDGEDISTANCE*HBRIDGEDISTANCE) {
     205              // get hydrogen, check for InterfaceElement
     206              HydrogenFlag = false;
     207              OtherHydrogenFlag = false;
     208              InterfaceFlag = (InterfaceElement == NULL);
     209              // on other atom(Runner) we check for bond to interface element
     210              for (BondList::const_iterator BondRunner = Runner->ListOfBonds.begin(); BondRunner != Runner->ListOfBonds.end(); BondRunner++) {
     211                atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     212                if (!OtherHydrogenFlag && (OtherAtom->type->Z == 1)) {
     213                  OtherHydrogen = OtherAtom;
     214                  OtherHydrogen = true;
     215                }
     216                InterfaceFlag = InterfaceFlag || (OtherAtom->type == InterfaceElement);
     217              }
     218              // on this element (Walker) we check for bond to hydrogen, i.e. part of water molecule
     219              for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
     220                atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     221                if (!HydrogenFlag && (OtherAtom->type->Z == 1)) {
     222                  Hydrogen = OtherAtom;
     223                  HydrogenFlag = true;
     224                }
     225              }
     226              if (InterfaceFlag && HydrogenFlag) {
     227                if ((Walker->nr < Runner->nr) || (!OtherHydrogenFlag)) {
     228                  // check angle
     229                  OHBond.CopyVector(&Walker->x);
     230                  OHBond.SubtractVector(&Hydrogen->x);
     231                  OOBond.CopyVector(&Runner->x);
     232                  OOBond.SubtractVector(&Walker->x);
     233                  const double angle = OHBond.Angle(&OOBond);
     234                  if (angle < M_PI*(30./180.)) {
     235                    DoLog(1) && (Log() << Verbose(1) << Walker->Name << ", " << Hydrogen->Name << " and " << Runner->Name << " have a hydrogen bridge bond with " << sqrt(distance) << " and at angle " << (180./M_PI)*angle << " degrees." << endl);
     236                    count++;
     237                  }
     238                }
     239              }
     240            }
     241          }
     242        }
     243      }
     244    }
     245  }
     246  return count;
     247}
Note: See TracChangeset for help on using the changeset viewer.