42#include "utils/simError.h"
45#define FILE_SEP_CHAR "\\"
47#define FILE_SEP_CHAR "/"
51#define BUFF_SIZE 32768
61 std::vector<Element*>::iterator i;
62 for (i = elements_.begin(); i != elements_.end(); ++i)
70 RealType Rcov, Rvdw, mass, elNeg, ARENeg, ionize, elAffin;
71 RealType red, green, blue;
74 if (buffer[0] !=
'#') {
76 "%d %3s %lf %lf %*f %lf %d %lf %lf %lf %lf %lf %lf %lf %255s",
77 &num, symbol, &ARENeg, &Rcov, &Rvdw, &maxbonds, &mass, &elNeg,
78 &ionize, &elAffin, &red, &green, &blue, name);
81 new Element(num, symbol, ARENeg, Rcov, Rvdw, maxbonds, mass, elNeg,
82 ionize, elAffin, red, green, blue, name);
83 elements_.push_back(ele);
90 return elements_.size();
96 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
99 return (elements_[atomicnum]->
GetSymbol());
105 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
114 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
123 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
132 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
141 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
150 std::vector<RealType> colors;
153 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size())) {
154 colors.push_back(0.0);
155 colors.push_back(0.0);
156 colors.push_back(0.0);
160 colors.push_back(elements_[atomicnum]->GetRed());
161 colors.push_back(elements_[atomicnum]->GetGreen());
162 colors.push_back(elements_[atomicnum]->GetBlue());
170 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
173 return (elements_[atomicnum]->
GetName());
179 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
182 return (elements_[atomicnum]->
GetVdwRad());
189 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
192 rad = elements_[atomicnum]->GetCovalentRad();
206 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
209 rad = elements_[atomicnum]->GetVdwRad();
222 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
231 if (atomicnum < 0 || atomicnum >=
static_cast<int>(elements_.size()))
234 return (elements_[atomicnum]->
GetMass());
246 std::vector<Element*>::iterator i;
247 for (i = elements_.begin(); i != elements_.end(); ++i)
248 if (!strncasecmp(identifier, (*i)->GetSymbol(), 3))
249 return ((*i)->GetAtomicNum());
253 int numCharsToTest = std::max<int>(strlen(identifier), 5);
254 for (i = elements_.begin(); i != elements_.end(); ++i)
255 if (strncasecmp(identifier, (*i)->GetName().c_str(), numCharsToTest) == 0)
256 return ((*i)->GetAtomicNum());
258 if (strcasecmp(identifier,
"D") == 0 ||
259 (strcasecmp(identifier,
"Deuterium") == 0)) {
262 }
else if (strcasecmp(identifier,
"T") == 0 ||
263 (strcasecmp(identifier,
"Tritium") == 0)) {
266 }
else if (strcasecmp(identifier,
"Hl") == 0) {
268 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
269 "ElementsTable warning.\n"
270 "\tCannot understand the element label %s\n"
271 "\tGuessing it's hydrogen\n",
273 painCave.isFatal = 0;
274 painCave.severity = OPENMD_WARNING;
280 if (identifier[0] !=
'*') {
301 char charBuffer[BUFF_SIZE];
302 tempPath = getenv(
"FORCE_PARAM_PATH");
304 if (tempPath == NULL) {
306 STR_DEFINE(
dir_, FRC_PATH);
325 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
326 "Error opening the ElementsTable file:\n"
328 "\tHave you tried setting the FORCE_PARAM_PATH environment "
331 painCave.severity = OPENMD_ERROR;
332 painCave.isFatal = 1;
338 while (efStream->getline(charBuffer, BUFF_SIZE))
344 if (GetSize() == 0) {
345 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
346 "ElementsTable error.\n"
347 "\tCannot initialize database %s \n",
349 painCave.isFatal = 0;
This basic Periodic Table class was originally taken from the data.h file in OpenBabel.
std::string dir_
data directory for file if _envvar fails
bool init_
whether the data been read already
RealType CorrectedVdwRad(int atomicnum, int hyb=3)
RealType CorrectedBondRad(int atomicnum, int hyb=3)
RealType GetCovalentRad(int atomicnum)
~ElementsTable()
Destructor.
const char * GetSymbol(int atomicnum)
unsigned int GetNumberOfElements()
RealType GetAllredRochowElectroNeg(int atomicnum)
ElementsTable()
Constructor.
std::vector< RealType > GetRGB(int atomicnum)
std::string filename_
file to search for
int GetMaxBonds(int atomicnum)
RealType GetElectronAffinity(int atomicnum)
RealType GetIonization(int atomicnum)
RealType GetMass(int atomicnum)
std::string GetName(int atomicnum)
void Init()
Read in the data file.
void ParseLine(const char *line)
Specified by particular table classes (parses an individual data line)
RealType GetVdwRad(int atomicnum)
RealType GetElectroNeg(int atomicnum)
int GetAtomicNum(const char *str)
ifstrstream class provides a stream interface to read data from files.
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in, bool checkFilename=false)
Opens a file and associates a buffer with the specified file to perform the i/o operations (single mo...
bool is_open()
Tests if the stream is currently associated with a valid buffer.
void close()
In single mode, closes a file.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.