| [14de469] | 1 | /** \file atom.cpp | 
|---|
|  | 2 | * | 
|---|
|  | 3 | * Function implementations for the class atom. | 
|---|
|  | 4 | * | 
|---|
|  | 5 | */ | 
|---|
|  | 6 |  | 
|---|
|  | 7 | #include "molecules.hpp" | 
|---|
|  | 8 |  | 
|---|
|  | 9 | /************************************* Functions for class atom *************************************/ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | /** Constructor of class atom. | 
|---|
|  | 12 | */ | 
|---|
|  | 13 | atom::atom() | 
|---|
|  | 14 | { | 
|---|
|  | 15 | Name = NULL; | 
|---|
|  | 16 | previous = NULL; | 
|---|
|  | 17 | next = NULL; | 
|---|
|  | 18 | father = this;  // generally, father is itself | 
|---|
|  | 19 | Ancestor = NULL; | 
|---|
|  | 20 | type = NULL; | 
|---|
|  | 21 | sort = NULL; | 
|---|
| [943d02] | 22 | FixedIon = 0; | 
|---|
| [14de469] | 23 | nr = -1; | 
|---|
|  | 24 | GraphNr = -1; | 
|---|
|  | 25 | ComponentNr = NULL; | 
|---|
| [683914] | 26 | IsCyclic = false; | 
|---|
| [14de469] | 27 | SeparationVertex = false; | 
|---|
|  | 28 | LowpointNr = -1; | 
|---|
| [db942e] | 29 | AdaptiveOrder = 0; | 
|---|
| [14de469] | 30 | }; | 
|---|
|  | 31 |  | 
|---|
|  | 32 | /** Destructor of class atom. | 
|---|
|  | 33 | */ | 
|---|
|  | 34 | atom::~atom() | 
|---|
|  | 35 | { | 
|---|
|  | 36 | Free((void **)&Name, "atom::~atom: *Name"); | 
|---|
|  | 37 | Free((void **)&ComponentNr, "atom::~atom: *ComponentNr"); | 
|---|
|  | 38 | }; | 
|---|
|  | 39 |  | 
|---|
|  | 40 |  | 
|---|
|  | 41 | /** Climbs up the father list until NULL, last is returned. | 
|---|
|  | 42 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen) | 
|---|
|  | 43 | */ | 
|---|
|  | 44 | atom *atom::GetTrueFather() | 
|---|
|  | 45 | { | 
|---|
|  | 46 | atom *walker = this; | 
|---|
|  | 47 | do { | 
|---|
|  | 48 | if (walker == walker->father) // top most father is the one that points on itself | 
|---|
|  | 49 | break; | 
|---|
|  | 50 | walker = walker->father; | 
|---|
|  | 51 | } while (walker != NULL); | 
|---|
|  | 52 | return walker; | 
|---|
|  | 53 | }; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | /** Output of a single atom. | 
|---|
|  | 56 | * \param ElementNo cardinal number of the element | 
|---|
|  | 57 | * \param AtomNo cardinal number among these atoms of the same element | 
|---|
|  | 58 | * \param *out stream to output to | 
|---|
|  | 59 | */ | 
|---|
|  | 60 | bool atom::Output(int ElementNo, int AtomNo, ofstream *out) const | 
|---|
|  | 61 | { | 
|---|
|  | 62 | if (out != NULL) { | 
|---|
|  | 63 | *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint; | 
|---|
| [943d02] | 64 | *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2]; | 
|---|
|  | 65 | *out << "\t" << FixedIon; | 
|---|
|  | 66 | if (v.Norm() > MYEPSILON) | 
|---|
|  | 67 | *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t"; | 
|---|
|  | 68 | *out << " # Number in molecule " << nr << endl; | 
|---|
| [14de469] | 69 | return true; | 
|---|
|  | 70 | } else | 
|---|
|  | 71 | return false; | 
|---|
|  | 72 | }; | 
|---|
|  | 73 |  | 
|---|
|  | 74 | /** Output of a single atom as one lin in xyz file. | 
|---|
|  | 75 | * \param *out stream to output to | 
|---|
|  | 76 | */ | 
|---|
|  | 77 | bool atom::OutputXYZLine(ofstream *out) const | 
|---|
|  | 78 | { | 
|---|
|  | 79 | if (out != NULL) { | 
|---|
|  | 80 | *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl; | 
|---|
|  | 81 | return true; | 
|---|
|  | 82 | } else | 
|---|
|  | 83 | return false; | 
|---|
|  | 84 | }; | 
|---|
|  | 85 |  | 
|---|
|  | 86 | ostream & operator << (ostream &ost, atom &a) | 
|---|
|  | 87 | { | 
|---|
|  | 88 | ost << "[" << a.Name << "|" << &a << "]"; | 
|---|
|  | 89 | return ost; | 
|---|
|  | 90 | }; | 
|---|
|  | 91 |  | 
|---|
|  | 92 | /** Compares the indices of \a this atom with a given \a ptr. | 
|---|
|  | 93 | * \param ptr atom to compare index against | 
|---|
|  | 94 | * \return true - this one's is smaller, false - not | 
|---|
|  | 95 | */ | 
|---|
|  | 96 | bool atom::Compare(atom &ptr) | 
|---|
|  | 97 | { | 
|---|
|  | 98 | if (nr < ptr.nr) | 
|---|
|  | 99 | return true; | 
|---|
|  | 100 | else | 
|---|
|  | 101 | return false; | 
|---|
|  | 102 | }; | 
|---|
|  | 103 |  | 
|---|
|  | 104 | bool operator < (atom &a, atom &b) | 
|---|
|  | 105 | { | 
|---|
|  | 106 | return a.Compare(b); | 
|---|
|  | 107 | }; | 
|---|
|  | 108 |  | 
|---|