source: src/atom_bondedparticle.cpp@ 3839e5

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 3839e5 was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * atom_bondedparticle.cpp
3 *
4 * Created on: Oct 19, 2009
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "atom.hpp"
11#include "atom_bondedparticle.hpp"
12#include "bond.hpp"
13#include "element.hpp"
14#include "lists.hpp"
15#include "log.hpp"
16#include "verbose.hpp"
17
18/** Constructor of class BondedParticle.
19 */
20BondedParticle::BondedParticle()
21{
22};
23
24/** Destructor of class BondedParticle.
25 */
26BondedParticle::~BondedParticle()
27{
28 BondList::const_iterator Runner;
29 while (!ListOfBonds.empty()) {
30 Runner = ListOfBonds.begin();
31 removewithoutcheck(*Runner);
32 }
33};
34
35/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
36 * \param *file output stream
37 */
38void BondedParticle::OutputOrder(ofstream *file) const
39{
40 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
41 //Log() << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
42};
43
44/** Prints all bonds of this atom with total degree.
45 */
46void BondedParticle::OutputBondOfAtom() const
47{
48 DoLog(4) && (Log() << Verbose(4) << "Atom " << getName() << "/" << nr << " with " << ListOfBonds.size() << " bonds: " << endl);
49 int TotalDegree = 0;
50 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
51 DoLog(4) && (Log() << Verbose(4) << **Runner << endl);
52 TotalDegree += (*Runner)->BondDegree;
53 }
54 DoLog(4) && (Log() << Verbose(4) << " -- TotalDegree: " << TotalDegree << endl);
55};
56
57/** Output of atom::nr along with all bond partners.
58 * \param *AdjacencyFile output stream
59 */
60void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
61{
62 *AdjacencyFile << nr << "\t";
63 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
64 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
65 *AdjacencyFile << endl;
66};
67
68/** Output of atom::nr along each bond partner per line.
69 * Only bonds are printed where atom::nr is smaller than the one of the bond partner.
70 * \param *AdjacencyFile output stream
71 */
72void BondedParticle::OutputBonds(ofstream * const BondFile) const
73{
74 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
75 if (nr < (*Runner)->GetOtherAtom(this)->nr)
76 *BondFile << nr << "\t" << (*Runner)->GetOtherAtom(this)->nr << "\n";
77};
78
79/**
80 * Adds a bond between this bonded particle and another. Does nothing if this
81 * bond already exists.
82 *
83 * \param bonding partner
84 */
85void BondedParticle::addBond(BondedParticle* Partner) {
86 if (IsBondedTo(Partner)) {
87 return;
88 }
89
90 bond* newBond = new bond((atom*) this, (atom*) Partner, 1, 0);
91 RegisterBond(newBond);
92 Partner->RegisterBond(newBond);
93}
94
95/** Puts a given bond into atom::ListOfBonds.
96 * \param *Binder bond to insert
97 */
98bool BondedParticle::RegisterBond(bond *Binder)
99{
100 bool status = false;
101 if (Binder != NULL) {
102 if (Binder->Contains(this)) {
103 ListOfBonds.push_back(Binder);
104 status = true;
105 } else {
106 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
107 }
108 } else {
109 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
110 }
111 return status;
112};
113
114/** Removes a given bond from atom::ListOfBonds.
115 * \param *Binder bond to remove
116 */
117bool BondedParticle::UnregisterBond(bond *Binder)
118{
119 bool status = false;
120 if (Binder != NULL) {
121 if (Binder->Contains(this)) {
122 ListOfBonds.remove(Binder);
123 status = true;
124 } else {
125 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
126 }
127 } else {
128 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
129 }
130 return status;
131};
132
133/** Removes all bonds from atom::ListOfBonds.
134 * \note Does not do any memory de-allocation.
135 */
136void BondedParticle::UnregisterAllBond()
137{
138 ListOfBonds.clear();
139};
140
141/** Corrects the bond degree by one at most if necessary.
142 * \param *out output stream for debugging
143 */
144int BondedParticle::CorrectBondDegree()
145{
146 int NoBonds = 0;
147 int OtherNoBonds = 0;
148 int FalseBondDegree = 0;
149 atom *OtherWalker = NULL;
150 bond *CandidateBond = NULL;
151
152 NoBonds = CountBonds();
153 //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
154 if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
155 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
156 OtherWalker = (*Runner)->GetOtherAtom(this);
157 OtherNoBonds = OtherWalker->CountBonds();
158 //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
159 if ((int)(OtherWalker->type->NoValenceOrbitals) > OtherNoBonds) { // check if possible candidate
160 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
161 CandidateBond = (*Runner);
162 //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
163 }
164 }
165 }
166 if ((CandidateBond != NULL)) {
167 CandidateBond->BondDegree++;
168 //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
169 } else {
170 DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
171 FalseBondDegree++;
172 }
173 }
174 return FalseBondDegree;
175};
176
177/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
178 * \param *BondPartner atom to check for
179 * \return true - bond exists, false - bond does not exist
180 */
181bool BondedParticle::IsBondedTo(BondedParticle * const BondPartner)
182{
183 bool status = false;
184
185 for (BondList::iterator runner = ListOfBonds.begin(); runner != ListOfBonds.end(); runner++) {
186 status = status || ((*runner)->Contains(BondPartner));
187 }
188 return status;
189};
190
Note: See TracBrowser for help on using the repository browser.