source: src/Atom/atom_bondedparticle.cpp@ 8b58ac

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 8b58ac was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 11.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * atom_bondedparticle.cpp
25 *
26 * Created on: Oct 19, 2009
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "atom.hpp"
38#include "atom_bondedparticle.hpp"
39#include "Bond/bond.hpp"
40#include "CodePatterns/Assert.hpp"
41#include "CodePatterns/Log.hpp"
42#include "CodePatterns/Verbose.hpp"
43#include "Element/element.hpp"
44#include "WorldTime.hpp"
45
46/** Constructor of class BondedParticle.
47 */
48BondedParticle::BondedParticle()
49{
50 ListOfBonds.push_back(BondList());
51};
52
53/** Destructor of class BondedParticle.
54 */
55BondedParticle::~BondedParticle()
56{
57 removeAllBonds();
58};
59
60/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
61 * \param *file output stream
62 */
63void BondedParticle::OutputOrder(ofstream *file) const
64{
65 *file << getNr() << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
66 //LOG(2, "Storing: " << getNr() << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << ".");
67};
68
69/** Prints all bonds of this atom with total degree.
70 */
71void BondedParticle::OutputBondOfAtom(std::ostream &ost) const
72{
73 const BondList& ListOfBonds = getListOfBonds();
74 ost << "Atom " << getName() << "/" << getNr() << " with " << ListOfBonds.size() << " bonds: ";
75 int TotalDegree = 0;
76 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
77 ost << **Runner << "\t";
78 TotalDegree += (*Runner)->BondDegree;
79 }
80 ost << " -- TotalDegree: " << TotalDegree;
81};
82
83/** Output of atom::Nr along with all bond partners.
84 * \param *AdjacencyFile output stream
85 */
86void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
87{
88 const BondList& ListOfBonds = getListOfBonds();
89 *AdjacencyFile << getNr() << "\t";
90 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
91 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->getNr() << "\t";
92 *AdjacencyFile << endl;
93};
94
95/** Output of atom::Nr along each bond partner per line.
96 * Only bonds are printed where atom::Nr is smaller than the one of the bond partner.
97 * \param *AdjacencyFile output stream
98 */
99void BondedParticle::OutputBonds(ofstream * const BondFile) const
100{
101 const BondList& ListOfBonds = getListOfBonds();
102 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
103 if (getNr() < (*Runner)->GetOtherAtom(this)->getNr())
104 *BondFile << getNr() << "\t" << (*Runner)->GetOtherAtom(this)->getNr() << "\n";
105};
106
107/**
108 * Adds a bond between this bonded particle and another. Returns present instance if this
109 * bond already exists.
110 *
111 * @param _step time step to access
112 * @param bonding partner
113 * @return const pointer to created bond or to already present bonds
114 */
115bond * const BondedParticle::addBond(const unsigned int _step, BondedParticle* Partner)
116{
117 const BondList &bondlist = getListOfBondsAtStep(_step);
118 for (BondList::const_iterator runner = bondlist.begin();
119 runner != bondlist.end();
120 runner++) {
121 if ((*runner)->Contains(Partner))
122 return *runner;
123 }
124
125 bond* newBond = new bond((atom*) this, (atom*) Partner, 1);
126 RegisterBond(_step, newBond);
127 Partner->RegisterBond(_step, newBond);
128
129 return newBond;
130}
131
132/** Removes a bond for this atom.
133 *
134 * @param Binder bond to remove
135 */
136void BondedParticle::removeBond(bond * binder)
137{
138 UnregisterBond(binder);
139}
140
141/** Removes all bonds in all timesteps and their instances, too.
142 *
143 */
144void BondedParticle::removeAllBonds()
145{
146 for (size_t index = 0; index < ListOfBonds.size(); ++index)
147 removeAllBonds(index);
148}
149
150/** Removes all bonds for a given \a _step and their instances, too.
151 *
152 * @param _step time step to access
153 */
154void BondedParticle::removeAllBonds(const unsigned int _step)
155{
156 for (BondList::iterator iter = ListOfBonds[_step].begin();
157 !ListOfBonds[_step].empty();
158 iter = ListOfBonds[_step].begin()) {
159 delete (*iter);
160 // unregister/NOTIFY is done by bond::~bond()
161 }
162}
163
164/** Puts a given bond into atom::ListOfBonds.
165 * @param _step time step to access
166 * \param *Binder bond to insert
167 */
168bool BondedParticle::RegisterBond(const unsigned int _step, bond * const Binder)
169{
170 OBSERVE;
171 bool status = false;
172 if (Binder != NULL) {
173 if (Binder->Contains(this)) {
174 //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
175 if (ListOfBonds.size() <= _step)
176 ListOfBonds.resize(_step+1);
177 ListOfBonds[_step].push_back(Binder);
178 if (WorldTime::getTime() == _step)
179 NOTIFY(AtomObservable::BondsAdded);
180 status = true;
181 } else {
182 ELOG(1, *Binder << " does not contain " << *this << ".");
183 }
184 } else {
185 ELOG(1, "Binder is " << Binder << ".");
186 }
187 return status;
188};
189
190/** Removes a given bond from atom::ListOfBonds.
191 * @param _step time step to access
192 * \param *Binder bond to remove
193 */
194bool BondedParticle::UnregisterBond(bond * const Binder)
195{
196 OBSERVE;
197 bool status = false;
198 ASSERT(Binder != NULL, "BondedParticle::UnregisterBond() - Binder is NULL.");
199 const int step = ContainsBondAtStep(Binder);
200 if (step != -1) {
201 //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
202 ListOfBonds[step].remove(Binder);
203 if (WorldTime::getTime() == step)
204 NOTIFY(AtomObservable::BondsRemoved);
205 status = true;
206 } else {
207 ELOG(1, *Binder << " does not contain " << *this << ".");
208 }
209 return status;
210};
211
212/** Removes all bonds from atom::ListOfBonds.
213 * \note Does not do any memory de-allocation.
214 */
215void BondedParticle::UnregisterAllBond(const unsigned int _step)
216{
217 OBSERVE;
218 NOTIFY(AtomObservable::BondsRemoved);
219 ListOfBonds[_step].clear();
220}
221
222/** Removes all bonds of given \a _step with freeing memory.
223 *
224 * @param _step time step whose bonds to free
225 */
226void BondedParticle::ClearBondsAtStep(const unsigned int _step)
227{
228 OBSERVE;
229 NOTIFY(AtomObservable::BondsRemoved);
230 //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
231 for (BondList::iterator iter = (ListOfBonds[_step]).begin();
232 !(ListOfBonds[_step]).empty();
233 iter = (ListOfBonds[_step]).begin()) {
234 //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds);
235 delete((*iter)); // will also unregister with us and remove from list
236 }
237}
238
239/** Searches for the time step where the given bond \a *Binder is a bond of this particle.
240 *
241 * @param Binder bond to check
242 * @return >=0 - first time step where bond appears, -1 - bond not present in lists
243 */
244int BondedParticle::ContainsBondAtStep(bond *Binder) const
245{
246 int step = -1;
247 int tempstep = 0;
248 for(std::vector<BondList>::const_iterator iter = ListOfBonds.begin();
249 iter != ListOfBonds.end();
250 ++iter,++tempstep) {
251 for (BondList::const_iterator bonditer = iter->begin();
252 bonditer != iter->end();
253 ++bonditer) {
254 if ((*bonditer) == Binder) {
255 step = tempstep;
256 break;
257 }
258 }
259 if (step != -1)
260 break;
261 }
262
263 return step;
264}
265
266/** Corrects the bond degree by one at most if necessary.
267 * \return number of corrections done
268 */
269int BondedParticle::CorrectBondDegree()
270{
271 OBSERVE;
272 NOTIFY(AtomObservable::BondDegreeChanged);
273 int NoBonds = 0;
274 int OtherNoBonds = 0;
275 int FalseBondDegree = 0;
276 atom *OtherWalker = NULL;
277 bond *CandidateBond = NULL;
278
279 NoBonds = CountBonds();
280 //LOG(3, "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?");
281 if ((int)(getType()->getNoValenceOrbitals()) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
282 const BondList& ListOfBonds = getListOfBonds();
283 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
284 OtherWalker = (*Runner)->GetOtherAtom(this);
285 OtherNoBonds = OtherWalker->CountBonds();
286 //LOG(3, "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?");
287 if ((int)(OtherWalker->getType()->getNoValenceOrbitals()) > OtherNoBonds) { // check if possible candidate
288 const BondList& OtherListOfBonds = OtherWalker->getListOfBonds();
289 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherListOfBonds.size())) { // pick the one with fewer number of bonds first
290 CandidateBond = (*Runner);
291 //LOG(3, "New candidate is " << *CandidateBond << ".");
292 }
293 }
294 }
295 if ((CandidateBond != NULL)) {
296 CandidateBond->BondDegree++;
297 //LOG(2, "Increased bond degree for bond " << *CandidateBond << ".");
298 } else {
299 ELOG(2, "Could not find correct degree for atom " << *this << ".");
300 FalseBondDegree++;
301 }
302 }
303 return FalseBondDegree;
304};
305
306/** Sets the weight of all connected bonds to one.
307 */
308void BondedParticle::resetBondDegree()
309{
310 OBSERVE;
311 NOTIFY(BondedParticle::BondDegreeChanged);
312 for (std::vector<BondList>::iterator Runner = ListOfBonds.begin();
313 Runner != ListOfBonds.end();
314 ++Runner)
315 for (BondList::iterator BondRunner = (*Runner).begin();
316 BondRunner != (*Runner).end();
317 ++BondRunner)
318 (*BondRunner)->BondDegree = 1;
319};
320
321/** Counts the number of bonds weighted by bond::BondDegree.
322 * @param _step time step to access
323 * \param bonds times bond::BondDegree
324 */
325int BondedParticle::CountBonds() const
326{
327 int NoBonds = 0;
328 const BondList& ListOfBonds = getListOfBonds();
329 for (BondList::const_iterator Runner = ListOfBonds.begin();
330 Runner != ListOfBonds.end();
331 (++Runner))
332 NoBonds += (*Runner)->BondDegree;
333 return NoBonds;
334};
335
336/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
337 * @param _step time step to access
338 * \param *BondPartner atom to check for
339 * \return true - bond exists, false - bond does not exist
340 */
341bool BondedParticle::IsBondedTo(const unsigned int _step, BondedParticle * const BondPartner) const
342{
343 bool status = false;
344
345 const BondList& ListOfBonds = getListOfBondsAtStep(_step);
346 for (BondList::const_iterator runner = ListOfBonds.begin();
347 runner != ListOfBonds.end();
348 runner++) {
349 status = status || ((*runner)->Contains(BondPartner));
350 }
351 return status;
352};
353
354std::ostream & BondedParticle::operator << (std::ostream &ost) const
355{
356 ParticleInfo::operator<<(ost);
357 ost << "," << getPosition();
358 return ost;
359}
360
361std::ostream & operator << (std::ostream &ost, const BondedParticle &a)
362{
363 a.ParticleInfo::operator<<(ost);
364 ost << "," << a.getPosition();
365 return ost;
366}
367
Note: See TracBrowser for help on using the repository browser.