Hallo,
please find attached the svn diff for the abinit parsing code.
I lightly tested it with some of my outputs.

I noticed that conversion to cif output discards information about
cell orientation, is this a limitation in cif format?

Fulvio

From: Geoffrey Hutchison <geoff.hutchi...@gmail.com>
Subject: Re: [OpenBabel-Devel] abinit parsing
Date: Mon, 15 Apr 2013 13:07:24 -0400

>> I think this is the general pattern, though I am not sure.
>> 
>> If you agree with the above, I will gladly patch the code.
> 
> Yes, I would agree with this. It's a combination of laziness and not having 
> very many abinit files to test.
> 
> Thanks!
> -Geoff
> 
Index: formats/abinitformat.cpp
===================================================================
--- formats/abinitformat.cpp	(revision 5060)
+++ formats/abinitformat.cpp	(working copy)
@@ -79,7 +79,7 @@
     vector<string> vs;
 
     OBAtom *atom;
-    int natom;
+    int natom=-1;
     vector<int> atomicNumbers, atomTypes;
     double x, y, z;
     vector<vector3> atomPositions;
@@ -108,24 +108,32 @@
           }
         }
         // Sometimes Cartesian has lower-case letter
-        else if (strstr(buffer, "artesian coordinates")) {
+        else if 
+          ((strstr(buffer, "artesian coordinates")) &&
+           (strstr(buffer, "(xcart)")) &&
+           (natom > -1) //be sure natom has already been read
+           )
+          {
           double unit = BOHR_TO_ANGSTROM;
           if (strstr(buffer, "ngstrom"))
             unit = 1.0; // no conversion needed
-
-          ifs.getline(buffer,BUFF_SIZE);
-          tokenize(vs, buffer);
-          while(vs.size() == 3) {
-            x = atof(vs[0].c_str()) * unit;
-            y = atof(vs[1].c_str()) * unit;
-            z = atof(vs[2].c_str()) * unit;
-
-            atomPositions.push_back(vector3(x, y, z));
-            // get next line
-            ifs.getline(buffer,BUFF_SIZE);
-            tokenize(vs, buffer);
+          for (int i=0;i<natom;i++)
+            {
+              ifs.getline(buffer,BUFF_SIZE);
+              tokenize(vs, buffer);
+              if (vs.size() != 3) {
+                obErrorLog.ThrowError
+                  (__FUNCTION__,
+                   "error while parsing coordinates of atoms", obWarning);
+                return(false);
+              }
+              x = atof(vs[0].c_str()) * unit;
+              y = atof(vs[1].c_str()) * unit;
+              z = atof(vs[2].c_str()) * unit;
+              atomPositions.push_back(vector3(x, y, z));
+              // get next line
+            }
           }
-        }
         else if (strstr(buffer, "natom")) {
           tokenize(vs, buffer);
           if (vs.size() != 2)
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to