source: src/atom_bondedparticle.cpp@ d557374

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

Cosmetic changes to class bond::~bond and BondedParticle::UnregisterBond.

  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * atom_bondedparticle.cpp
10 *
11 * Created on: Oct 19, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "atom.hpp"
23#include "atom_bondedparticle.hpp"
24#include "bond.hpp"
25#include "CodePatterns/Assert.hpp"
26#include "CodePatterns/Log.hpp"
27#include "CodePatterns/Verbose.hpp"
28#include "element.hpp"
29#include "lists.hpp"
30
31/** Constructor of class BondedParticle.
32 */
33BondedParticle::BondedParticle()
34{
35 ListOfBonds.push_back(BondList());
36};
37
38/** Destructor of class BondedParticle.
39 */
40BondedParticle::~BondedParticle()
41{
42 BondList::iterator Runner;
43 for (std::vector<BondList>::iterator iter = ListOfBonds.begin();
44 !ListOfBonds.empty();
45 iter = ListOfBonds.begin()) {
46 while (!(*iter).empty()) {
47 Runner = (*iter).begin();
48 removewithoutcheck(*Runner);
49 }
50 ListOfBonds.erase(iter);
51 }
52};
53
54/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
55 * \param *file output stream
56 */
57void BondedParticle::OutputOrder(ofstream *file) const
58{
59 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
60 //Log() << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
61};
62
63/** Prints all bonds of this atom with total degree.
64 */
65void BondedParticle::OutputBondOfAtom() const
66{
67 const BondList& ListOfBonds = getListOfBonds();
68 DoLog(4) && (Log() << Verbose(4) << "Atom " << getName() << "/" << nr << " with " << ListOfBonds.size() << " bonds: " << endl);
69 int TotalDegree = 0;
70 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
71 DoLog(4) && (Log() << Verbose(4) << **Runner << endl);
72 TotalDegree += (*Runner)->BondDegree;
73 }
74 DoLog(4) && (Log() << Verbose(4) << " -- TotalDegree: " << TotalDegree << endl);
75};
76
77/** Output of atom::nr along with all bond partners.
78 * \param *AdjacencyFile output stream
79 */
80void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
81{
82 const BondList& ListOfBonds = getListOfBonds();
83 *AdjacencyFile << nr << "\t";
84 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
85 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
86 *AdjacencyFile << endl;
87};
88
89/** Output of atom::nr along each bond partner per line.
90 * Only bonds are printed where atom::nr is smaller than the one of the bond partner.
91 * \param *AdjacencyFile output stream
92 */
93void BondedParticle::OutputBonds(ofstream * const BondFile) const
94{
95 const BondList& ListOfBonds = getListOfBonds();
96 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
97 if (nr < (*Runner)->GetOtherAtom(this)->nr)
98 *BondFile << nr << "\t" << (*Runner)->GetOtherAtom(this)->nr << "\n";
99};
100
101/**
102 * Adds a bond between this bonded particle and another. Does nothing if this
103 * bond already exists.
104 *
105 * \param bonding partner
106 */
107void BondedParticle::addBond(BondedParticle* Partner) {
108 if (IsBondedTo(Partner)) {
109 return;
110 }
111
112 bond* newBond = new bond((atom*) this, (atom*) Partner, 1, 0);
113 RegisterBond(newBond);
114 Partner->RegisterBond(newBond);
115}
116
117/** Puts a given bond into atom::ListOfBonds.
118 * \param *Binder bond to insert
119 */
120bool BondedParticle::RegisterBond(bond *Binder)
121{
122 bool status = false;
123 if (Binder != NULL) {
124 if (Binder->Contains(this)) {
125 //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
126 BondList& ListOfBonds = getListOfBonds();
127 ListOfBonds.push_back(Binder);
128 status = true;
129 } else {
130 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
131 }
132 } else {
133 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
134 }
135 return status;
136};
137
138/** Removes a given bond from atom::ListOfBonds.
139 * @param _step time step to access
140 * \param *Binder bond to remove
141 */
142bool BondedParticle::UnregisterBond(bond *Binder)
143{
144 bool status = false;
145 ASSERT(Binder != NULL, "BondedParticle::UnregisterBond() - Binder is NULL.");
146 const int step = ContainsBondAtStep(Binder);
147 if (step != -1) {
148 //LOG(3,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
149 ListOfBonds[step].remove(Binder);
150 status = true;
151 } else {
152 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
153 }
154 return status;
155};
156
157/** Removes all bonds from atom::ListOfBonds.
158 * \note Does not do any memory de-allocation.
159 */
160void BondedParticle::UnregisterAllBond(const unsigned int _step)
161{
162 BondList& ListOfBonds = getListOfBondsAtStep(_step);
163 ListOfBonds.clear();
164};
165
166/** Searches for the time step where the given bond \a *Binder is a bond of this particle.
167 *
168 * @param Binder bond to check
169 * @return >=0 - first time step where bond appears, -1 - bond not present in lists
170 */
171int BondedParticle::ContainsBondAtStep(bond *Binder)
172{
173 int step = -1;
174 int tempstep = 0;
175 for(std::vector<BondList>::const_iterator iter = ListOfBonds.begin();
176 iter != ListOfBonds.end();
177 ++iter,++tempstep) {
178 for (BondList::const_iterator bonditer = iter->begin();
179 bonditer != iter->end();
180 ++bonditer) {
181 if ((*bonditer) == Binder) {
182 step = tempstep;
183 break;
184 }
185 }
186 if (step != -1)
187 break;
188 }
189
190 return step;
191}
192
193/** Corrects the bond degree by one at most if necessary.
194 * \return number of corrections done
195 */
196int BondedParticle::CorrectBondDegree()
197{
198 int NoBonds = 0;
199 int OtherNoBonds = 0;
200 int FalseBondDegree = 0;
201 atom *OtherWalker = NULL;
202 bond *CandidateBond = NULL;
203
204 NoBonds = CountBonds();
205 //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
206 if ((int)(getType()->getNoValenceOrbitals()) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
207 const BondList& ListOfBonds = getListOfBonds();
208 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
209 OtherWalker = (*Runner)->GetOtherAtom(this);
210 OtherNoBonds = OtherWalker->CountBonds();
211 //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
212 if ((int)(OtherWalker->getType()->getNoValenceOrbitals()) > OtherNoBonds) { // check if possible candidate
213 const BondList& OtherListOfBonds = OtherWalker->getListOfBonds();
214 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherListOfBonds.size())) { // pick the one with fewer number of bonds first
215 CandidateBond = (*Runner);
216 //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
217 }
218 }
219 }
220 if ((CandidateBond != NULL)) {
221 CandidateBond->BondDegree++;
222 //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
223 } else {
224 DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
225 FalseBondDegree++;
226 }
227 }
228 return FalseBondDegree;
229};
230
231/** Counts the number of bonds weighted by bond::BondDegree.
232 * @param _step time step to access
233 * \param bonds times bond::BondDegree
234 */
235int BondedParticle::CountBonds() const
236{
237 int NoBonds = 0;
238 const BondList& ListOfBonds = getListOfBonds();
239 for (BondList::const_iterator Runner = ListOfBonds.begin();
240 Runner != ListOfBonds.end();
241 (++Runner))
242 NoBonds += (*Runner)->BondDegree;
243 return NoBonds;
244};
245
246/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
247 * \param *BondPartner atom to check for
248 * \return true - bond exists, false - bond does not exist
249 */
250bool BondedParticle::IsBondedTo(BondedParticle * const BondPartner)
251{
252 bool status = false;
253
254 const BondList& ListOfBonds = getListOfBonds();
255 for (BondList::const_iterator runner = ListOfBonds.begin(); runner != ListOfBonds.end(); runner++) {
256 status = status || ((*runner)->Contains(BondPartner));
257 }
258 return status;
259};
260
261std::ostream & BondedParticle::operator << (std::ostream &ost) const
262{
263 ParticleInfo::operator<<(ost);
264 ost << "," << getPosition();
265 return ost;
266}
267
268std::ostream & operator << (std::ostream &ost, const BondedParticle &a)
269{
270 a.ParticleInfo::operator<<(ost);
271 ost << "," << a.getPosition();
272 return ost;
273}
274
Note: See TracBrowser for help on using the repository browser.