source: src/bondgraph.cpp@ 5b4605

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 5b4605 was 88b400, checked in by Frederik Heber <heber@…>, 15 years ago

converted #define's to enums, consts and typedefs [Meyers, "Effective C++", item 1].

basic changes:

  • #define bla 1.3 -> const double bla = 1.3
  • #define bla "test" -> const char * const bla = "test
  • use class specific constants! (HULLEPSILON)

const int Class::bla = 1.3; (in .cpp)
static const int bla; (in .hpp inside class private section)

  • "enum hack": #define bla 5 -> enum { bla = 5 };
    • if const int bla=5; impossible
    • e.g. necessary if constant is used in array declaration (int blabla[bla];)

details:

  • new file defs.cpp where const double reside in and are referenced by extern "C" const double
  • joiner.cpp: main() had to be changed due to concatenation of two #define possible, of two const char * not
  • class specific constants: HULLEPSILON, BONDTHRESHOLD, SPHERERADIUS
  • extended GetPathLengthonCircumCircle to additional parameter HULLEPSILON
  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * bondgraph.cpp
3 *
4 * Created on: Oct 29, 2009
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include <iostream>
11
12#include "atom.hpp"
13#include "bond.hpp"
14#include "bondgraph.hpp"
15#include "element.hpp"
16#include "Helpers/Info.hpp"
17#include "Helpers/Verbose.hpp"
18#include "Helpers/Log.hpp"
19#include "molecule.hpp"
20#include "parser.hpp"
21#include "periodentafel.hpp"
22#include "LinearAlgebra/Vector.hpp"
23
24const double BondGraph::BondThreshold = 0.4; //!< CSD threshold in bond check which is the width of the interval whose center is the sum of the covalent radii
25
26/** Constructor of class BondGraph.
27 * This classes contains typical bond lengths and thus may be used to construct a bond graph for a given molecule.
28 */
29BondGraph::BondGraph(bool IsA) : BondLengthMatrix(NULL), max_distance(0), IsAngstroem(IsA)
30{
31};
32
33/** Destructor of class BondGraph.
34 */
35BondGraph::~BondGraph()
36{
37 if (BondLengthMatrix != NULL) {
38 delete(BondLengthMatrix);
39 }
40};
41
42/** Parses the bond lengths in a given file and puts them int a matrix form.
43 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
44 * but only if parsing is successful. Otherwise variable is left as NULL.
45 * \param *out output stream for debugging
46 * \param filename file with bond lengths to parse
47 * \return true - success in parsing file, false - failed to parse the file
48 */
49bool BondGraph::LoadBondLengthTable(const string &filename)
50{
51 Info FunctionInfo(__func__);
52 bool status = true;
53 MatrixContainer *TempContainer = NULL;
54
55 // allocate MatrixContainer
56 if (BondLengthMatrix != NULL) {
57 DoLog(1) && (Log() << Verbose(1) << "MatrixContainer for Bond length already present, removing." << endl);
58 delete(BondLengthMatrix);
59 }
60 TempContainer = new MatrixContainer;
61
62 // parse in matrix
63 if ((status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0))) {
64 DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl);
65 } else {
66 DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
67 }
68
69 // find greatest distance
70 max_distance=0;
71 if (status) {
72 for(int i=0;i<TempContainer->RowCounter[0];i++)
73 for(int j=i;j<TempContainer->ColumnCounter[0];j++)
74 if (TempContainer->Matrix[0][i][j] > max_distance)
75 max_distance = TempContainer->Matrix[0][i][j];
76 }
77
78 if (status) // set to not NULL only if matrix was parsed
79 BondLengthMatrix = TempContainer;
80 else {
81 BondLengthMatrix = NULL;
82 delete(TempContainer);
83 }
84 return status;
85};
86
87/** Parses the bond lengths in a given file and puts them int a matrix form.
88 * \param *out output stream for debugging
89 * \param *mol molecule with atoms
90 * \return true - success, false - failed to construct bond structure
91 */
92bool BondGraph::ConstructBondGraph(molecule * const mol)
93{
94 Info FunctionInfo(__func__);
95 bool status = true;
96
97 if (mol->empty()) // only construct if molecule is not empty
98 return false;
99
100 if (BondLengthMatrix == NULL) { // no bond length matrix parsed?
101 SetMaxDistanceToMaxOfCovalentRadii(mol);
102 mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::CovalentMinMaxDistance, this);
103 } else
104 mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::BondLengthMatrixMinMaxDistance, this);
105
106 return status;
107};
108
109/** Returns the entry for a given index pair.
110 * \param firstelement index/atom number of first element (row index)
111 * \param secondelement index/atom number of second element (column index)
112 * \note matrix is of course symmetric.
113 */
114double BondGraph::GetBondLength(int firstZ, int secondZ)
115{
116 if (BondLengthMatrix == NULL)
117 return( -1. );
118 else
119 return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
120};
121
122/** Determines the maximum of all element::CovalentRadius for elements present in \a *mol.
123 * \param *out output stream for debugging
124 * \param *mol molecule with all atoms and their respective elements.
125 */
126double BondGraph::SetMaxDistanceToMaxOfCovalentRadii(const molecule * const mol)
127{
128 Info FunctionInfo(__func__);
129 max_distance = 0.;
130
131 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
132 if ((*iter)->getType()->CovalentRadius > max_distance)
133 max_distance = (*iter)->getType()->CovalentRadius;
134 }
135 max_distance *= 2.;
136
137 return max_distance;
138};
139
140/** Returns bond criterion for given pair based on covalent radius.
141 * \param *Walker first BondedParticle
142 * \param *OtherWalker second BondedParticle
143 * \param &MinDistance lower bond bound on return
144 * \param &MaxDistance upper bond bound on return
145 * \param IsAngstroem whether units are in angstroem or bohr radii
146 */
147void BondGraph::CovalentMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
148{
149 MinDistance = OtherWalker->getType()->CovalentRadius + Walker->getType()->CovalentRadius;
150 MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
151 MaxDistance = MinDistance + BondThreshold;
152 MinDistance -= BondThreshold;
153};
154
155/** Returns bond criterion for given pair based on a bond length matrix.
156 * The matrix should be contained in \a this BondGraph and contain an element-
157 * to-element length.
158 * \param *Walker first BondedParticle
159 * \param *OtherWalker second BondedParticle
160 * \param &MinDistance lower bond bound on return
161 * \param &MaxDistance upper bond bound on return
162 * \param IsAngstroem whether units are in angstroem or bohr radii
163 */
164void BondGraph::BondLengthMatrixMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
165{
166 if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
167 DoeLog(2) && (eLog()<< Verbose(2) << "BondLengthMatrixMinMaxDistance() called without having parsed the bond length matrix yet!" << endl);
168 CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
169 } else {
170 MinDistance = GetBondLength(Walker->getType()->Z-1, OtherWalker->getType()->Z-1);
171 MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
172 MaxDistance = MinDistance + BondThreshold;
173 MinDistance -= BondThreshold;
174 }
175};
Note: See TracBrowser for help on using the repository browser.