source: src/atom.cpp@ a630fd

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

Removed the VectorIsInParallelepiped in favor of more general methods in the Shape class

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