1 | /*
|
---|
2 | * bondgraph.cpp
|
---|
3 | *
|
---|
4 | * Created on: Oct 29, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <iostream>
|
---|
9 |
|
---|
10 | #include "atom.hpp"
|
---|
11 | #include "bondgraph.hpp"
|
---|
12 | #include "element.hpp"
|
---|
13 | #include "molecule.hpp"
|
---|
14 | #include "parser.hpp"
|
---|
15 | #include "vector.hpp"
|
---|
16 |
|
---|
17 | /** Constructor of class BondGraph.
|
---|
18 | * This classes contains typical bond lengths and thus may be used to construct a bond graph for a given molecule.
|
---|
19 | */
|
---|
20 | BondGraph::BondGraph(bool IsA) : BondLengthMatrix(NULL), IsAngstroem(IsA)
|
---|
21 | {
|
---|
22 | };
|
---|
23 |
|
---|
24 | /** Destructor of class BondGraph.
|
---|
25 | */
|
---|
26 | BondGraph::~BondGraph()
|
---|
27 | {
|
---|
28 | if (BondLengthMatrix != NULL) {
|
---|
29 | delete(BondLengthMatrix);
|
---|
30 | }
|
---|
31 | };
|
---|
32 |
|
---|
33 | /** Parses the bond lengths in a given file and puts them int a matrix form.
|
---|
34 | * Allocates \a MatrixContainer and uses MatrixContainer::ParseMatrix().
|
---|
35 | * \param *out output stream for debugging
|
---|
36 | * \param filename file with bond lengths to parse
|
---|
37 | * \return true - success in parsing file, false - failed to parse the file
|
---|
38 | */
|
---|
39 | bool BondGraph::LoadBondLengthTable(ofstream * const out, const string &filename)
|
---|
40 | {
|
---|
41 | bool status = true;
|
---|
42 |
|
---|
43 | // allocate MatrixContainer
|
---|
44 | if (BondLengthMatrix != NULL) {
|
---|
45 | *out << "MatrixContainer for Bond length already present, removing." << endl;
|
---|
46 | delete(BondLengthMatrix);
|
---|
47 | }
|
---|
48 | BondLengthMatrix = new MatrixContainer;
|
---|
49 |
|
---|
50 | // parse in matrix
|
---|
51 | BondLengthMatrix->ParseMatrix(filename.c_str(), 0, 1, 0);
|
---|
52 |
|
---|
53 | // find greatest distance
|
---|
54 | max_distance=0;
|
---|
55 | for(int i=0;i<BondLengthMatrix->RowCounter[0];i++)
|
---|
56 | for(int j=i;j<BondLengthMatrix->ColumnCounter[0];j++)
|
---|
57 | if (BondLengthMatrix->Matrix[0][i][j] > max_distance)
|
---|
58 | max_distance = BondLengthMatrix->Matrix[0][i][j];
|
---|
59 |
|
---|
60 | return status;
|
---|
61 | };
|
---|
62 |
|
---|
63 | /** Parses the bond lengths in a given file and puts them int a matrix form.
|
---|
64 | * \param *out output stream for debugging
|
---|
65 | * \param *mol molecule with atoms
|
---|
66 | * \return true - success, false - failed to construct bond structure
|
---|
67 | */
|
---|
68 | bool BondGraph::ConstructBondGraph(ofstream * const out, molecule * const mol)
|
---|
69 | {
|
---|
70 | bool status = true;
|
---|
71 |
|
---|
72 | if (BondLengthMatrix == NULL)
|
---|
73 | return false;
|
---|
74 | mol->CreateAdjacencyList(out, max_distance, IsAngstroem, &BondGraph::BondLengthMatrixMinMaxDistance, this);
|
---|
75 |
|
---|
76 | return status;
|
---|
77 | };
|
---|
78 |
|
---|
79 | /** Returns the entry for a given index pair.
|
---|
80 | * \param firstelement index/atom number of first element (row index)
|
---|
81 | * \param secondelement index/atom number of second element (column index)
|
---|
82 | * \note matrix is of course symmetric.
|
---|
83 | */
|
---|
84 | double BondGraph::GetBondLength(int firstZ, int secondZ)
|
---|
85 | {
|
---|
86 | return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
|
---|
87 | };
|
---|
88 |
|
---|
89 | /** Returns bond criterion for given pair based on covalent radius.
|
---|
90 | * \param *Walker first BondedParticle
|
---|
91 | * \param *OtherWalker second BondedParticle
|
---|
92 | * \param &MinDistance lower bond bound on return
|
---|
93 | * \param &MaxDistance upper bond bound on return
|
---|
94 | * \param IsAngstroem whether units are in angstroem or bohr radii
|
---|
95 | */
|
---|
96 | void BondGraph::CovalentMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
|
---|
97 | {
|
---|
98 | MinDistance = OtherWalker->type->CovalentRadius + Walker->type->CovalentRadius;
|
---|
99 | MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
|
---|
100 | MaxDistance = MinDistance + BONDTHRESHOLD;
|
---|
101 | MinDistance -= BONDTHRESHOLD;
|
---|
102 | };
|
---|
103 |
|
---|
104 | /** Returns bond criterion for given pair based on a bond length matrix.
|
---|
105 | * The matrix should be contained in \a this BondGraph and contain an element-
|
---|
106 | * to-element length.
|
---|
107 | * \param *Walker first BondedParticle
|
---|
108 | * \param *OtherWalker second BondedParticle
|
---|
109 | * \param &MinDistance lower bond bound on return
|
---|
110 | * \param &MaxDistance upper bond bound on return
|
---|
111 | * \param IsAngstroem whether units are in angstroem or bohr radii
|
---|
112 | */
|
---|
113 | void BondGraph::BondLengthMatrixMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
|
---|
114 | {
|
---|
115 | if (BondLengthMatrix->Matrix == NULL) {// safety measure if no matrix has been parsed yet
|
---|
116 | cerr << Verbose(1) << "WARNING: BondLengthMatrixMinMaxDistance() called without having parsed the bond length matrix yet!" << endl;
|
---|
117 | CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
|
---|
118 | } else {
|
---|
119 | MinDistance = GetBondLength(Walker->type->Z-1, OtherWalker->type->Z-1);
|
---|
120 | MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
|
---|
121 | MaxDistance = MinDistance + BONDTHRESHOLD;
|
---|
122 | MinDistance -= BONDTHRESHOLD;
|
---|
123 | }
|
---|
124 | };
|
---|
125 |
|
---|