source: src/bondgraph.cpp@ 36166d

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 36166d was 36166d, checked in by Tillmann Crueger <crueger@…>, 14 years ago

Removed left over parts from old memory-tracker

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