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 | int AtomCount = 0;
|
---|
27 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
28 | const int count = (*iter)->ListOfBonds.size();
|
---|
29 | if (Max < count)
|
---|
30 | Max = count;
|
---|
31 | if (Min > count)
|
---|
32 | Min = count;
|
---|
33 | Mean += count;
|
---|
34 | AtomCount++;
|
---|
35 | }
|
---|
36 | if (((int)Mean % 2) != 0)
|
---|
37 | eLog() << Verbose(1) << "Something is wrong with the bond structure, the number of bonds is not even!" << endl;
|
---|
38 | Mean /= (double)AtomCount;
|
---|
39 | };
|
---|
40 |
|
---|
41 | /** Calculates the min and max bond distance of all atoms of two given elements.
|
---|
42 | * \param *mol molecule with atoms
|
---|
43 | * \param *type1 one element
|
---|
44 | * \param *type2 other element
|
---|
45 | * \param &Min minimum distance on return, 0 if no bond between the two elements
|
---|
46 | * \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
|
---|
47 | * \param &Max maximum distance on return, 0 if no bond between the two elements
|
---|
48 | */
|
---|
49 | void MinMeanMaxBondDistanceBetweenElements(const molecule *mol, element *type1, element *type2, double &Min, double &Mean, double &Max)
|
---|
50 | {
|
---|
51 | Min = 2e+6;
|
---|
52 | Mean = 0.;
|
---|
53 | Max = -2e+6;
|
---|
54 |
|
---|
55 | int AtomNo = 0;
|
---|
56 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
57 | if ((*iter)->type == type1)
|
---|
58 | for (BondList::const_iterator BondRunner = (*iter)->ListOfBonds.begin(); BondRunner != (*iter)->ListOfBonds.end(); BondRunner++)
|
---|
59 | if ((*BondRunner)->GetOtherAtom((*iter))->type == type2) {
|
---|
60 | const double distance = (*BondRunner)->GetDistanceSquared();
|
---|
61 | if (Min > distance)
|
---|
62 | Min = distance;
|
---|
63 | if (Max < distance)
|
---|
64 | Max = distance;
|
---|
65 | Mean += sqrt(distance);
|
---|
66 | AtomNo++;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | if (Max < 0) {
|
---|
70 | Max = Min = 0.;
|
---|
71 | } else {
|
---|
72 | Max = sqrt(Max);
|
---|
73 | Min = sqrt(Min);
|
---|
74 | Mean = Mean/(double)AtomNo;
|
---|
75 | }
|
---|
76 | };
|
---|