source: src/atom.cpp@ b453f9

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

Begun with ticket #38 (make const what is const).

  • basically all changes to member function that now state that they do not change member attributes.
  • in molecule_template.hpp all member functions are declared const, as we only need start and end from molecule and these are never changed (lots of overloaded templates removed thereby).
  • Vector::Distance...() and ...DistanceSquared() are const now too
  • Property mode set to 100644
File size: 8.6 KB
Line 
1/** \file atom.cpp
2 *
3 * Function implementations for the class atom.
4 *
5 */
6
7#include "atom.hpp"
8#include "bond.hpp"
9#include "config.hpp"
10#include "element.hpp"
11#include "lists.hpp"
12#include "memoryallocator.hpp"
13#include "parser.hpp"
14#include "vector.hpp"
15
16/************************************* Functions for class atom *************************************/
17
18/** Constructor of class atom.
19 */
20atom::atom()
21{
22 father = this; // generally, father is itself
23 previous = NULL;
24 next = NULL;
25 sort = &nr;
26
27 // set LCNode::Vector to our Vector
28 node = &x;
29};
30
31/** Constructor of class atom.
32 */
33atom::atom(atom *pointer)
34{
35 previous = NULL;
36 next = NULL;
37 father = pointer; // generally, father is itself
38
39 type = pointer->type; // copy element of atom
40 x.CopyVector(&pointer->x); // copy coordination
41 v.CopyVector(&pointer->v); // copy velocity
42 FixedIon = pointer->FixedIon;
43 sort = &nr;
44 node = &x;
45};
46
47
48/** Destructor of class atom.
49 */
50atom::~atom()
51{
52 unlink(this);
53};
54
55
56/** Climbs up the father list until NULL, last is returned.
57 * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
58 */
59atom *atom::GetTrueFather()
60{
61 atom *walker = this;
62 do {
63 if (walker == walker->father) // top most father is the one that points on itself
64 break;
65 walker = walker->father;
66 } while (walker != NULL);
67 return walker;
68};
69
70/** Sets father to itself or its father in case of copying a molecule.
71 */
72void atom::CorrectFather()
73{
74 if (father->father == father) // same atom in copy's father points to itself
75 father = this; // set father to itself (copy of a whole molecule)
76 else
77 father = father->father; // set father to original's father
78
79};
80
81/** Check whether father is equal to given atom.
82 * \param *ptr atom to compare father to
83 * \param **res return value (only set if atom::father is equal to \a *ptr)
84 */
85void atom::EqualsFather ( const atom *ptr, const atom **res ) const
86{
87 if ( ptr == father )
88 *res = this;
89};
90
91/** Checks whether atom is within the given box.
92 * \param offset offset to box origin
93 * \param *parallelepiped box matrix
94 * \return true - is inside, false - is not
95 */
96bool atom::IsInParallelepiped(const Vector offset, const double *parallelepiped) const
97{
98 return (node->IsInParallelepiped(offset, parallelepiped));
99};
100
101/** Counts the number of bonds weighted by bond::BondDegree.
102 * \param bonds times bond::BondDegree
103 */
104int BondedParticle::CountBonds() const
105{
106 int NoBonds = 0;
107 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
108 NoBonds += (*Runner)->BondDegree;
109 return NoBonds;
110};
111
112/** Output of a single atom with given numbering.
113 * \param ElementNo cardinal number of the element
114 * \param AtomNo cardinal number among these atoms of the same element
115 * \param *out stream to output to
116 * \param *comment commentary after '#' sign
117 * \return true - \a *out present, false - \a *out is NULL
118 */
119bool atom::OutputIndexed(ofstream *out, const int ElementNo, const int AtomNo, const char *comment) const
120{
121 if (out != NULL) {
122 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
123 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
124 *out << "\t" << FixedIon;
125 if (v.Norm() > MYEPSILON)
126 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
127 if (comment != NULL)
128 *out << " # " << comment << endl;
129 else
130 *out << " # molecule nr " << nr << endl;
131 return true;
132 } else
133 return false;
134};
135
136/** Output of a single atom with numbering from array according to atom::type.
137 * \param *ElementNo cardinal number of the element
138 * \param *AtomNo cardinal number among these atoms of the same element
139 * \param *out stream to output to
140 * \param *comment commentary after '#' sign
141 * \return true - \a *out present, false - \a *out is NULL
142 */
143bool atom::OutputArrayIndexed(ofstream *out, const int *ElementNo, int *AtomNo, const char *comment) const
144{
145 AtomNo[type->Z]++; // increment number
146 if (out != NULL) {
147 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
148 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
149 *out << "\t" << FixedIon;
150 if (v.Norm() > MYEPSILON)
151 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
152 if (comment != NULL)
153 *out << " # " << comment << endl;
154 else
155 *out << " # molecule nr " << nr << endl;
156 return true;
157 } else
158 return false;
159};
160
161/** Output of a single atom as one lin in xyz file.
162 * \param *out stream to output to
163 * \return true - \a *out present, false - \a *out is NULL
164 */
165bool atom::OutputXYZLine(ofstream *out) const
166{
167 if (out != NULL) {
168 *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;
169 return true;
170 } else
171 return false;
172};
173
174/** Output of a single atom as one lin in xyz file.
175 * \param *out stream to output to
176 * \param *ElementNo array with ion type number in the config file this atom's element shall have
177 * \param *AtomNo array with atom number in the config file this atom shall have, is increase by one automatically
178 * \param step Trajectory time step to output
179 * \return true - \a *out present, false - \a *out is NULL
180 */
181bool atom::OutputTrajectory(ofstream *out, const int *ElementNo, int *AtomNo, const int step) const
182{
183 AtomNo[type->Z]++;
184 if (out != NULL) {
185 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
186 *out << Trajectory.R.at(step).x[0] << "\t" << Trajectory.R.at(step).x[1] << "\t" << Trajectory.R.at(step).x[2];
187 *out << "\t" << FixedIon;
188 if (Trajectory.U.at(step).Norm() > MYEPSILON)
189 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step).x[0] << "\t" << Trajectory.U.at(step).x[1] << "\t" << Trajectory.U.at(step).x[2] << "\t";
190 if (Trajectory.F.at(step).Norm() > MYEPSILON)
191 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step).x[0] << "\t" << Trajectory.F.at(step).x[1] << "\t" << Trajectory.F.at(step).x[2] << "\t";
192 *out << "\t# Number in molecule " << nr << endl;
193 return true;
194 } else
195 return false;
196};
197
198/** Output of a single atom as one lin in xyz file.
199 * \param *out stream to output to
200 * \param step Trajectory time step to output
201 * \return true - \a *out present, false - \a *out is NULL
202 */
203bool atom::OutputTrajectoryXYZ(ofstream *out, const int step) const
204{
205 if (out != NULL) {
206 *out << type->symbol << "\t";
207 *out << Trajectory.R.at(step).x[0] << "\t";
208 *out << Trajectory.R.at(step).x[1] << "\t";
209 *out << Trajectory.R.at(step).x[2] << endl;
210 return true;
211 } else
212 return false;
213};
214
215/** Outputs the MPQC configuration line for this atom.
216 * \param *out output stream
217 * \param *center center of molecule subtracted from position
218 * \param *AtomNo pointer to atom counter that is increased by one
219 */
220void atom::OutputMPQCLine(ofstream *out, const Vector *center, int *AtomNo = NULL) const
221{
222 *out << "\t\t" << type->symbol << " [ " << x.x[0]-center->x[0] << "\t" << x.x[1]-center->x[1] << "\t" << x.x[2]-center->x[2] << " ]" << endl;
223 if (AtomNo != NULL)
224 *AtomNo++;
225};
226
227/** Compares the indices of \a this atom with a given \a ptr.
228 * \param ptr atom to compare index against
229 * \return true - this one's is smaller, false - not
230 */
231bool atom::Compare(const atom &ptr) const
232{
233 if (nr < ptr.nr)
234 return true;
235 else
236 return false;
237};
238
239/** Returns squared distance to a given vector.
240 * \param origin vector to calculate distance to
241 * \return distance squared
242 */
243double atom::DistanceSquaredToVector(const Vector &origin) const
244{
245 return origin.DistanceSquared(&x);
246};
247
248/** Returns distance to a given vector.
249 * \param origin vector to calculate distance to
250 * \return distance
251 */
252double atom::DistanceToVector(const Vector &origin) const
253{
254 return origin.Distance(&x);
255};
256
257/** Initialises the component number array.
258 * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
259 */
260void atom::InitComponentNr()
261{
262 if (ComponentNr != NULL)
263 Free(&ComponentNr);
264 ComponentNr = Malloc<int>(ListOfBonds.size()+1, "atom::InitComponentNumbers: *ComponentNr");
265 for (int i=ListOfBonds.size()+1;i--;)
266 ComponentNr[i] = -1;
267};
268
269
270bool operator < (atom &a, atom &b)
271{
272 return a.Compare(b);
273};
274
Note: See TracBrowser for help on using the repository browser.