~ubuntu-branches/ubuntu/hardy/openbabel/hardy

« back to all changes in this revision

Viewing changes to src/formats/cssrformat.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-08-06 17:28:40 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070806172840-22hoqb3ve230qav1
Tags: 2.1.1-0ubuntu1
* New upstream release
* New so version 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
GNU General Public License for more details.
14
14
***********************************************************************/
15
15
 
16
 
#include "mol.h"
17
 
#include "obconversion.h"
 
16
#include <openbabel/babelconfig.h>
 
17
#include <openbabel/obmolecformat.h>
18
18
 
19
19
using namespace std;
20
20
namespace OpenBabel
21
21
{
22
22
 
23
 
class CSSRFormat : public OBFormat
24
 
{
25
 
public:
 
23
  class CSSRFormat : public OBMoleculeFormat
 
24
  {
 
25
  public:
26
26
    //Register this format type ID
27
27
    CSSRFormat()
28
28
    {
29
 
        OBConversion::RegisterFormat("cssr",this);
 
29
      OBConversion::RegisterFormat("cssr",this);
30
30
    }
31
31
 
32
32
    virtual const char* Description() //required
33
33
    {
34
 
        return
35
 
            "CSD CSSR format\n \
 
34
      return
 
35
        "CSD CSSR format\n \
36
36
            No comments yet\n";
37
37
    };
38
38
 
39
 
  virtual const char* SpecificationURL()
40
 
  {return "";}; //optional
 
39
    virtual const char* SpecificationURL()
 
40
    {return "";}; //optional
41
41
 
42
42
    //Flags() can return be any the following combined by | or be omitted if none apply
43
43
    // NOTREADABLE  READONEONLY  NOTWRITABLE  WRITEONEONLY
44
44
    virtual unsigned int Flags()
45
45
    {
46
 
        return NOTREADABLE;
 
46
      return NOTREADABLE;
47
47
    };
48
48
 
49
 
    //*** This section identical for most OBMol conversions ***
50
49
    ////////////////////////////////////////////////////
51
50
    /// The "API" interface functions
52
51
    virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
53
52
 
54
 
    ////////////////////////////////////////////////////
55
 
    /// The "Convert" interface functions
56
 
 
57
 
    virtual bool WriteChemObject(OBConversion* pConv)
58
 
    {
59
 
        //Retrieve the target OBMol
60
 
        OBBase* pOb = pConv->GetChemObject();
61
 
        OBMol* pmol = dynamic_cast<OBMol*> (pOb);
62
 
        bool ret=false;
63
 
        if(pmol)
64
 
            ret=WriteMolecule(pmol,pConv);
65
 
        delete pOb;
66
 
 
67
 
        std::string auditMsg = "OpenBabel::Write molecule ";
68
 
        std::string description(Description());
69
 
        auditMsg += description.substr( 0, description.find('\n') );
70
 
        obErrorLog.ThrowError(__FUNCTION__,
71
 
                              auditMsg,
72
 
                              obAuditMsg);
73
 
 
74
 
        return ret;
75
 
    };
76
 
};
77
 
//***
78
 
 
79
 
//Make an instance of the format class
80
 
CSSRFormat theCSSRFormat;
81
 
 
82
 
////////////////////////////////////////////////////////////////
83
 
 
84
 
bool CSSRFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
85
 
{
 
53
  };
 
54
 
 
55
  //Make an instance of the format class
 
56
  CSSRFormat theCSSRFormat;
 
57
 
 
58
  ////////////////////////////////////////////////////////////////
 
59
 
 
60
  bool CSSRFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
 
61
  {
86
62
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
87
63
    if(pmol==NULL)
88
 
        return false;
 
64
      return false;
89
65
 
90
66
    //Define some references so we can use the old parameter names
91
67
    ostream &ofs = *pConv->GetOutStream();
96
72
    if (!mol.HasData(OBGenericDataType::UnitCell))
97
73
      {
98
74
        snprintf(buffer, BUFF_SIZE,
99
 
                " REFERENCE STRUCTURE = 00000   A,B,C =%8.3f%8.3f%8.3f",
100
 
                1.0,1.0,1.0);
101
 
        ofs << buffer << endl;
 
75
                 " REFERENCE STRUCTURE = 00000   A,B,C =%8.3f%8.3f%8.3f",
 
76
                 1.0,1.0,1.0);
 
77
        ofs << buffer << endl;
102
78
        snprintf(buffer, BUFF_SIZE,
103
 
                "   ALPHA,BETA,GAMMA =%8.3f%8.3f%8.3f    SPGR =    P1"
104
 
                , 90.0f, 90.0f, 90.0f);
105
 
        ofs << buffer << endl;
 
79
                 "   ALPHA,BETA,GAMMA =%8.3f%8.3f%8.3f    SPGR =    P1"
 
80
                 , 90.0f, 90.0f, 90.0f);
 
81
        ofs << buffer << endl;
106
82
      }
107
83
    else
108
84
      {
109
 
        OBUnitCell *uc = (OBUnitCell*)mol.GetData(OBGenericDataType::UnitCell);
110
 
        snprintf(buffer, BUFF_SIZE, 
111
 
                " REFERENCE STRUCTURE = 00000   A,B,C =%8.3f%8.3f%8.3f",
112
 
                uc->GetA(), uc->GetB(), uc->GetC()); 
113
 
        ofs << buffer << endl;
114
 
        snprintf(buffer, BUFF_SIZE, 
115
 
                "   ALPHA,BETA,GAMMA =%8.3f%8.3f%8.3f    SPGR =    P1",
116
 
                uc->GetAlpha() , uc->GetBeta(), uc->GetGamma());
117
 
        ofs << buffer << endl;
 
85
        OBUnitCell *uc = (OBUnitCell*)mol.GetData(OBGenericDataType::UnitCell);
 
86
        snprintf(buffer, BUFF_SIZE, 
 
87
                 " REFERENCE STRUCTURE = 00000   A,B,C =%8.3f%8.3f%8.3f",
 
88
                 uc->GetA(), uc->GetB(), uc->GetC()); 
 
89
        ofs << buffer << endl;
 
90
        snprintf(buffer, BUFF_SIZE, 
 
91
                 "   ALPHA,BETA,GAMMA =%8.3f%8.3f%8.3f    SPGR =    P1",
 
92
                 uc->GetAlpha() , uc->GetBeta(), uc->GetGamma());
 
93
        ofs << buffer << endl;
118
94
      }
119
95
 
120
96
    snprintf(buffer, BUFF_SIZE, "%4d   1 %s\n",mol.NumAtoms(), mol.GetTitle());
121
97
    ofs << buffer << endl << endl;
122
98
 
123
99
    OBAtom *atom,*nbr;
124
 
    vector<OBNodeBase*>::iterator i;
125
 
    vector<OBEdgeBase*>::iterator j;
 
100
    vector<OBAtom*>::iterator i;
 
101
    vector<OBBond*>::iterator j;
126
102
    vector<int> vtmp(106,0);
127
103
    int bonds;
128
104
 
129
105
    for(atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
130
 
    {
 
106
      {
131
107
        //assign_pdb_number(pdb_types,atom->GetIdx());
132
108
        vtmp[atom->GetAtomicNum()]++;
133
109
        snprintf(buffer, BUFF_SIZE, "%4d%2s%-3d  %9.5f %9.5f %9.5f ",
134
 
                atom->GetIdx(),
135
 
                etab.GetSymbol(atom->GetAtomicNum()),
136
 
                vtmp[atom->GetAtomicNum()],
137
 
                atom->x(),
138
 
                atom->y(),
139
 
                atom->z());
 
110
                 atom->GetIdx(),
 
111
                 etab.GetSymbol(atom->GetAtomicNum()),
 
112
                 vtmp[atom->GetAtomicNum()],
 
113
                 atom->x(),
 
114
                 atom->y(),
 
115
                 atom->z());
140
116
        ofs << buffer;
141
 
        bonds = 0;
 
117
        bonds = 0;
142
118
        for (nbr = atom->BeginNbrAtom(j); nbr; nbr = atom->NextNbrAtom(j))
143
 
        {
144
 
          if (bonds > 8) break;
145
 
          sprintf(buffer,"%4d",nbr->GetIdx());
146
 
          ofs << buffer;
147
 
          bonds++;
148
 
        }
149
 
        for (; bonds < 8; bonds ++)
150
 
          {
151
 
            sprintf(buffer,"%4d",0);
152
 
            ofs << buffer;
153
 
          }
154
 
        sprintf(buffer," %7.3f%4d", atom->GetPartialCharge(), 1);
155
 
        ofs << buffer << endl;
156
 
    }
 
119
          {
 
120
            if (bonds > 8) break;
 
121
            sprintf(buffer,"%4d",nbr->GetIdx());
 
122
            ofs << buffer;
 
123
            bonds++;
 
124
          }
 
125
        for (; bonds < 8; bonds ++)
 
126
          {
 
127
            sprintf(buffer,"%4d",0);
 
128
            ofs << buffer;
 
129
          }
 
130
        sprintf(buffer," %7.3f%4d", atom->GetPartialCharge(), 1);
 
131
        ofs << buffer << endl;
 
132
      }
157
133
 
158
134
    return(true);
159
 
}
 
135
  }
160
136
 
161
137
} //namespace OpenBabel