13
13
GNU General Public License for more details.
14
14
***********************************************************************/
17
#include "obconversion.h"
16
#include <openbabel/babelconfig.h>
17
#include <openbabel/obmolecformat.h>
19
19
using namespace std;
20
20
namespace OpenBabel
23
class CSSRFormat : public OBFormat
23
class CSSRFormat : public OBMoleculeFormat
26
26
//Register this format type ID
29
OBConversion::RegisterFormat("cssr",this);
29
OBConversion::RegisterFormat("cssr",this);
32
32
virtual const char* Description() //required
36
36
No comments yet\n";
39
virtual const char* SpecificationURL()
40
{return "";}; //optional
39
virtual const char* SpecificationURL()
40
{return "";}; //optional
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()
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);
54
////////////////////////////////////////////////////
55
/// The "Convert" interface functions
57
virtual bool WriteChemObject(OBConversion* pConv)
59
//Retrieve the target OBMol
60
OBBase* pOb = pConv->GetChemObject();
61
OBMol* pmol = dynamic_cast<OBMol*> (pOb);
64
ret=WriteMolecule(pmol,pConv);
67
std::string auditMsg = "OpenBabel::Write molecule ";
68
std::string description(Description());
69
auditMsg += description.substr( 0, description.find('\n') );
70
obErrorLog.ThrowError(__FUNCTION__,
79
//Make an instance of the format class
80
CSSRFormat theCSSRFormat;
82
////////////////////////////////////////////////////////////////
84
bool CSSRFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
55
//Make an instance of the format class
56
CSSRFormat theCSSRFormat;
58
////////////////////////////////////////////////////////////////
60
bool CSSRFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
86
62
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
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))
98
74
snprintf(buffer, BUFF_SIZE,
99
" REFERENCE STRUCTURE = 00000 A,B,C =%8.3f%8.3f%8.3f",
101
ofs << buffer << endl;
75
" REFERENCE STRUCTURE = 00000 A,B,C =%8.3f%8.3f%8.3f",
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;
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;
120
96
snprintf(buffer, BUFF_SIZE, "%4d 1 %s\n",mol.NumAtoms(), mol.GetTitle());
121
97
ofs << buffer << endl << endl;
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);
129
105
for(atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
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 ",
135
etab.GetSymbol(atom->GetAtomicNum()),
136
vtmp[atom->GetAtomicNum()],
111
etab.GetSymbol(atom->GetAtomicNum()),
112
vtmp[atom->GetAtomicNum()],
142
118
for (nbr = atom->BeginNbrAtom(j); nbr; nbr = atom->NextNbrAtom(j))
144
if (bonds > 8) break;
145
sprintf(buffer,"%4d",nbr->GetIdx());
149
for (; bonds < 8; bonds ++)
151
sprintf(buffer,"%4d",0);
154
sprintf(buffer," %7.3f%4d", atom->GetPartialCharge(), 1);
155
ofs << buffer << endl;
120
if (bonds > 8) break;
121
sprintf(buffer,"%4d",nbr->GetIdx());
125
for (; bonds < 8; bonds ++)
127
sprintf(buffer,"%4d",0);
130
sprintf(buffer," %7.3f%4d", atom->GetPartialCharge(), 1);
131
ofs << buffer << endl;
161
137
} //namespace OpenBabel