source: src/atom_bondedparticle.cpp@ 93c6e9

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 Candidate_v1.7.0 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 93c6e9 was 93c6e9, checked in by Frederik Heber <heber@…>, 15 years ago

BondedParticle::UnregisterBond() uses BondedParticle::ContainsBondAtStep() with step.

  • Property mode set to 100644
File size: 8.5 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 "element.hpp"
26#include "lists.hpp"
27#include "CodePatterns/Log.hpp"
28#include "CodePatterns/Verbose.hpp"
29#include "WorldTime.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 BondList& ListOfBonds = getListOfBonds();
126 ListOfBonds.push_back(Binder);
127 status = true;
128 } else {
129 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
130 }
131 } else {
132 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
133 }
134 return status;
135};
136
137/** Removes a given bond from atom::ListOfBonds.
138 * @param _step time step to access
139 * \param *Binder bond to remove
140 */
141bool BondedParticle::UnregisterBond(bond *Binder)
142{
143 bool status = false;
144 if (Binder != NULL) {
145 if (Binder->Contains(this)) {
146 const int step = ContainsBondAtStep(Binder);
147 if (step != -1) {
148 ListOfBonds[step].remove(Binder);
149 }
150 status = true;
151 } else {
152 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
153 }
154 } else {
155 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
156 }
157 return status;
158};
159
160/** Removes all bonds from atom::ListOfBonds.
161 * \note Does not do any memory de-allocation.
162 */
163void BondedParticle::UnregisterAllBond(const unsigned int _step)
164{
165 BondList& ListOfBonds = getListOfBondsAtStep(_step);
166 ListOfBonds.clear();
167};
168
169/** Searches for the time step where the given bond \a *Binder is a bond of this particle.
170 *
171 * @param Binder bond to check
172 * @return >=0 - first time step where bond appears, -1 - bond not present in lists
173 */
174int BondedParticle::ContainsBondAtStep(bond *Binder)
175{
176 int step = -1;
177 int tempstep = 0;
178 for(std::vector<BondList>::const_iterator iter = ListOfBonds.begin();
179 iter != ListOfBonds.end();
180 ++iter,++tempstep) {
181 for (BondList::const_iterator bonditer = iter->begin();
182 bonditer != iter->end();
183 ++bonditer) {
184 if ((*bonditer) == Binder) {
185 step = tempstep;
186 break;
187 }
188 }
189 if (step != -1)
190 break;
191 }
192
193 return step;
194}
195
196/** Corrects the bond degree by one at most if necessary.
197 * \return number of corrections done
198 */
199int BondedParticle::CorrectBondDegree()
200{
201 int NoBonds = 0;
202 int OtherNoBonds = 0;
203 int FalseBondDegree = 0;
204 atom *OtherWalker = NULL;
205 bond *CandidateBond = NULL;
206
207 NoBonds = CountBonds();
208 //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
209 if ((int)(getType()->getNoValenceOrbitals()) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
210 const BondList& ListOfBonds = getListOfBonds();
211 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
212 OtherWalker = (*Runner)->GetOtherAtom(this);
213 OtherNoBonds = OtherWalker->CountBonds();
214 //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
215 if ((int)(OtherWalker->getType()->getNoValenceOrbitals()) > OtherNoBonds) { // check if possible candidate
216 const BondList& OtherListOfBonds = OtherWalker->getListOfBonds();
217 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherListOfBonds.size())) { // pick the one with fewer number of bonds first
218 CandidateBond = (*Runner);
219 //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
220 }
221 }
222 }
223 if ((CandidateBond != NULL)) {
224 CandidateBond->BondDegree++;
225 //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
226 } else {
227 DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
228 FalseBondDegree++;
229 }
230 }
231 return FalseBondDegree;
232};
233
234/** Counts the number of bonds weighted by bond::BondDegree.
235 * @param _step time step to access
236 * \param bonds times bond::BondDegree
237 */
238int BondedParticle::CountBonds() const
239{
240 int NoBonds = 0;
241 const BondList& ListOfBonds = getListOfBonds();
242 for (BondList::const_iterator Runner = ListOfBonds.begin();
243 Runner != ListOfBonds.end();
244 (++Runner))
245 NoBonds += (*Runner)->BondDegree;
246 return NoBonds;
247};
248
249/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
250 * \param *BondPartner atom to check for
251 * \return true - bond exists, false - bond does not exist
252 */
253bool BondedParticle::IsBondedTo(BondedParticle * const BondPartner)
254{
255 bool status = false;
256
257 const BondList& ListOfBonds = getListOfBonds();
258 for (BondList::const_iterator runner = ListOfBonds.begin(); runner != ListOfBonds.end(); runner++) {
259 status = status || ((*runner)->Contains(BondPartner));
260 }
261 return status;
262};
263
264std::ostream & BondedParticle::operator << (std::ostream &ost) const
265{
266 ParticleInfo::operator<<(ost);
267 ost << "," << getPosition();
268 return ost;
269}
270
271std::ostream & operator << (std::ostream &ost, const BondedParticle &a)
272{
273 a.ParticleInfo::operator<<(ost);
274 ost << "," << a.getPosition();
275 return ost;
276}
277
Note: See TracBrowser for help on using the repository browser.