~ubuntu-branches/debian/stretch/openbabel/stretch

« back to all changes in this revision

Viewing changes to src/formats/nwchemformat.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2008-07-22 23:54:58 UTC
  • mfrom: (3.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080722235458-3o606czluviz4akx
Tags: 2.2.0-2
* Upload to unstable.
* debian/control: Updated descriptions.
* debian/patches/gauss_cube_format.patch: New patch, makes the 
  gaussian cube format available again.
* debian/rules (DEB_DH_MAKESHLIBS_ARGS_libopenbabel3): Removed.
* debian/rules (DEB_CONFIGURE_EXTRA_FLAGS): Likewise.
* debian/libopenbabel3.install: Adjust formats directory to single 
  version hierarchy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
GNU General Public License for more details.
13
13
***********************************************************************/
 
14
#include <openbabel/babelconfig.h>
14
15
 
15
 
#include "mol.h"
16
 
#include "obconversion.h"
17
 
#include "obmolecformat.h"
 
16
#include <openbabel/obmolecformat.h>
18
17
 
19
18
using namespace std;
20
19
namespace OpenBabel
21
20
{
22
21
 
23
 
class NWChemOutputFormat : public OBMoleculeFormat
24
 
{
25
 
public:
 
22
  class NWChemOutputFormat : public OBMoleculeFormat
 
23
  {
 
24
  public:
26
25
    //Register this format type ID
27
26
    NWChemOutputFormat()
28
27
    {
29
 
        OBConversion::RegisterFormat("nwo",this);
 
28
      OBConversion::RegisterFormat("nwo",this);
30
29
    }
31
30
 
32
 
  virtual const char* Description() //required
33
 
  {
34
 
    return
35
 
      "NWChem output format\n \
 
31
    virtual const char* Description() //required
 
32
    {
 
33
      return
 
34
        "NWChem output format\n \
36
35
       Read Options e.g. -as\n\
37
36
        s  Output single bonds only\n\
38
37
        b  Disable bonding entirely\n\n";
39
 
  };
 
38
    };
40
39
 
41
 
  virtual const char* SpecificationURL()
42
 
  {return "http://www.emsl.pnl.gov/docs/nwchem/";}; //optional
 
40
    virtual const char* SpecificationURL()
 
41
    {return "http://www.emsl.pnl.gov/docs/nwchem/";}; //optional
43
42
 
44
43
    //Flags() can return be any the following combined by | or be omitted if none apply
45
44
    // NOTREADABLE  READONEONLY  NOTWRITABLE  WRITEONEONLY
46
45
    virtual unsigned int Flags()
47
46
    {
48
 
        return READONEONLY | NOTWRITABLE;
 
47
      return READONEONLY | NOTWRITABLE;
49
48
    };
50
49
 
51
50
    ////////////////////////////////////////////////////
52
51
    /// The "API" interface functions
53
52
    virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
54
 
};
55
 
 
56
 
//Make an instance of the format class
57
 
NWChemOutputFormat theNWChemOutputFormat;
58
 
 
59
 
class NWChemInputFormat : public OBFormat
60
 
{
61
 
public:
 
53
  };
 
54
 
 
55
  //Make an instance of the format class
 
56
  NWChemOutputFormat theNWChemOutputFormat;
 
57
 
 
58
  class NWChemInputFormat : public OBMoleculeFormat
 
59
  {
 
60
  public:
62
61
    //Register this format type ID
63
62
    NWChemInputFormat()
64
63
    {
65
 
        OBConversion::RegisterFormat("nw",this);
 
64
      OBConversion::RegisterFormat("nw",this);
66
65
    }
67
66
 
68
67
    virtual const char* Description() //required
69
68
    {
70
 
        return
71
 
            "NWChem input format\n \
 
69
      return
 
70
        "NWChem input format\n \
72
71
            No comments yet\n";
73
72
    };
74
73
 
75
 
  virtual const char* SpecificationURL()
76
 
  {return "http://www.emsl.pnl.gov/docs/nwchem/";}; //optional
 
74
    virtual const char* SpecificationURL()
 
75
    {return "http://www.emsl.pnl.gov/docs/nwchem/";}; //optional
77
76
 
78
77
    //Flags() can return be any the following combined by | or be omitted if none apply
79
78
    // NOTREADABLE  READONEONLY  NOTWRITABLE  WRITEONEONLY
86
85
    /// The "API" interface functions
87
86
    virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
88
87
 
89
 
    ////////////////////////////////////////////////////
90
 
    /// The "Convert" interface functions
91
 
    virtual bool WriteChemObject(OBConversion* pConv)
92
 
    {
93
 
        //Retrieve the target OBMol
94
 
        OBBase* pOb = pConv->GetChemObject();
95
 
        OBMol* pmol = dynamic_cast<OBMol*> (pOb);
96
 
        bool ret=false;
97
 
        if(pmol)
98
 
            ret=WriteMolecule(pmol,pConv);
99
 
        delete pOb;
100
 
        return ret;
101
 
    };
102
 
};
103
 
 
104
 
//Make an instance of the format class
105
 
NWChemInputFormat theNWChemInputFormat;
106
 
 
107
 
 
108
 
/////////////////////////////////////////////////////////////////
109
 
bool NWChemOutputFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
110
 
{
111
 
 
112
 
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
 
88
  };
 
89
 
 
90
  //Make an instance of the format class
 
91
  NWChemInputFormat theNWChemInputFormat;
 
92
 
 
93
 
 
94
  /////////////////////////////////////////////////////////////////
 
95
  bool NWChemOutputFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
 
96
  {
 
97
 
 
98
    OBMol* pmol = pOb->CastAndClear<OBMol>();
113
99
    if(pmol==NULL)
114
 
        return false;
 
100
      return false;
115
101
 
116
102
    //Define some references so we can use the old parameter names
117
103
    istream &ifs = *pConv->GetInStream();
126
112
 
127
113
    mol.BeginModify();
128
114
    while       (ifs.getline(buffer,BUFF_SIZE))
129
 
    {
 
115
      {
130
116
        if(strstr(buffer,"Output coordinates") != NULL)
131
 
        {
 
117
          {
132
118
            // mol.EndModify();
133
119
            mol.Clear();
134
120
            mol.BeginModify();
138
124
            ifs.getline(buffer,BUFF_SIZE);
139
125
            tokenize(vs,buffer);
140
126
            while (vs.size() == 6)
141
 
            {
 
127
              {
142
128
                atom = mol.NewAtom();
143
129
                x = atof((char*)vs[3].c_str());
144
130
                y = atof((char*)vs[4].c_str());
149
135
                atom->SetAtomicNum(etab.GetAtomicNum(vs[1].c_str()));
150
136
 
151
137
                if (!ifs.getline(buffer,BUFF_SIZE))
152
 
                    break;
 
138
                  break;
153
139
                tokenize(vs,buffer);
154
 
            }
155
 
        } // if "output coordinates"
156
 
    } // while
 
140
              }
 
141
          } // if "output coordinates"
 
142
      } // while
 
143
 
 
144
    if (mol.NumAtoms() == 0) { // e.g., if we're at the end of a file PR#1737209
 
145
      mol.EndModify();
 
146
      return false;
 
147
    }
157
148
 
158
149
    if (!pConv->IsOption("b",OBConversion::INOPTIONS))
159
150
      mol.ConnectTheDots();
163
154
    mol.EndModify();
164
155
    mol.SetTitle(title);
165
156
    return(true);
166
 
}
167
 
 
168
 
////////////////////////////////////////////////////////////////
169
 
 
170
 
bool NWChemInputFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
171
 
{
 
157
  }
 
158
 
 
159
  ////////////////////////////////////////////////////////////////
 
160
 
 
161
  bool NWChemInputFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
 
162
  {
172
163
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
173
164
    if(pmol==NULL)
174
 
        return false;
 
165
      return false;
175
166
 
176
167
    //Define some references so we can use the old parameter names
177
168
    ostream &ofs = *pConv->GetOutStream();
185
176
    ofs << "geometry units angstroms print xyz autosym\n";
186
177
 
187
178
    FOR_ATOMS_OF_MOL(atom, mol)
188
 
    {
 
179
      {
189
180
        snprintf(buffer, BUFF_SIZE, "%3s%15.5f%15.5f%15.5f\n",
190
181
                etab.GetSymbol(atom->GetAtomicNum()),
191
182
                atom->GetX(),
192
183
                atom->GetY(),
193
184
                atom->GetZ());
194
185
        ofs << buffer;
195
 
    }
 
186
      }
196
187
 
197
188
    ofs << "end\n";
198
189
 
199
190
    return(true);
200
 
}
 
191
  }
201
192
 
202
193
} //namespace OpenBabel