| 1 | /* | 
|---|
| 2 | * analysis_bonds.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Nov 7, 2009 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #include "analysis_bonds.hpp" | 
|---|
| 9 | #include "atom.hpp" | 
|---|
| 10 | #include "bond.hpp" | 
|---|
| 11 | #include "log.hpp" | 
|---|
| 12 | #include "molecule.hpp" | 
|---|
| 13 |  | 
|---|
| 14 | /** Calculates the min, mean and maximum bond counts for the given molecule. | 
|---|
| 15 | * \param *mol molecule with atoms and atom::ListOfBonds | 
|---|
| 16 | * \param &Min minimum count on return | 
|---|
| 17 | * \param &Mean mean count on return | 
|---|
| 18 | * \param &Max maximum count on return | 
|---|
| 19 | */ | 
|---|
| 20 | void GetMaxMinMeanBondCount(const molecule * const mol, double &Min, double &Mean, double &Max) | 
|---|
| 21 | { | 
|---|
| 22 | Min = 2e+6; | 
|---|
| 23 | Max = -2e+5; | 
|---|
| 24 | Mean = 0.; | 
|---|
| 25 |  | 
|---|
| 26 | atom *Walker = mol->start; | 
|---|
| 27 | int AtomCount = 0; | 
|---|
| 28 | while (Walker->next != mol->end) { | 
|---|
| 29 | Walker = Walker->next; | 
|---|
| 30 | const int count = Walker->ListOfBonds.size(); | 
|---|
| 31 | if (Max < count) | 
|---|
| 32 | Max = count; | 
|---|
| 33 | if (Min > count) | 
|---|
| 34 | Min = count; | 
|---|
| 35 | Mean += count; | 
|---|
| 36 | AtomCount++; | 
|---|
| 37 | } | 
|---|
| 38 | if (((int)Mean % 2) != 0) | 
|---|
| 39 | eLog() << Verbose(1) << "Something is wrong with the bond structure, the number of bonds is not even!" << endl; | 
|---|
| 40 | Mean /= (double)AtomCount; | 
|---|
| 41 | }; | 
|---|
| 42 |  | 
|---|
| 43 | /** Calculates the min and max bond distance of all atoms of two given elements. | 
|---|
| 44 | * \param *mol molecule with atoms | 
|---|
| 45 | * \param *type1 one element | 
|---|
| 46 | * \param *type2 other element | 
|---|
| 47 | * \param &Min minimum distance on return, 0 if no bond between the two elements | 
|---|
| 48 | * \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 | 
|---|
| 49 | * \param &Max maximum distance on return, 0 if no bond between the two elements | 
|---|
| 50 | */ | 
|---|
| 51 | void MinMeanMaxBondDistanceBetweenElements(const molecule *mol, element *type1, element *type2, double &Min, double &Mean, double &Max) | 
|---|
| 52 | { | 
|---|
| 53 | Min = 2e+6; | 
|---|
| 54 | Mean = 0.; | 
|---|
| 55 | Max = -2e+6; | 
|---|
| 56 |  | 
|---|
| 57 | int AtomNo = 0; | 
|---|
| 58 | atom *Walker = mol->start; | 
|---|
| 59 | while (Walker->next != mol->end) { | 
|---|
| 60 | Walker = Walker->next; | 
|---|
| 61 | if (Walker->type == type1) | 
|---|
| 62 | for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) | 
|---|
| 63 | if ((*BondRunner)->GetOtherAtom(Walker)->type == type2) { | 
|---|
| 64 | const double distance = (*BondRunner)->GetDistanceSquared(); | 
|---|
| 65 | if (Min > distance) | 
|---|
| 66 | Min = distance; | 
|---|
| 67 | if (Max < distance) | 
|---|
| 68 | Max = distance; | 
|---|
| 69 | Mean += sqrt(distance); | 
|---|
| 70 | AtomNo++; | 
|---|
| 71 | } | 
|---|
| 72 | } | 
|---|
| 73 | if (Max < 0) { | 
|---|
| 74 | Max = Min = 0.; | 
|---|
| 75 | } else { | 
|---|
| 76 | Max = sqrt(Max); | 
|---|
| 77 | Min = sqrt(Min); | 
|---|
| 78 | Mean = Mean/(double)AtomNo; | 
|---|
| 79 | } | 
|---|
| 80 | }; | 
|---|