source: src/atom.cpp@ 831a14

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 831a14 was 6b919f8, checked in by Frederik Heber <heber@…>, 16 years ago

Refactored atom.cpp into multiple files.

After the class atom was refactored into multiple base classes that are inherited, these base classes are also all put into separate files. This is basically a preparatory step for the like-wise refactoring of class molecule into inherited base classes and splitting up (that is there done already). Finally, we will also separate the relations, i.e. not have "atom.hpp" included everywhere and use class atom, but rather the subclasses such as TrajectoryParticle and its header files only.
Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 8.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"
[1907a7]15
[14de469]16/************************************* Functions for class atom *************************************/
17
18/** Constructor of class atom.
19 */
[1907a7]20atom::atom()
[14de469]21{
[357fba]22 father = this; // generally, father is itself
[14de469]23 previous = NULL;
24 next = NULL;
[4455f4]25 sort = &nr;
26
[357fba]27 // set LCNode::Vector to our Vector
28 node = &x;
[14de469]29};
30
[2319ed]31/** Constructor of class atom.
32 */
33atom::atom(atom *pointer)
34{
35 previous = NULL;
36 next = NULL;
[89c8b2]37 father = pointer; // generally, father is itself
[4455f4]38
[2319ed]39 type = pointer->type; // copy element of atom
40 x.CopyVector(&pointer->x); // copy coordination
41 v.CopyVector(&pointer->v); // copy velocity
42 FixedIon = pointer->FixedIon;
43 sort = &nr;
[89c8b2]44 node = &x;
[2319ed]45}
46
47
[14de469]48/** Destructor of class atom.
49 */
[1907a7]50atom::~atom()
[14de469]51{
[266237]52 unlink(this);
[14de469]53};
54
55
56/** Climbs up the father list until NULL, last is returned.
57 * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
58 */
59atom *atom::GetTrueFather()
60{
61 atom *walker = this;
62 do {
63 if (walker == walker->father) // top most father is the one that points on itself
64 break;
65 walker = walker->father;
66 } while (walker != NULL);
67 return walker;
68};
69
[e65246]70/** Sets father to itself or its father in case of copying a molecule.
71 */
72void atom::CorrectFather()
73{
74 if (father->father == father) // same atom in copy's father points to itself
75 father = this; // set father to itself (copy of a whole molecule)
76 else
77 father = father->father; // set father to original's father
78
79};
80
81/** Check whether father is equal to given atom.
82 * \param *ptr atom to compare father to
83 * \param **res return value (only set if atom::father is equal to \a *ptr)
84 */
85void atom::EqualsFather ( atom *ptr, atom **res )
86{
87 if ( ptr == father )
88 *res = this;
89};
90
[e9f8f9]91/** Checks whether atom is within the given box.
92 * \param offset offset to box origin
93 * \param *parallelepiped box matrix
94 * \return true - is inside, false - is not
95 */
96bool atom::IsInParallelepiped(Vector offset, double *parallelepiped)
97{
98 return (node->IsInParallelepiped(offset, parallelepiped));
99};
100
[266237]101/** Counts the number of bonds weighted by bond::BondDegree.
102 * \param bonds times bond::BondDegree
103 */
[4455f4]104int BondedParticle::CountBonds() const
[266237]105{
106 int NoBonds = 0;
107 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
108 NoBonds += (*Runner)->BondDegree;
109 return NoBonds;
110};
111
[14de469]112/** Output of a single atom.
113 * \param ElementNo cardinal number of the element
114 * \param AtomNo cardinal number among these atoms of the same element
115 * \param *out stream to output to
[1907a7]116 * \param *comment commentary after '#' sign
[e41951]117 * \return true - \a *out present, false - \a *out is NULL
[14de469]118 */
[fcd7b6]119bool atom::Output(ofstream *out, int ElementNo, int AtomNo, const char *comment) const
[14de469]120{
121 if (out != NULL) {
122 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[943d02]123 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
124 *out << "\t" << FixedIon;
125 if (v.Norm() > MYEPSILON)
126 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
[437922]127 if (comment != NULL)
128 *out << " # " << comment << endl;
[e9f8f9]129 else
130 *out << " # molecule nr " << nr << endl;
131 return true;
132 } else
133 return false;
134};
[fcd7b6]135bool atom::Output(ofstream *out, int *ElementNo, int *AtomNo, const char *comment)
[e9f8f9]136{
137 AtomNo[type->Z]++; // increment number
138 if (out != NULL) {
139 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
140 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
141 *out << "\t" << FixedIon;
142 if (v.Norm() > MYEPSILON)
143 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
144 if (comment != NULL)
145 *out << " # " << comment << endl;
[437922]146 else
147 *out << " # molecule nr " << nr << endl;
[14de469]148 return true;
149 } else
150 return false;
151};
152
153/** Output of a single atom as one lin in xyz file.
154 * \param *out stream to output to
[e41951]155 * \return true - \a *out present, false - \a *out is NULL
[14de469]156 */
157bool atom::OutputXYZLine(ofstream *out) const
158{
159 if (out != NULL) {
160 *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;
161 return true;
162 } else
163 return false;
164};
165
[fcd7b6]166/** Output of a single atom as one lin in xyz file.
167 * \param *out stream to output to
[e41951]168 * \param *ElementNo array with ion type number in the config file this atom's element shall have
169 * \param *AtomNo array with atom number in the config file this atom shall have, is increase by one automatically
170 * \param step Trajectory time step to output
171 * \return true - \a *out present, false - \a *out is NULL
[fcd7b6]172 */
173bool atom::OutputTrajectory(ofstream *out, int *ElementNo, int *AtomNo, int step) const
174{
175 AtomNo[type->Z]++;
176 if (out != NULL) {
177 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
178 *out << Trajectory.R.at(step).x[0] << "\t" << Trajectory.R.at(step).x[1] << "\t" << Trajectory.R.at(step).x[2];
179 *out << "\t" << FixedIon;
180 if (Trajectory.U.at(step).Norm() > MYEPSILON)
181 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step).x[0] << "\t" << Trajectory.U.at(step).x[1] << "\t" << Trajectory.U.at(step).x[2] << "\t";
182 if (Trajectory.F.at(step).Norm() > MYEPSILON)
183 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step).x[0] << "\t" << Trajectory.F.at(step).x[1] << "\t" << Trajectory.F.at(step).x[2] << "\t";
184 *out << "\t# Number in molecule " << nr << endl;
185 return true;
186 } else
187 return false;
188};
189
[681a8a]190/** Output of a single atom as one lin in xyz file.
191 * \param *out stream to output to
[e41951]192 * \param step Trajectory time step to output
193 * \return true - \a *out present, false - \a *out is NULL
[681a8a]194 */
195bool atom::OutputTrajectoryXYZ(ofstream *out, int step) const
196{
197 if (out != NULL) {
198 *out << type->symbol << "\t";
199 *out << Trajectory.R.at(step).x[0] << "\t";
200 *out << Trajectory.R.at(step).x[1] << "\t";
201 *out << Trajectory.R.at(step).x[2] << endl;
202 return true;
203 } else
204 return false;
205};
206
[4455f4]207/** Outputs the MPQC configuration line for this atom.
208 * \param *out output stream
209 * \param *center center of molecule subtracted from position
210 * \param *AtomNo pointer to atom counter that is increased by one
211 */
212void atom::OutputMPQCLine(ofstream *out, Vector *center, int *AtomNo = NULL) const
213{
214 *out << "\t\t" << type->symbol << " [ " << x.x[0]-center->x[0] << "\t" << x.x[1]-center->x[1] << "\t" << x.x[2]-center->x[2] << " ]" << endl;
215 if (AtomNo != NULL)
216 *AtomNo++;
217};
218
219ostream & operator << (ostream &ost, const ParticleInfo &a)
220{
221 ost << "[" << a.Name << "|" << &a << "]";
222 return ost;
223};
224
225ostream & ParticleInfo::operator << (ostream &ost)
226{
227 ost << "[" << Name << "|" << this << "]";
228 return ost;
229};
230
231/** Compares the indices of \a this atom with a given \a ptr.
232 * \param ptr atom to compare index against
233 * \return true - this one's is smaller, false - not
234 */
235bool atom::Compare(const atom &ptr)
236{
237 if (nr < ptr.nr)
238 return true;
239 else
240 return false;
241};
242
243/** Returns squared distance to a given vector.
244 * \param origin vector to calculate distance to
245 * \return distance squared
246 */
247double atom::DistanceSquaredToVector(Vector &origin)
248{
249 return origin.DistanceSquared(&x);
250};
251
252/** Returns distance to a given vector.
253 * \param origin vector to calculate distance to
254 * \return distance
255 */
256double atom::DistanceToVector(Vector &origin)
257{
258 return origin.Distance(&x);
259};
260
261/** Initialises the component number array.
262 * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
263 */
264void atom::InitComponentNr()
265{
266 if (ComponentNr != NULL)
267 Free(&ComponentNr);
268 ComponentNr = Malloc<int>(ListOfBonds.size()+1, "atom::InitComponentNumbers: *ComponentNr");
269 for (int i=ListOfBonds.size()+1;i--;)
270 ComponentNr[i] = -1;
271};
272
273
274bool operator < (atom &a, atom &b)
275{
276 return a.Compare(b);
277};
278
Note: See TracBrowser for help on using the repository browser.