source: src/atom.cpp@ 6cfa36

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

Made atoms remove themselves from molecules upon destruction

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