/* * analysis_bonds.cpp * * Created on: Nov 7, 2009 * Author: heber */ #include "analysis_bonds.hpp" #include "atom.hpp" #include "bond.hpp" #include "log.hpp" #include "molecule.hpp" /** Calculates the min, mean and maximum bond counts for the given molecule. * \param *mol molecule with atoms and atom::ListOfBonds * \param &Min minimum count on return * \param &Mean mean count on return * \param &Max maximum count on return */ void GetMaxMinMeanBondCount(const molecule * const mol, double &Min, double &Mean, double &Max) { Min = 2e+6; Max = -2e+5; Mean = 0.; atom *Walker = mol->start; int AtomCount = 0; while (Walker->next != mol->end) { Walker = Walker->next; const int count = Walker->ListOfBonds.size(); if (Max < count) Max = count; if (Min > count) Min = count; Mean += count; AtomCount++; } if (((int)Mean % 2) != 0) eLog() << Verbose(1) << "Something is wrong with the bond structure, the number of bonds is not even!" << endl; Mean /= (double)AtomCount; }; /** Calculates the min and max bond distance of all atoms of two given elements. * \param *mol molecule with atoms * \param *type1 one element * \param *type2 other element * \param &Min minimum distance on return, 0 if no bond between the two elements * \param &Mean mean distance (i.e. sum of distance for matching element pairs, divided by number) on return, 0 if no bond between the two elements * \param &Max maximum distance on return, 0 if no bond between the two elements */ void MinMeanMaxBondDistanceBetweenElements(const molecule *mol, element *type1, element *type2, double &Min, double &Mean, double &Max) { Min = 2e+6; Mean = 0.; Max = -2e+6; int AtomNo = 0; atom *Walker = mol->start; while (Walker->next != mol->end) { Walker = Walker->next; if (Walker->type == type1) for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) if ((*BondRunner)->GetOtherAtom(Walker)->type == type2) { const double distance = (*BondRunner)->GetDistanceSquared(); if (Min > distance) Min = distance; if (Max < distance) Max = distance; Mean += sqrt(distance); AtomNo++; } } if (Max < 0) { Max = Min = 0.; } else { Max = sqrt(Max); Min = sqrt(Min); Mean = Mean/(double)AtomNo; } };