| [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] | 14 | atom::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 | */ | 
|---|
|  | 36 | atom::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] | 62 | atom::~atom() | 
|---|
| [14de469] | 63 | { | 
|---|
| [29812d] | 64 | Free(&ComponentNr); | 
|---|
| [14de469] | 65 | }; | 
|---|
|  | 66 |  | 
|---|
|  | 67 |  | 
|---|
|  | 68 | /** Climbs up the father list until NULL, last is returned. | 
|---|
|  | 69 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen) | 
|---|
|  | 70 | */ | 
|---|
|  | 71 | atom *atom::GetTrueFather() | 
|---|
|  | 72 | { | 
|---|
|  | 73 | atom *walker = this; | 
|---|
|  | 74 | do { | 
|---|
|  | 75 | if (walker == walker->father) // top most father is the one that points on itself | 
|---|
|  | 76 | break; | 
|---|
|  | 77 | walker = walker->father; | 
|---|
|  | 78 | } while (walker != NULL); | 
|---|
|  | 79 | return walker; | 
|---|
|  | 80 | }; | 
|---|
|  | 81 |  | 
|---|
|  | 82 | /** Output of a single atom. | 
|---|
|  | 83 | * \param ElementNo cardinal number of the element | 
|---|
|  | 84 | * \param AtomNo cardinal number among these atoms of the same element | 
|---|
|  | 85 | * \param *out stream to output to | 
|---|
| [1907a7] | 86 | * \param *comment commentary after '#' sign | 
|---|
| [14de469] | 87 | */ | 
|---|
| [1907a7] | 88 | bool atom::Output(int ElementNo, int AtomNo, ofstream *out, const char *comment) const | 
|---|
| [14de469] | 89 | { | 
|---|
|  | 90 | if (out != NULL) { | 
|---|
|  | 91 | *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint; | 
|---|
| [943d02] | 92 | *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2]; | 
|---|
|  | 93 | *out << "\t" << FixedIon; | 
|---|
|  | 94 | if (v.Norm() > MYEPSILON) | 
|---|
|  | 95 | *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t"; | 
|---|
| [437922] | 96 | if (comment != NULL) | 
|---|
|  | 97 | *out << " # " << comment << endl; | 
|---|
|  | 98 | else | 
|---|
|  | 99 | *out << " # molecule nr " << nr << endl; | 
|---|
| [14de469] | 100 | return true; | 
|---|
|  | 101 | } else | 
|---|
|  | 102 | return false; | 
|---|
|  | 103 | }; | 
|---|
|  | 104 |  | 
|---|
|  | 105 | /** Output of a single atom as one lin in xyz file. | 
|---|
|  | 106 | * \param *out stream to output to | 
|---|
|  | 107 | */ | 
|---|
|  | 108 | bool atom::OutputXYZLine(ofstream *out) const | 
|---|
|  | 109 | { | 
|---|
|  | 110 | if (out != NULL) { | 
|---|
|  | 111 | *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl; | 
|---|
|  | 112 | return true; | 
|---|
|  | 113 | } else | 
|---|
|  | 114 | return false; | 
|---|
|  | 115 | }; | 
|---|
|  | 116 |  | 
|---|
| [321a11] | 117 | ostream & operator << (ostream &ost, const atom &a) | 
|---|
| [14de469] | 118 | { | 
|---|
|  | 119 | ost << "[" << a.Name << "|" << &a << "]"; | 
|---|
|  | 120 | return ost; | 
|---|
|  | 121 | }; | 
|---|
|  | 122 |  | 
|---|
| [055861] | 123 | ostream & atom::operator << (ostream &ost) | 
|---|
|  | 124 | { | 
|---|
|  | 125 | ost << "[" << Name << "|" << this << "]"; | 
|---|
|  | 126 | return ost; | 
|---|
|  | 127 | }; | 
|---|
|  | 128 |  | 
|---|
| [14de469] | 129 | /** Compares the indices of \a this atom with a given \a ptr. | 
|---|
|  | 130 | * \param ptr atom to compare index against | 
|---|
|  | 131 | * \return true - this one's is smaller, false - not | 
|---|
| [1907a7] | 132 | */ | 
|---|
| [321a11] | 133 | bool atom::Compare(const atom &ptr) | 
|---|
| [14de469] | 134 | { | 
|---|
|  | 135 | if (nr < ptr.nr) | 
|---|
|  | 136 | return true; | 
|---|
|  | 137 | else | 
|---|
|  | 138 | return false; | 
|---|
|  | 139 | }; | 
|---|
|  | 140 |  | 
|---|
| [1907a7] | 141 | bool operator < (atom &a, atom &b) | 
|---|
| [14de469] | 142 | { | 
|---|
|  | 143 | return a.Compare(b); | 
|---|
|  | 144 | }; | 
|---|
|  | 145 |  | 
|---|