source: src/bondgraph.cpp@ 88104f

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 88104f was bd6bfa, checked in by Frederik Heber <heber@…>, 15 years ago

Fixes after first,last removal.

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