source: src/atom.cpp@ 2a76b0

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

Made fields name and symbol of element class private

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