[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[bcf653] | 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 |
|
---|
[83f176] | 106 | double element::getMass() const
|
---|
| 107 | {
|
---|
| 108 | return mass;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | double element::getCovalentRadius() const
|
---|
| 112 | {
|
---|
| 113 | return CovalentRadius;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[064178] | 116 | const unsigned char * element::getColor() const
|
---|
| 117 | {
|
---|
| 118 | return color;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[67c92b] | 121 | double element::getElectronegativity() const
|
---|
| 122 | {
|
---|
| 123 | return Electronegativity;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[83f176] | 126 | double element::getVanDerWaalsRadius() const
|
---|
| 127 | {
|
---|
| 128 | return VanDerWaalsRadius;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[ed26ae] | 131 | atomicNumber_t element::getAtomicNumber() const
|
---|
[83f176] | 132 | {
|
---|
| 133 | return Z;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | double element::getValence() const
|
---|
| 137 | {
|
---|
| 138 | return Valence;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | int element::getNoValenceOrbitals() const
|
---|
| 142 | {
|
---|
| 143 | return NoValenceOrbitals;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[bae8b0] | 146 | double element::getHBondDistance(const size_t i) const
|
---|
[83f176] | 147 | {
|
---|
[bae8b0] | 148 | ASSERT((i<3), "Access to element::HBondDistance out of bounds.");
|
---|
[83f176] | 149 | return HBondDistance[i];
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[bae8b0] | 152 | double element::getHBondAngle(const size_t i) const
|
---|
[83f176] | 153 | {
|
---|
[bae8b0] | 154 | ASSERT((i<3), "Access to element::HBondAngle out of bounds.");
|
---|
[83f176] | 155 | return HBondAngle[i];
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[7e3fc94] | 158 | const string &element::getSymbol() const{
|
---|
| 159 | return symbol;
|
---|
[ff6a10] | 160 | }
|
---|
[83f176] | 161 |
|
---|
| 162 | void element::setSymbol(const std::string &temp)
|
---|
| 163 | {
|
---|
| 164 | symbol = temp;
|
---|
| 165 | }
|
---|
[ff6a10] | 166 |
|
---|
[7e3fc94] | 167 | const std::string &element::getName() const{
|
---|
| 168 | return name;
|
---|
[ff6a10] | 169 | }
|
---|
[83f176] | 170 |
|
---|
| 171 | void element::setName(const std::string &temp)
|
---|
| 172 | {
|
---|
| 173 | name = temp;
|
---|
| 174 | }
|
---|
[ff6a10] | 175 |
|
---|
[d7d022] | 176 | /** Comparison operator for stub of Element.
|
---|
| 177 | *
|
---|
| 178 | * @param other other instance to compare to
|
---|
| 179 | * @return true if all member variables have the same contents.
|
---|
| 180 | */
|
---|
| 181 | bool element::operator==(const element &other) const
|
---|
| 182 | {
|
---|
| 183 | if (mass != other.mass) return false;
|
---|
| 184 | if (CovalentRadius != other.CovalentRadius) return false;
|
---|
| 185 | if (Electronegativity != other.Electronegativity) return false;
|
---|
| 186 | if (VanDerWaalsRadius != other.VanDerWaalsRadius) return false;
|
---|
| 187 | if (Z != other.Z) return false;
|
---|
| 188 | if (period != other.period) return false;
|
---|
| 189 | if (group != other.group) return false;
|
---|
| 190 | if (block != other.block) return false;
|
---|
| 191 | if (Valence != other.Valence) return false;
|
---|
| 192 | if (NoValenceOrbitals != other.NoValenceOrbitals) return false;
|
---|
| 193 | for (size_t i = 0; i < 3; ++i)
|
---|
| 194 | if (HBondDistance[i] != other.HBondDistance[i]) return false;
|
---|
| 195 | for (size_t i = 0; i < 3; ++i)
|
---|
| 196 | if (HBondAngle[i] != other.HBondAngle[i]) return false;
|
---|
| 197 | for (size_t i = 0; i < 3; ++i)
|
---|
| 198 | if (color[i] != other.color[i]) return false;
|
---|
| 199 | if (name != other.name) return false;
|
---|
| 200 | if (symbol != other.symbol) return false;
|
---|
| 201 | return true;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[e345e3] | 204 | std::ostream &operator<<(std::ostream &ost,const element &elem){
|
---|
[ed26ae] | 205 | ost << elem.getName() << "(" << elem.getAtomicNumber() << ")";
|
---|
[e345e3] | 206 | return ost;
|
---|
| 207 | }
|
---|
[d7d022] | 208 |
|
---|