ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/openbabel/tinkerformat.cpp
(Generate patch)

Comparing trunk/src/openbabel/tinkerformat.cpp (file contents):
Revision 746 by tim, Wed Nov 16 21:22:51 2005 UTC vs.
Revision 1081 by gezelter, Thu Oct 19 20:49:05 2006 UTC

# Line 13 | Line 13 | GNU General Public License for more details.
13   GNU General Public License for more details.
14   ***********************************************************************/
15  
16 < #include "tinkerformat.hpp"
16 > #include "mol.hpp"
17 > #include "obconversion.hpp"
18  
19   using namespace std;
20   namespace OpenBabel
21   {
22  
23 + class TinkerFormat : public OBFormat
24 + {
25 + public:
26 +    //Register this format type ID
27 +    TinkerFormat()
28 +    {
29 +        OBConversion::RegisterFormat("txyz",this);
30 +    }
31 +
32 +    virtual const char* Description() //required
33 +    {
34 +        return
35 +            "Tinker MM2 format\n \
36 +            No comments yet\n";
37 +    };
38 +
39 +  virtual const char* SpecificationURL()
40 +  {return "http://dasher.wustl.edu/tinker/";}; //optional
41 +
42 +    //Flags() can return be any the following combined by | or be omitted if none apply
43 +    // NOTREADABLE  READONEONLY  NOTWRITABLE  WRITEONEONLY
44 +    virtual unsigned int Flags()
45 +    {
46 +        return NOTREADABLE | WRITEONEONLY;
47 +    };
48 +
49 +    //*** This section identical for most OBMol conversions ***
50 +    ////////////////////////////////////////////////////
51 +    /// The "API" interface functions
52 +    virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
53 +
54 +    ////////////////////////////////////////////////////
55 +    /// The "Convert" interface functions
56 +    virtual bool WriteChemObject(OBConversion* pConv)
57 +    {
58 +        //Retrieve the target OBMol
59 +        OBBase* pOb = pConv->GetChemObject();
60 +        OBMol* pmol = dynamic_cast<OBMol*> (pOb);
61 +        bool ret=false;
62 +        if(pmol)
63 +            ret=WriteMolecule(pmol,pConv);
64 +
65 +        std::string auditMsg = "OpenBabel::Write molecule ";
66 +        std::string description(Description());
67 +        auditMsg += description.substr( 0, description.find('\n') );
68 +        obErrorLog.ThrowError(__func__,
69 +                              auditMsg,
70 +                              obAuditMsg);
71 +
72 +        delete pOb;
73 +        return ret;
74 +    };
75 + };
76 + //***
77 +
78 + //Make an instance of the format class
79 + TinkerFormat theTinkerFormat;
80 +
81 + /////////////////////////////////////////////////////////////////
82 +
83   bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
84   {
85      OBMol* pmol = dynamic_cast<OBMol*>(pOb);
# Line 34 | Line 95 | bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConver
95      OBBond *bond;
96      vector<OBEdgeBase*>::iterator j;
97  
98 <    sprintf(buffer,"%6d %-20s   MM2 parameters",mol.NumAtoms(),mol.GetTitle());
99 <    ofs << buffer << endl;
98 >    snprintf(buffer, BUFF_SIZE, "%6d %-20s   MM2 parameters\n",mol.NumAtoms(),mol.GetTitle());
99 >    ofs << buffer;
100  
101      ttab.SetFromType("INT");
102  
# Line 47 | Line 108 | bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConver
108          str = atom->GetType();
109          ttab.SetToType("MM2");
110          ttab.Translate(str1,str);
111 <        sprintf(buffer,"%6d %2s  %12.6f%12.6f%12.6f %5d",
111 >        snprintf(buffer, BUFF_SIZE, "%6d %2s  %12.6f%12.6f%12.6f %5d",
112                  i,
113                  etab.GetSymbol(atom->GetAtomicNum()),
114                  atom->GetX(),
# Line 58 | Line 119 | bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConver
119  
120          for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j))
121          {
122 <            sprintf(buffer,"%6d", (bond->GetNbrAtom(atom))->GetIdx());
122 >            snprintf(buffer, BUFF_SIZE, "%6d", (bond->GetNbrAtom(atom))->GetIdx());
123              ofs << buffer;
124          }
125  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines