Skip to content

Commit

Permalink
Merge pull request #1663 from sencer/master
Browse files Browse the repository at this point in the history
Fix reading atom symbols from XSF file
  • Loading branch information
ghutchis committed Oct 19, 2017
2 parents 19b8b26 + 976936a commit c70ca0d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/formats/xsfformat.cpp
Expand Up @@ -81,6 +81,7 @@ namespace OpenBabel
vector<string> vs;
vector<vector3> atomPositions;
bool createdAtoms = false;
int atomicNum;

mol.BeginModify();

Expand All @@ -89,14 +90,19 @@ namespace OpenBabel
if (buffer[0] == '#')
continue; // comment
if (strstr(buffer, "ATOMS") != NULL) {
// Minimum of 4 columns -- atomic number, x, y, z (forces)
// Minimum of 4 columns -- AtNum, x, y, z (forces)
// where AtNum stands for atomic number (or symbol), while X Y Z are
ifs.getline(buffer, BUFF_SIZE);
tokenize(vs, buffer);
while (vs.size() >= 4) {
if (!createdAtoms) {
atom = mol.NewAtom();
//set atomic number
atom->SetAtomicNum(atoi(vs[0].c_str()));
atomicNum = OBElements::GetAtomicNum(vs[0].c_str());
if (atomicNum == 0) {
atomicNum = atoi(vs[0].c_str());
}
atom->SetAtomicNum(atomicNum);
}
x = atof((char*)vs[1].c_str());
y = atof((char*)vs[2].c_str());
Expand Down Expand Up @@ -137,7 +143,11 @@ namespace OpenBabel
if (!createdAtoms) {
atom = mol.NewAtom();
//set atomic number
atom->SetAtomicNum(atoi(vs[0].c_str()));
atomicNum = OBElements::GetAtomicNum(vs[0].c_str());
if (atomicNum == 0) {
atomicNum = atoi(vs[0].c_str());
}
atom->SetAtomicNum(atomicNum);
}
x = atof((char*)vs[1].c_str());
y = atof((char*)vs[2].c_str());
Expand Down

0 comments on commit c70ca0d

Please sign in to comment.