source: src/atom.cpp@ 112b09

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 112b09 was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

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