source: src/atom.cpp@ e345e3

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 e345e3 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
RevLine 
[14de469]1/** \file atom.cpp
[1907a7]2 *
[14de469]3 * Function implementations for the class atom.
[1907a7]4 *
[14de469]5 */
6
[112b09]7#include "Helpers/MemDebug.hpp"
8
[357fba]9#include "atom.hpp"
[e41951]10#include "bond.hpp"
[4a7776a]11#include "config.hpp"
[f66195]12#include "element.hpp"
[266237]13#include "lists.hpp"
[ccd9f5]14#include "parser.hpp"
[f66195]15#include "vector.hpp"
[d346b6]16#include "World.hpp"
[6cfa36]17#include "molecule.hpp"
[c550dd]18#include "Shapes/Shape.hpp"
[1907a7]19
[36166d]20#include <iomanip>
21
[14de469]22/************************************* Functions for class atom *************************************/
23
[70ff32]24
[14de469]25/** Constructor of class atom.
26 */
[46d958]27atom::atom() :
[6cfa36]28 father(this), sort(&nr), mol(0)
[14de469]29{
[70ff32]30 node = &x; // TesselPoint::x can only be referenced from here
[14de469]31};
32
[2319ed]33/** Constructor of class atom.
34 */
[46d958]35atom::atom(atom *pointer) :
[6cfa36]36 ParticleInfo(pointer),father(pointer), sort(&nr)
[2319ed]37{
38 type = pointer->type; // copy element of atom
[273382]39 x = pointer->x; // copy coordination
40 v = pointer->v; // copy velocity
[2319ed]41 FixedIon = pointer->FixedIon;
[89c8b2]42 node = &x;
[6cfa36]43 mol = 0;
[b453f9]44};
[2319ed]45
[46d958]46atom *atom::clone(){
[68f03d]47 atom *res = new atom(this);
[46d958]48 res->father = this;
[5f612ee]49 res->sort = &res->nr;
[46d958]50 res->type = type;
[273382]51 res->x = this->x;
52 res->v = this->v;
[46d958]53 res->FixedIon = FixedIon;
54 res->node = &x;
[6cfa36]55 res->mol = 0;
[23b547]56 World::getInstance().registerAtom(res);
[46d958]57 return res;
58}
59
[2319ed]60
[14de469]61/** Destructor of class atom.
62 */
[1907a7]63atom::~atom()
[14de469]64{
[6cfa36]65 removeFromMolecule();
[a80241]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 }
[14de469]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{
[215df0]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 }
[14de469]88};
89
[e65246]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 */
[b453f9]105void atom::EqualsFather ( const atom *ptr, const atom **res ) const
[e65246]106{
107 if ( ptr == father )
108 *res = this;
109};
110
[00abfc]111bool atom::isFather(const atom *ptr){
112 return ptr==father;
113}
114
[e9f8f9]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 */
[c550dd]120bool atom::IsInShape(const Shape& shape) const
[e9f8f9]121{
[c550dd]122 return shape.isInside(*node);
[e9f8f9]123};
124
[266237]125/** Counts the number of bonds weighted by bond::BondDegree.
126 * \param bonds times bond::BondDegree
127 */
[4455f4]128int BondedParticle::CountBonds() const
[266237]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
[b453f9]136/** Output of a single atom with given numbering.
[14de469]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
[1907a7]140 * \param *comment commentary after '#' sign
[e41951]141 * \return true - \a *out present, false - \a *out is NULL
[14de469]142 */
[e138de]143bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
[14de469]144{
145 if (out != NULL) {
146 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[0a4f7f]147 *out << x[0] << "\t" << x[1] << "\t" << x[2];
[943d02]148 *out << "\t" << FixedIon;
149 if (v.Norm() > MYEPSILON)
[0a4f7f]150 *out << "\t" << scientific << setprecision(6) << v[0] << "\t" << v[1] << "\t" << v[2] << "\t";
[437922]151 if (comment != NULL)
152 *out << " # " << comment << endl;
[e9f8f9]153 else
154 *out << " # molecule nr " << nr << endl;
155 return true;
156 } else
157 return false;
158};
[b453f9]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 */
[43dad6]167bool atom::OutputArrayIndexed(ostream * const out, const int *ElementNo, int *AtomNo, const char *comment) const
[e9f8f9]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;
[0a4f7f]172 *out << x[0] << "\t" << x[1] << "\t" << x[2];
[e9f8f9]173 *out << "\t" << FixedIon;
174 if (v.Norm() > MYEPSILON)
[0a4f7f]175 *out << "\t" << scientific << setprecision(6) << v[0] << "\t" << v[1] << "\t" << v[2] << "\t";
[e9f8f9]176 if (comment != NULL)
177 *out << " # " << comment << endl;
[437922]178 else
179 *out << " # molecule nr " << nr << endl;
[14de469]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
[e41951]187 * \return true - \a *out present, false - \a *out is NULL
[14de469]188 */
189bool atom::OutputXYZLine(ofstream *out) const
190{
191 if (out != NULL) {
[0a4f7f]192 *out << type->symbol << "\t" << x[0] << "\t" << x[1] << "\t" << x[2] << "\t" << endl;
[14de469]193 return true;
194 } else
195 return false;
196};
197
[fcd7b6]198/** Output of a single atom as one lin in xyz file.
199 * \param *out stream to output to
[e41951]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
[fcd7b6]204 */
[e138de]205bool atom::OutputTrajectory(ofstream * const out, const int *ElementNo, int *AtomNo, const int step) const
[fcd7b6]206{
207 AtomNo[type->Z]++;
208 if (out != NULL) {
209 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
[0a4f7f]210 *out << Trajectory.R.at(step)[0] << "\t" << Trajectory.R.at(step)[1] << "\t" << Trajectory.R.at(step)[2];
[fcd7b6]211 *out << "\t" << FixedIon;
212 if (Trajectory.U.at(step).Norm() > MYEPSILON)
[0a4f7f]213 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step)[0] << "\t" << Trajectory.U.at(step)[1] << "\t" << Trajectory.U.at(step)[2] << "\t";
[fcd7b6]214 if (Trajectory.F.at(step).Norm() > MYEPSILON)
[0a4f7f]215 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step)[0] << "\t" << Trajectory.F.at(step)[1] << "\t" << Trajectory.F.at(step)[2] << "\t";
[fcd7b6]216 *out << "\t# Number in molecule " << nr << endl;
217 return true;
218 } else
219 return false;
220};
221
[681a8a]222/** Output of a single atom as one lin in xyz file.
223 * \param *out stream to output to
[e41951]224 * \param step Trajectory time step to output
225 * \return true - \a *out present, false - \a *out is NULL
[681a8a]226 */
[e138de]227bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
[681a8a]228{
229 if (out != NULL) {
230 *out << type->symbol << "\t";
[0a4f7f]231 *out << Trajectory.R.at(step)[0] << "\t";
232 *out << Trajectory.R.at(step)[1] << "\t";
233 *out << Trajectory.R.at(step)[2] << endl;
[681a8a]234 return true;
235 } else
236 return false;
237};
238
[4455f4]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 */
[1b2d30]244void atom::OutputMPQCLine(ostream * const out, const Vector *center, int *AtomNo = NULL) const
[4455f4]245{
[0a4f7f]246 *out << "\t\t" << type->symbol << " [ " << x[0]-center->at(0) << "\t" << x[1]-center->at(1) << "\t" << x[2]-center->at(2) << " ]" << endl;
[4455f4]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 */
[b453f9]255bool atom::Compare(const atom &ptr) const
[4455f4]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 */
[b453f9]267double atom::DistanceSquaredToVector(const Vector &origin) const
[4455f4]268{
[273382]269 return origin.DistanceSquared(x);
[4455f4]270};
271
272/** Returns distance to a given vector.
273 * \param origin vector to calculate distance to
274 * \return distance
275 */
[b453f9]276double atom::DistanceToVector(const Vector &origin) const
[4455f4]277{
[1513a74]278 return origin.distance(x);
[4455f4]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)
[920c70]287 delete[](ComponentNr);
288 ComponentNr = new int[ListOfBonds.size()+1];
[4455f4]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
[46d958]299World *atom::getWorld(){
300 return world;
301}
302
303void atom::setWorld(World* _world){
304 world = _world;
305}
306
[88d586]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) {
[46d958]320 id=_id;
321}
322
[ad2b411]323atomId_t atom::getId() const {
[46d958]324 return id;
325}
326
[6cfa36]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
[c084cc]336molecule* atom::getMolecule(){
337 return mol;
338}
339
[6cfa36]340void atom::removeFromMolecule(){
341 if(mol){
342 if(mol->containsAtom(this)){
343 mol->erase(this);
344 }
345 mol=0;
346 }
347}
348
349
[88d586]350atom* NewAtom(atomId_t _id){
351 atom * res =new atom();
352 res->setId(_id);
353 return res;
[46d958]354}
355
[88d586]356void DeleteAtom(atom* atom){
[46d958]357 delete atom;
358}
Note: See TracBrowser for help on using the repository browser.