source: src/atom_bondedparticle.cpp@ 1e6249

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 1e6249 was 073a9e4, checked in by Frederik Heber <heber@…>, 14 years ago

BondedParticle::(Un)RegisterBond,AddBond,IsBondedTo with step.

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