source: src/atom.cpp@ fd179f

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

Huge change from ofstream * (const) out --> Log().

  • first shift was done via regular expressions
  • then via error messages from the code
  • note that class atom, class element and class molecule kept in parts their output stream, was they print to file.
  • make check runs fine
  • MISSING: Verbosity is not fixed for everything (i.e. if no endl; is present and next has Verbose(0) ...)

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

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