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