source: src/atom_bondedparticle.cpp@ 70ff32

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

Begun with ticket #4 (shorten constructors) on class atom and class bond.

  • note that in bond we removed two constructor definitions which were unnecessary if standard values were given in the definition not in the declaration.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * atom_bondedparticle.cpp
3 *
4 * Created on: Oct 19, 2009
5 * Author: heber
6 */
7
8#include "atom.hpp"
9#include "atom_bondedparticle.hpp"
10#include "bond.hpp"
11#include "element.hpp"
12#include "lists.hpp"
13#include "verbose.hpp"
14
15/** Constructor of class BondedParticle.
16 */
17BondedParticle::BondedParticle()
18{
19};
20
21/** Destructor of class BondedParticle.
22 */
23BondedParticle::~BondedParticle()
24{
25 BondList::const_iterator Runner;
26 while (!ListOfBonds.empty()) {
27 Runner = ListOfBonds.begin();
28 removewithoutcheck(*Runner);
29 }
30};
31
32/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
33 * \param *file output stream
34 */
35void BondedParticle::OutputOrder(ofstream *file) const
36{
37 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
38 //cout << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
39};
40
41/** Prints all bonds of this atom with total degree.
42 * \param *out stream to output to
43 * \return true - \a *out present, false - \a *out is NULL
44 */
45bool BondedParticle::OutputBondOfAtom(ofstream *out) const
46{
47 if (out != NULL) {
48 *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: ";
49 int TotalDegree = 0;
50 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
51 *out << **Runner << "\t";
52 TotalDegree += (*Runner)->BondDegree;
53 }
54 *out << " -- TotalDegree: " << TotalDegree << endl;
55 return true;
56 } else
57 return false;
58};
59
60/** Output of atom::nr along with all bond partners.
61 * \param *AdjacencyFile output stream
62 */
63void BondedParticle::OutputAdjacency(ofstream *AdjacencyFile) const
64{
65 *AdjacencyFile << nr << "\t";
66 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
67 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
68 *AdjacencyFile << endl;
69};
70
71/** Puts a given bond into atom::ListOfBonds.
72 * \param *Binder bond to insert
73 */
74bool BondedParticle::RegisterBond(bond *Binder)
75{
76 bool status = false;
77 if (Binder != NULL) {
78 if (Binder->Contains(this)) {
79 ListOfBonds.push_back(Binder);
80 status = true;
81 } else {
82 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
83 }
84 } else {
85 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
86 }
87 return status;
88};
89
90/** Removes a given bond from atom::ListOfBonds.
91 * \param *Binder bond to remove
92 */
93bool BondedParticle::UnregisterBond(bond *Binder)
94{
95 bool status = false;
96 if (Binder != NULL) {
97 if (Binder->Contains(this)) {
98 ListOfBonds.remove(Binder);
99 status = true;
100 } else {
101 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
102 }
103 } else {
104 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
105 }
106 return status;
107};
108
109/** Removes all bonds from atom::ListOfBonds.
110 * \note Does not do any memory de-allocation.
111 */
112void BondedParticle::UnregisterAllBond()
113{
114 ListOfBonds.clear();
115};
116
117/** Corrects the bond degree by one at most if necessary.
118 * \param *out output stream for debugging
119 */
120int BondedParticle::CorrectBondDegree(ofstream *out)
121{
122 int NoBonds = 0;
123 int OtherNoBonds = 0;
124 int FalseBondDegree = 0;
125 atom *OtherWalker = NULL;
126 bond *CandidateBond = NULL;
127
128 *out << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
129 NoBonds = CountBonds();
130 if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
131 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
132 OtherWalker = (*Runner)->GetOtherAtom(this);
133 OtherNoBonds = OtherWalker->CountBonds();
134 *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
135 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate
136 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
137 CandidateBond = (*Runner);
138 *out << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
139 }
140 }
141 }
142 if ((CandidateBond != NULL)) {
143 CandidateBond->BondDegree++;
144 *out << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
145 } else {
146 *out << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
147 FalseBondDegree++;
148 }
149 }
150 return FalseBondDegree;
151};
152
Note: See TracBrowser for help on using the repository browser.