source: src/bondgraph.cpp@ 99593f

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 99593f was 3c349b, checked in by Frederik Heber <heber@…>, 16 years ago

"not working parsed molecule into subgraph splitting"-BUG fixed, BugFinder branch can be closed.

  • config::Load() - atoms were not in the right order for MaxOrder-test (12). Hence, the BondFragmentAdjacency could not be parsed. Now, we just take the subgraphs as the association of each atom to a molecule, i.e. we make a list and then re-link each atom to its new connected subgraph molecule, which is returned as the MoleculeListClass.

other fixes:

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