From 1ce7159e1d7b5e6a3c7fcd18748d9d19b3b28d65 Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Tue, 10 Oct 2017 19:39:41 -0400 Subject: [PATCH 1/2] Fix reading atom symbols from XSF file This is from the [official definition of XSF format](http://www.xcrysden.org/doc/XSF.html#__toc__3): > An entry for an atom looks like: > AtNum X Y Z > where AtNum stands for atomic number (or symbol), while X Y Z are > Cartesian coordinates in ANGSTROMS units. Here is one example: # Please > enter the commit message for your changes. Lines starting --- src/formats/xsfformat.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/formats/xsfformat.cpp b/src/formats/xsfformat.cpp index fa1e455366..1e03577418 100644 --- a/src/formats/xsfformat.cpp +++ b/src/formats/xsfformat.cpp @@ -81,6 +81,7 @@ namespace OpenBabel vector vs; vector atomPositions; bool createdAtoms = false; + int atomicNum; mol.BeginModify(); @@ -96,7 +97,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()); @@ -137,7 +142,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()); From 976936a741b42497eeaa4433a07431b83016cfe6 Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Tue, 17 Oct 2017 16:11:36 -0400 Subject: [PATCH 2/2] added comment in the file --- src/formats/xsfformat.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/formats/xsfformat.cpp b/src/formats/xsfformat.cpp index 1e03577418..f9419501a3 100644 --- a/src/formats/xsfformat.cpp +++ b/src/formats/xsfformat.cpp @@ -90,7 +90,8 @@ 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) {