source: src/atom.cpp@ e65246

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

New function atom::CorrectFactor() and atom::EqualsFather().

  • Property mode set to 100755
File size: 4.1 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"
[29812d]8#include "memoryallocator.hpp"
[1907a7]9
[14de469]10/************************************* Functions for class atom *************************************/
11
12/** Constructor of class atom.
13 */
[1907a7]14atom::atom()
[14de469]15{
[357fba]16 father = this; // generally, father is itself
[14de469]17 previous = NULL;
18 next = NULL;
19 Ancestor = NULL;
20 type = NULL;
21 sort = NULL;
[943d02]22 FixedIon = 0;
[14de469]23 GraphNr = -1;
24 ComponentNr = NULL;
[683914]25 IsCyclic = false;
[14de469]26 SeparationVertex = false;
27 LowpointNr = -1;
[db942e]28 AdaptiveOrder = 0;
[362b0e]29 MaxOrder = false;
[357fba]30 // set LCNode::Vector to our Vector
31 node = &x;
[14de469]32};
33
[2319ed]34/** Constructor of class atom.
35 */
36atom::atom(atom *pointer)
37{
38 Name = NULL;
39 previous = NULL;
40 next = NULL;
[89c8b2]41 father = pointer; // generally, father is itself
[2319ed]42 Ancestor = NULL;
[357fba]43 GraphNr = -1;
44 ComponentNr = NULL;
45 IsCyclic = false;
46 SeparationVertex = false;
47 LowpointNr = -1;
48 AdaptiveOrder = 0;
49 MaxOrder = false;
[2319ed]50 type = pointer->type; // copy element of atom
51 x.CopyVector(&pointer->x); // copy coordination
52 v.CopyVector(&pointer->v); // copy velocity
53 FixedIon = pointer->FixedIon;
54 nr = -1;
55 sort = &nr;
[89c8b2]56 node = &x;
[2319ed]57}
58
59
[14de469]60/** Destructor of class atom.
61 */
[1907a7]62atom::~atom()
[14de469]63{
[a33931]64 Free<int>(&ComponentNr, "atom::~atom: *ComponentNr");
[c26f44]65 Free<char>(&Name, "atom::~atom: *Name");
[14de469]66};
67
68
69/** Climbs up the father list until NULL, last is returned.
70 * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
71 */
72atom *atom::GetTrueFather()
73{
74 atom *walker = this;
75 do {
76 if (walker == walker->father) // top most father is the one that points on itself
77 break;
78 walker = walker->father;
79 } while (walker != NULL);
80 return walker;
81};
82
[e65246]83/** Sets father to itself or its father in case of copying a molecule.
84 */
85void atom::CorrectFather()
86{
87 if (father->father == father) // same atom in copy's father points to itself
88 father = this; // set father to itself (copy of a whole molecule)
89 else
90 father = father->father; // set father to original's father
91
92};
93
94/** Check whether father is equal to given atom.
95 * \param *ptr atom to compare father to
96 * \param **res return value (only set if atom::father is equal to \a *ptr)
97 */
98void atom::EqualsFather ( atom *ptr, atom **res )
99{
100 if ( ptr == father )
101 *res = this;
102};
103
[14de469]104/** Output of a single atom.
105 * \param ElementNo cardinal number of the element
106 * \param AtomNo cardinal number among these atoms of the same element
107 * \param *out stream to output to
[1907a7]108 * \param *comment commentary after '#' sign
[14de469]109 */
[1907a7]110bool atom::Output(int ElementNo, int AtomNo, ofstream *out, const char *comment) const
[14de469]111{
112 if (out != NULL) {
113 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[943d02]114 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
115 *out << "\t" << FixedIon;
116 if (v.Norm() > MYEPSILON)
117 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
[437922]118 if (comment != NULL)
119 *out << " # " << comment << endl;
120 else
121 *out << " # molecule nr " << nr << endl;
[14de469]122 return true;
123 } else
124 return false;
125};
126
127/** Output of a single atom as one lin in xyz file.
128 * \param *out stream to output to
129 */
130bool atom::OutputXYZLine(ofstream *out) const
131{
132 if (out != NULL) {
133 *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;
134 return true;
135 } else
136 return false;
137};
138
[321a11]139ostream & operator << (ostream &ost, const atom &a)
[14de469]140{
141 ost << "[" << a.Name << "|" << &a << "]";
142 return ost;
143};
144
[055861]145ostream & atom::operator << (ostream &ost)
146{
147 ost << "[" << Name << "|" << this << "]";
148 return ost;
149};
150
[14de469]151/** Compares the indices of \a this atom with a given \a ptr.
152 * \param ptr atom to compare index against
153 * \return true - this one's is smaller, false - not
[1907a7]154 */
[321a11]155bool atom::Compare(const atom &ptr)
[14de469]156{
157 if (nr < ptr.nr)
158 return true;
159 else
160 return false;
161};
162
[1907a7]163bool operator < (atom &a, atom &b)
[14de469]164{
165 return a.Compare(b);
166};
167
Note: See TracBrowser for help on using the repository browser.