source: src/atom.cpp@ cd5047

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

Merge branch 'StructureRefactoring' into stable

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/periodentafel.cpp

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