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

« back to all changes in this revision

Viewing changes to src/formats/mmodformat.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:
12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
13
GNU General Public License for more details.
14
14
***********************************************************************/
 
15
#include <openbabel/babelconfig.h>
15
16
 
16
 
#include "mol.h"
17
 
#include "obconversion.h"
18
 
#include "obmolecformat.h"
 
17
#include <openbabel/obmolecformat.h>
19
18
 
20
19
using namespace std;
21
20
namespace OpenBabel
22
21
{
23
22
 
24
 
class MacroModFormat : public OBMoleculeFormat
25
 
{
26
 
public:
 
23
  class MacroModFormat : public OBMoleculeFormat
 
24
  {
 
25
  public:
27
26
    //Register this format type ID
28
27
    MacroModFormat()
29
28
    {
30
 
        OBConversion::RegisterFormat("mmd",this, "chemical/x-macromodel-input");
31
 
        OBConversion::RegisterFormat("mmod",this, "chemical/x-macromodel-input");
 
29
      OBConversion::RegisterFormat("mmd",this, "chemical/x-macromodel-input");
 
30
      OBConversion::RegisterFormat("mmod",this, "chemical/x-macromodel-input");
32
31
    }
33
32
 
34
33
    virtual const char* Description() //required
35
34
    {
36
 
        return
37
 
            "MacroModel format\n \
 
35
      return
 
36
        "MacroModel format\n \
38
37
            No comments yet\n";
39
38
    };
40
39
 
41
 
  virtual const char* SpecificationURL()
42
 
  {return "";}; //optional
 
40
    virtual const char* SpecificationURL()
 
41
    {return "";}; //optional
43
42
 
44
 
  virtual const char* GetMIMEType() 
45
 
  { return "chemical/x-macromodel-input"; };
 
43
    virtual const char* GetMIMEType() 
 
44
    { return "chemical/x-macromodel-input"; };
46
45
 
47
46
    //Flags() can return be any the following combined by | or be omitted if none apply
48
47
    // NOTREADABLE  READONEONLY  NOTWRITABLE  WRITEONEONLY
49
48
    virtual unsigned int Flags()
50
49
    {
51
 
        return READONEONLY;
 
50
      return READONEONLY;
52
51
    };
53
52
 
54
53
    //*** This section identical for most OBMol conversions ***
56
55
    /// The "API" interface functions
57
56
    virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
58
57
    virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
59
 
};
60
 
//***
61
 
 
62
 
//Make an instance of the format class
63
 
MacroModFormat theMacroModFormat;
64
 
 
65
 
/////////////////////////////////////////////////////////////////
66
 
bool MacroModFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
67
 
{
68
 
 
69
 
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
 
58
  };
 
59
  //***
 
60
 
 
61
  //Make an instance of the format class
 
62
  MacroModFormat theMacroModFormat;
 
63
 
 
64
  /////////////////////////////////////////////////////////////////
 
65
  bool MacroModFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
 
66
  {
 
67
 
 
68
    OBMol* pmol = pOb->CastAndClear<OBMol>();
70
69
    if(pmol==NULL)
71
 
        return false;
 
70
      return false;
72
71
 
73
72
    //Define some references so we can use the old parameter names
74
73
    istream &ifs = *pConv->GetInStream();
81
80
    vector<vector<pair<int,int> > > connections;
82
81
 
83
82
    if (ifs.getline(buffer,BUFF_SIZE))
84
 
    {
 
83
      {
85
84
        vector<string> vs;
86
85
        tokenize(vs,buffer," \n");
87
86
 
88
87
        if ( !vs.empty() && vs.size() > 0)
89
 
            sscanf(buffer,"%i%*s",&natoms);
 
88
          sscanf(buffer,"%i%*s",&natoms);
90
89
 
91
 
        if (natoms == 0)
92
 
          return false;
 
90
        if (natoms == 0)
 
91
          return false;
93
92
 
94
93
        if ( !vs.empty() && vs.size() > 1)
95
 
            mol.SetTitle(vs[1]);
 
94
          mol.SetTitle(vs[1]);
96
95
        else
97
 
        {
 
96
          {
98
97
            string s = defaultTitle;
99
98
            mol.SetTitle(defaultTitle);
100
 
        }
101
 
    }
 
99
          }
 
100
      }
102
101
    else
103
 
        return(false);
 
102
      return(false);
104
103
 
105
104
    mol.BeginModify();
106
105
    mol.ReserveAtoms(natoms);
119
118
 
120
119
    ttab.SetFromType("MMD");
121
120
    for (i = 1; i <= natoms; i++)
122
 
    {
 
121
      {
123
122
        if (!ifs.getline(buffer,BUFF_SIZE))
124
 
            break;
 
123
          break;
125
124
 
126
125
        int end[6], order[6];
127
126
 
132
131
 
133
132
        pair<int,int> tmp;
134
133
        for ( j = 0 ; j <=5 ; j++ )
135
 
        {
 
134
          {
136
135
            if ( end[j] > 0  && end[j] > i)
137
 
            {
 
136
              {
138
137
                tmp.first = end[j];
139
138
                tmp.second = order[j];
140
139
                connections[i].push_back(tmp);
141
 
            }
142
 
        }
 
140
              }
 
141
          }
143
142
 
144
143
        v.SetX(x);
145
144
        v.SetY(y);
160
159
        sscanf(&buffer[101],"%lf", &charge);
161
160
        atom.SetPartialCharge(charge);
162
161
        mol.AddAtom(atom);
163
 
    }
 
162
      }
164
163
 
165
164
    for (i = 1; i <= natoms; i++)
166
 
        for (j = 0; j < (signed)connections[i].size(); j++)
167
 
            mol.AddBond(i, connections[i][j].first, connections[i][j].second);
 
165
      for (j = 0; j < (signed)connections[i].size(); j++)
 
166
        mol.AddBond(i, connections[i][j].first, connections[i][j].second);
168
167
 
169
168
    mol.EndModify();
170
169
 
171
170
    OBBond *bond;
172
 
    vector<OBEdgeBase*>::iterator bi;
 
171
    vector<OBBond*>::iterator bi;
173
172
    for (bond = mol.BeginBond(bi);bond;bond = mol.NextBond(bi))
174
 
        if (bond->GetBO() == 5 && !bond->IsInRing())
175
 
            bond->SetBO(1);
 
173
      if (bond->GetBO() == 5 && !bond->IsInRing())
 
174
        bond->SetBO(1);
176
175
 
177
176
    if ( natoms != (signed)mol.NumAtoms() )
178
 
        return(false);
 
177
      return(false);
179
178
 
180
179
    // clean out remaining blank lines
181
180
    while(ifs.peek() != EOF && ifs.good() && 
182
 
          (ifs.peek() == '\n' || ifs.peek() == '\r'))
 
181
          (ifs.peek() == '\n' || ifs.peek() == '\r'))
183
182
      ifs.getline(buffer,BUFF_SIZE);
184
183
 
185
184
    return(true);
186
 
}
187
 
 
188
 
////////////////////////////////////////////////////////////////
189
 
 
190
 
bool MacroModFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
191
 
{
 
185
  }
 
186
 
 
187
  ////////////////////////////////////////////////////////////////
 
188
 
 
189
  bool MacroModFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
 
190
  {
192
191
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
193
192
    if(pmol==NULL)
194
 
        return false;
 
193
      return false;
195
194
 
196
195
    //Define some references so we can use the old parameter names
197
196
    ostream &ofs = *pConv->GetOutStream();
205
204
    int type,k;
206
205
    OBAtom *atom,*nbr;
207
206
    string from,to;
208
 
    vector<OBNodeBase*>::iterator i;
209
 
    vector<OBEdgeBase*>::iterator j;
 
207
    vector<OBAtom*>::iterator i;
 
208
    vector<OBBond*>::iterator j;
210
209
    ttab.SetFromType("INT");
211
210
    ttab.SetToType("MMD");
212
211
 
213
212
    for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
214
 
    {
 
213
      {
215
214
        if (atom->IsHydrogen())
216
 
        {
 
215
          {
217
216
            type = 41;
218
217
            if ((nbr = atom->BeginNbrAtom(j)))
219
 
                if (nbr->IsOxygen())
220
 
                    type = 42;
221
 
                else if (nbr->IsNitrogen())
222
 
                    type = 43;
223
 
        }
 
218
              if (nbr->IsOxygen())
 
219
                type = 42;
 
220
              else if (nbr->IsNitrogen())
 
221
                type = 43;
 
222
          }
224
223
        else
225
 
        {
 
224
          {
226
225
            from = atom->GetType();
227
226
            ttab.Translate(to,from);
228
227
            type = atoi((char*)to.c_str());
229
 
        }
 
228
          }
230
229
        snprintf(buffer, BUFF_SIZE, "%4d",type);
231
230
        ofs << buffer;
232
231
        for (nbr = atom->BeginNbrAtom(j);nbr;nbr = atom->NextNbrAtom(j))
233
 
        {
 
232
          {
234
233
            snprintf(buffer, BUFF_SIZE, " %5d %1d",nbr->GetIdx(),(*j)->GetBO());
235
234
            ofs << buffer;
236
 
        }
 
235
          }
237
236
        for (k=atom->GetValence();k < 6;k++)
238
 
        {
 
237
          {
239
238
            snprintf(buffer, BUFF_SIZE," %5d %1d",0,0);
240
239
            ofs << buffer;
241
 
        }
 
240
          }
242
241
 
243
242
        snprintf(buffer, BUFF_SIZE, " %11.6f %11.6f %11.6f %5d %5d %8.5f \n",
244
243
                atom->x(), atom->y(),atom->z(),0,0,
245
244
                atom->GetPartialCharge());
246
245
        ofs << buffer;
247
 
    }
 
246
      }
248
247
 
249
248
    return(true);
250
 
}
 
249
  }
251
250
 
252
251
} //namespace OpenBabel