ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/openbabel/xyzformat.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/openbabel/xyzformat.cpp (file contents):
Revision 2440 by tim, Wed Nov 16 19:42:11 2005 UTC vs.
Revision 2518 by tim, Fri Dec 16 21:52:50 2005 UTC

# Line 13 | Line 13 | GNU General Public License for more details.
13   GNU General Public License for more details.
14   ***********************************************************************/
15  
16 < #include "mol.hpp"
17 < #include "obconversion.hpp"
18 < #include "obmolecformat.hpp"
16 > #include "xyzformat.hpp"
17  
20 #ifdef HAVE_SSTREAM
21 #include <sstream>
22 #else
23 #include <strstream>
24 #endif
18  
19   using namespace std;
20   namespace OpenBabel
21   {
22  
30 class XYZFormat : public OBMoleculeFormat
31 {
32 public:
33  //Register this format type ID
34  XYZFormat()
35  {
36    OBConversion::RegisterFormat("xyz", this, "chemical/x-xyz");
37  }
38
39  virtual const char* Description() //required
40  {
41    return
42      "XYZ cartesian coordinates format\n \
43       Read Options e.g. -as\n\
44        s  Output single bonds only\n\
45        b  Disable bonding entirely\n\n";
46  };
47
48  virtual const char* SpecificationURL()
49  {return "http://openbabel.sourceforge.net/formats/xyz.shtml";}; //optional
50
51  virtual const char* GetMIMEType()
52  { return "chemical/x-xyz"; };
53
54  //*** This section identical for most OBMol conversions ***
55  ////////////////////////////////////////////////////
56  /// The "API" interface functions
57  virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
58  virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
59 };
60 //***
61
62 //Make an instance of the format class
63 XYZFormat theXYZFormat;
64
65 /////////////////////////////////////////////////////////////////
23   bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
24   {
25      OBMol* pmol = dynamic_cast<OBMol*>(pOb);
# Line 85 | Line 42 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
42  
43      if (!ifs.getline(buffer,BUFF_SIZE))
44        {
45 <        obErrorLog.ThrowError(__FUNCTION__,
45 >        obErrorLog.ThrowError(__func__,
46                                "Problems reading an XYZ file: Cannot read the first line.", obWarning);
47          return(false);
48        }
49  
50      if (sscanf(buffer, "%d", &natoms) == 0 || !natoms)
51      {
52 <      obErrorLog.ThrowError(__FUNCTION__,
52 >      obErrorLog.ThrowError(__func__,
53                              "Problems reading an XYZ file: The first line must contain the number of atoms.", obWarning);
54        return(false);
55      }
# Line 104 | Line 61 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
61      // empty. Otherwise, use the title given by the calling function.
62      if (!ifs.getline(buffer,BUFF_SIZE))
63      {
64 <      obErrorLog.ThrowError(__FUNCTION__,
64 >      obErrorLog.ThrowError(__func__,
65                              "Problems reading an XYZ file: Could not read the second line (title/comments).", obWarning);
66          return(false);
67      }
# Line 127 | Line 84 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
84                     << " According to line one, there should be " << natoms
85                     << " atoms, and therefore " << natoms+2 << " lines in the file.";
86  
87 <          obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obWarning);
87 >          obErrorLog.ThrowError(__func__, errorMsg.str() , obWarning);
88            return(false);
89          }
90          tokenize(vs,buffer);
91 <        if (vs.size() != 4)
91 >        if (vs.size() < 4)
92          {
93            errorMsg << "Problems reading an XYZ file: "
94                     << "Could not read line #" << i+2 << "." << endl
# Line 139 | Line 96 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
96                     << "According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
97                     << "However, OpenBabel found " << vs.size() << " items.";
98  
99 <          obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obWarning);
99 >          obErrorLog.ThrowError(__func__, errorMsg.str() , obWarning);
100            return(false);
101          }
102  
# Line 167 | Line 124 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
124                     << "According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
125                     << "OpenBabel could not interpret item #1 as a number.";
126  
127 <          obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obWarning);
127 >          obErrorLog.ThrowError(__func__, errorMsg.str() , obWarning);
128            return(false);
129          }
130          double y = strtod((char*)vs[2].c_str(),&endptr);
# Line 179 | Line 136 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
136                     << "According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
137                     << "OpenBabel could not interpret item #2 as a number.";
138  
139 <          obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obWarning);
139 >          obErrorLog.ThrowError(__func__, errorMsg.str() , obWarning);
140            return(false);
141          }
142          double z = strtod((char*)vs[3].c_str(),&endptr);
# Line 191 | Line 148 | bool XYZFormat::ReadMolecule(OBBase* pOb, OBConversion
148                     << "According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
149                     << "OpenBabel could not interpret item #3 as a number.";
150  
151 <          obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obWarning);
151 >          obErrorLog.ThrowError(__func__, errorMsg.str() , obWarning);
152            return(false);
153          }
154          atom->SetVector(x,y,z); //set coordinates

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines