source: src/atom.cpp@ 0cc92b

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 0cc92b was 00abfc, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added a method to class atom that determines if the father of this atom is some pointer

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