[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[14de469] | 8 | /** \file element.cpp
|
---|
| 9 | *
|
---|
| 10 | * Function implementations for the class element.
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
| 13 |
|
---|
[bf3817] | 14 | // include config.h
|
---|
| 15 | #ifdef HAVE_CONFIG_H
|
---|
| 16 | #include <config.h>
|
---|
| 17 | #endif
|
---|
[bae8b0] | 18 |
|
---|
[ad011c] | 19 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 20 |
|
---|
[cd4ccc] | 21 | #include <iomanip>
|
---|
| 22 | #include <fstream>
|
---|
| 23 |
|
---|
[ad011c] | 24 | #include "CodePatterns/Assert.hpp"
|
---|
[907636] | 25 | #include "CodePatterns/Log.hpp"
|
---|
[bae8b0] | 26 | #include "element.hpp"
|
---|
[14de469] | 27 |
|
---|
[ead4e6] | 28 | using namespace std;
|
---|
| 29 |
|
---|
[14de469] | 30 | /************************************* Functions for class element **********************************/
|
---|
| 31 |
|
---|
| 32 | /** Constructor of class element.
|
---|
| 33 | */
|
---|
[d5af3e] | 34 | element::element() :
|
---|
| 35 | mass(0),
|
---|
| 36 | CovalentRadius(0),
|
---|
[bae8b0] | 37 | Electronegativity(0.),
|
---|
| 38 | VanDerWaalsRadius(0),
|
---|
| 39 | Z(0),
|
---|
| 40 | period(""),
|
---|
| 41 | group(""),
|
---|
| 42 | block(""),
|
---|
[d5af3e] | 43 | Valence(0),
|
---|
[bae8b0] | 44 | NoValenceOrbitals(0),
|
---|
| 45 | name(""),
|
---|
| 46 | symbol("")
|
---|
[d5af3e] | 47 | {
|
---|
[bae8b0] | 48 | for (size_t i =0; i<3;++i)
|
---|
| 49 | color[i] = (unsigned char)0;
|
---|
| 50 | for (size_t i =0; i<3;++i)
|
---|
| 51 | HBondDistance[i] = 0.;
|
---|
| 52 | for (size_t i =0; i<3;++i)
|
---|
| 53 | HBondAngle[i] = 0.;
|
---|
[27c6be] | 54 | };
|
---|
[14de469] | 55 |
|
---|
[2a76b0] | 56 | element::element(const element &src) :
|
---|
| 57 | mass(src.mass),
|
---|
| 58 | CovalentRadius(src.CovalentRadius),
|
---|
[bae8b0] | 59 | Electronegativity(src.Electronegativity),
|
---|
| 60 | VanDerWaalsRadius(src.VanDerWaalsRadius),
|
---|
[2a76b0] | 61 | Z(src.Z),
|
---|
[bae8b0] | 62 | period(src.period),
|
---|
| 63 | group(src.group),
|
---|
| 64 | block(src.block),
|
---|
[2a76b0] | 65 | Valence(src.Valence),
|
---|
| 66 | NoValenceOrbitals(src.NoValenceOrbitals),
|
---|
| 67 | name(src.name),
|
---|
[907636] | 68 | symbol(src.symbol)
|
---|
[2a76b0] | 69 | {
|
---|
[907636] | 70 | for (size_t i =0; i<3;++i)
|
---|
| 71 | color[i] = src.color[i];
|
---|
[bae8b0] | 72 | for (size_t i =0; i<3;++i)
|
---|
| 73 | HBondDistance[i] = src.HBondDistance[i];
|
---|
| 74 | for (size_t i =0; i<3;++i)
|
---|
| 75 | HBondAngle[i] = src.HBondAngle[i];
|
---|
[2a76b0] | 76 | }
|
---|
| 77 |
|
---|
[14de469] | 78 | /** Destructor of class element.
|
---|
| 79 | */
|
---|
| 80 | element::~element() {};
|
---|
| 81 |
|
---|
[2a76b0] | 82 | element &element::operator=(const element &src){
|
---|
| 83 | if(this!=&src){
|
---|
| 84 | mass=src.mass;
|
---|
[bae8b0] | 85 | CovalentRadius=src.CovalentRadius;
|
---|
| 86 | Electronegativity=src.Electronegativity;
|
---|
[2a76b0] | 87 | VanDerWaalsRadius=src.VanDerWaalsRadius;
|
---|
| 88 | Z=src.Z;
|
---|
[bae8b0] | 89 | period = src.period;
|
---|
| 90 | group = src.group;
|
---|
| 91 | block = src.block;
|
---|
[2a76b0] | 92 | Valence=src.Valence;
|
---|
| 93 | NoValenceOrbitals=src.NoValenceOrbitals;
|
---|
[907636] | 94 | for (size_t i =0; i<3;++i)
|
---|
| 95 | color[i] = src.color[i];
|
---|
[bae8b0] | 96 | for (size_t i =0; i<3;++i)
|
---|
| 97 | HBondDistance[i] = src.HBondDistance[i];
|
---|
| 98 | for (size_t i =0; i<3;++i)
|
---|
| 99 | HBondAngle[i] = src.HBondAngle[i];
|
---|
| 100 | name=src.name;
|
---|
| 101 | symbol=src.symbol;
|
---|
[2a76b0] | 102 | }
|
---|
| 103 | return *this;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[14de469] | 106 | /** Prints element data to \a *out.
|
---|
| 107 | * \param *out outstream
|
---|
| 108 | */
|
---|
[ead4e6] | 109 | bool element::Output(ostream * const out) const
|
---|
[14de469] | 110 | {
|
---|
[042f82] | 111 | if (out != NULL) {
|
---|
| 112 | *out << name << "\t" << symbol << "\t" << period << "\t" << group << "\t" << block << "\t" << Z << "\t" << mass << "\t" << CovalentRadius << "\t" << VanDerWaalsRadius << endl;
|
---|
| 113 | //*out << Z << "\t" << fixed << setprecision(11) << showpoint << mass << "g/mol\t" << name << "\t" << symbol << "\t" << endl;
|
---|
| 114 | return true;
|
---|
| 115 | } else
|
---|
| 116 | return false;
|
---|
[14de469] | 117 | };
|
---|
| 118 |
|
---|
| 119 | /** Prints element data to \a *out.
|
---|
| 120 | * \param *out outstream
|
---|
[042f82] | 121 | * \param No cardinal number of element
|
---|
[14de469] | 122 | * \param NoOfAtoms total number of atom of this element type
|
---|
| 123 | */
|
---|
[ead4e6] | 124 | bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const
|
---|
[14de469] | 125 | {
|
---|
[042f82] | 126 | if (out != NULL) {
|
---|
| 127 | *out << "Ion_Type" << Number << "\t" << NoOfAtoms << "\t" << Z << "\t1.0\t3\t3\t" << fixed << setprecision(11) << showpoint << mass << "\t" << name << "\t" << symbol <<endl;
|
---|
| 128 | return true;
|
---|
| 129 | } else
|
---|
| 130 | return false;
|
---|
[14de469] | 131 | };
|
---|
[ead4e6] | 132 |
|
---|
| 133 | atomicNumber_t element::getNumber() const{
|
---|
| 134 | return Z;
|
---|
| 135 | }
|
---|
[83f176] | 136 |
|
---|
| 137 | double element::getMass() const
|
---|
| 138 | {
|
---|
| 139 | return mass;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | double element::getCovalentRadius() const
|
---|
| 143 | {
|
---|
| 144 | return CovalentRadius;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[064178] | 147 | const unsigned char * element::getColor() const
|
---|
| 148 | {
|
---|
| 149 | return color;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[67c92b] | 152 | double element::getElectronegativity() const
|
---|
| 153 | {
|
---|
| 154 | return Electronegativity;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[83f176] | 157 | double element::getVanDerWaalsRadius() const
|
---|
| 158 | {
|
---|
| 159 | return VanDerWaalsRadius;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | int element::getAtomicNumber() const
|
---|
| 163 | {
|
---|
| 164 | return Z;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | double element::getValence() const
|
---|
| 168 | {
|
---|
| 169 | return Valence;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | int element::getNoValenceOrbitals() const
|
---|
| 173 | {
|
---|
| 174 | return NoValenceOrbitals;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[bae8b0] | 177 | double element::getHBondDistance(const size_t i) const
|
---|
[83f176] | 178 | {
|
---|
[bae8b0] | 179 | ASSERT((i<3), "Access to element::HBondDistance out of bounds.");
|
---|
[83f176] | 180 | return HBondDistance[i];
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[bae8b0] | 183 | double element::getHBondAngle(const size_t i) const
|
---|
[83f176] | 184 | {
|
---|
[bae8b0] | 185 | ASSERT((i<3), "Access to element::HBondAngle out of bounds.");
|
---|
[83f176] | 186 | return HBondAngle[i];
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[7e3fc94] | 189 | const string &element::getSymbol() const{
|
---|
| 190 | return symbol;
|
---|
[ff6a10] | 191 | }
|
---|
[83f176] | 192 |
|
---|
| 193 | void element::setSymbol(const std::string &temp)
|
---|
| 194 | {
|
---|
| 195 | symbol = temp;
|
---|
| 196 | }
|
---|
[ff6a10] | 197 |
|
---|
[7e3fc94] | 198 | const std::string &element::getName() const{
|
---|
| 199 | return name;
|
---|
[ff6a10] | 200 | }
|
---|
[83f176] | 201 |
|
---|
| 202 | void element::setName(const std::string &temp)
|
---|
| 203 | {
|
---|
| 204 | name = temp;
|
---|
| 205 | }
|
---|
[ff6a10] | 206 |
|
---|
[d7d022] | 207 | /** Comparison operator for stub of Element.
|
---|
| 208 | *
|
---|
| 209 | * @param other other instance to compare to
|
---|
| 210 | * @return true if all member variables have the same contents.
|
---|
| 211 | */
|
---|
| 212 | bool element::operator==(const element &other) const
|
---|
| 213 | {
|
---|
| 214 | if (mass != other.mass) return false;
|
---|
| 215 | if (CovalentRadius != other.CovalentRadius) return false;
|
---|
| 216 | if (Electronegativity != other.Electronegativity) return false;
|
---|
| 217 | if (VanDerWaalsRadius != other.VanDerWaalsRadius) return false;
|
---|
| 218 | if (Z != other.Z) return false;
|
---|
| 219 | if (period != other.period) return false;
|
---|
| 220 | if (group != other.group) return false;
|
---|
| 221 | if (block != other.block) return false;
|
---|
| 222 | if (Valence != other.Valence) return false;
|
---|
| 223 | if (NoValenceOrbitals != other.NoValenceOrbitals) return false;
|
---|
| 224 | for (size_t i = 0; i < 3; ++i)
|
---|
| 225 | if (HBondDistance[i] != other.HBondDistance[i]) return false;
|
---|
| 226 | for (size_t i = 0; i < 3; ++i)
|
---|
| 227 | if (HBondAngle[i] != other.HBondAngle[i]) return false;
|
---|
| 228 | for (size_t i = 0; i < 3; ++i)
|
---|
| 229 | if (color[i] != other.color[i]) return false;
|
---|
| 230 | if (name != other.name) return false;
|
---|
| 231 | if (symbol != other.symbol) return false;
|
---|
| 232 | return true;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[e345e3] | 235 | std::ostream &operator<<(std::ostream &ost,const element &elem){
|
---|
| 236 | ost << elem.getName() << "(" << elem.getNumber() << ")";
|
---|
| 237 | return ost;
|
---|
| 238 | }
|
---|
[d7d022] | 239 |
|
---|