ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/openbabel/oopseformat.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/openbabel/oopseformat.cpp (file contents):
Revision 2445 by tim, Wed Nov 16 21:22:51 2005 UTC vs.
Revision 2455 by tim, Fri Nov 18 16:38:34 2005 UTC

# Line 14 | Line 14 | namespace OpenBabel
14   ***********************************************************************/
15  
16   #include "oopseformat.hpp"
17 + #include <fstream>
18   namespace OpenBabel
19   {
20  
# Line 65 | Line 66 | bool OOPSEFormat::WriteMolecule(OBBase* pOb, OBConvers
66          numMols.push_back((*i).size());
67      }
68  
69 <    WriteMDFile(mdMols, numMols);    
69 >    string OutputFileName = pConv->GetInFilename();
70 >    unsigned int pos = OutputFileName.rfind(".");
71 >    if(pos==string::npos)
72 >        OutputFileName += ".md";
73 >    else
74 >        OutputFileName = OutputFileName.substr(0, pos) + ".md";      
75 >    ofstream ofs(OutputFileName.c_str());
76 >    if(!ofs)
77 >    {
78 >         cerr << "Cannot write to " << OutputFileName <<endl;
79 >         return false;
80 >    }
81 >                
82 >    WriteMDFile(mdMols, numMols, ofs);    
83  
84      for(vector<OBMol*>::iterator  i = mdMols.begin(); i != mdMols.end(); ++i)
85      {
# Line 163 | Line 177 | void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vec
177      newMol->FindTorsions();
178      return newMol;
179   }
180 < void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vector<int> numMols)
180 > void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vector<int> numMols, ostream& os)
181   {
182      std::string identLevel1("\t");
183      std::string identLevel2("\t\t");
184      std::string molPrefix("MolName");
171    ostream& ofs = std::cout;
185      const int BUFFLEN = 1024;
186      char buffer[BUFFLEN];
187      
# Line 176 | Line 189 | void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vec
189      {
190          OBMol* pmol = mols[i];
191          map<OBAtom*, int> atomMap;
192 <        ofs << "molecule {\n";
192 >        os << "molecule {\n";
193          sprintf(buffer, "%d", i);
194 <        ofs << identLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n";
194 >        os << identLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n";
195  
196          
197          //atom
185        ofs << identLevel1 << "nAtoms = " << pmol->NumAtoms() << ";\n";
198          int ai = 0;
199          FOR_ATOMS_OF_MOL(atom, *pmol ) {
200 <            ofs << identLevel1 << "atom[" << ai << "] {\n";
201 <            ofs << identLevel2 << "type = " << "\"" << atom->GetType() << "\"" << ";\n";
202 <            ofs << identLevel2 << "position(" << atom->GetX() << ", " << atom->GetY() << ", " << atom->GetZ() << ");\n";
191 <            ofs << identLevel1 << "}\n";
200 >            os << identLevel1 << "atom[" << ai << "] {\n";
201 >            os << identLevel2 << "type = " << "\"" << atom->GetType() << "\"" << ";\n";
202 >            os << identLevel1 << "}\n";
203              atomMap[&(*atom)] = ai++;
204          }        
205  
206          //bond
196        ofs << identLevel1 << "nBonds = " << pmol->NumBonds() << ";\n";
197        int bi = 0;
207          FOR_BONDS_OF_MOL(bond, *pmol ) {
208 <            ofs << identLevel1 << "bond[" << bi++ << "] {\n";
209 <            ofs << identLevel2 << "member(" << atomMap[bond->GetBeginAtom()] <<  ", " << atomMap[bond->GetEndAtom()] << ");\n";
210 <            ofs << identLevel1 << "}\n";
208 >            os << identLevel1 << "bond {\n";
209 >            os << identLevel2 << "members(" << atomMap[bond->GetBeginAtom()] <<  ", " << atomMap[bond->GetEndAtom()] << ");\n";
210 >            os << identLevel1 << "}\n";
211          }  
212          /*
213          //bend
# Line 206 | Line 215 | void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vec
215          OBAngleData* pAngleData = dynamic_cast<OBAngleData*>(pGenericData);
216          vector<OBAngle> angles = pAngleData->GetData();
217  
218 <        ofs << identLevel1 << "nBends = " << angles.size() << ";\n";        
218 >        os << identLevel1 << "nBends = " << angles.size() << ";\n";        
219          int bendIndex = 0;
220          for (vector<OBAngle>::iterator ti = angles.begin(); ti != angles.end(); ++ti)
221          {
222              triple<OBAtom*, OBAtom*, OBAtom*> bendAtoms = ti->getAtoms();
223 <            ofs << identLevel1 << "bend[" << bendIndex++ << "] {\n";
224 <            ofs << identLevel2 << "member(" << atomMap[bendAtoms.first] <<  ", " << atomMap[bendAtoms.second] << atomMap[bendAtoms.third] <<");\n";
225 <            ofs << identLevel1 << "}\n";            
223 >            os << identLevel1 << "bend[" << bendIndex++ << "] {\n";
224 >            os << identLevel2 << "member(" << atomMap[bendAtoms.first] <<  ", " << atomMap[bendAtoms.second] << atomMap[bendAtoms.third] <<");\n";
225 >            os << identLevel1 << "}\n";            
226          }
227          
228          //torsion
# Line 227 | Line 236 | void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vec
236              torsionArray.insert(torsionArray.end(), tmpTorsions.begin(), tmpTorsions.end());            
237          }
238  
239 <        ofs << identLevel1 << "nTorsions = " << torsionArray.size() << ";\n";
239 >        os << identLevel1 << "nTorsions = " << torsionArray.size() << ";\n";
240          int torsionIndex = 0;
241          for (vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> >::iterator ti = torsionArray.begin(); ti != torsionArray.end(); ++ti)
242          {
243 <            ofs << identLevel1 << "torsion[" << torsionIndex++ << "] {\n";
244 <            ofs << identLevel2 << "member(" << atomMap[ti->first] <<  ", " << atomMap[ti->second] <<", " << atomMap[ti->third] <<", " << atomMap[ti->forth] << ");\n";
245 <            ofs << identLevel1 << "}\n";          
243 >            os << identLevel1 << "torsion[" << torsionIndex++ << "] {\n";
244 >            os << identLevel2 << "member(" << atomMap[ti->first] <<  ", " << atomMap[ti->second] <<", " << atomMap[ti->third] <<", " << atomMap[ti->forth] << ");\n";
245 >            os << identLevel1 << "}\n";          
246          }
247          */
248 <        ofs << "}\n";
248 >        os << "}\n";
249      }
250  
251 <    ofs << "nComponents = " << mols.size() << ";\n";
251 >    os << "nComponents = " << mols.size() << ";\n";
252      
253      for(unsigned int i =0; i < mols.size(); ++i)
254      {
255 <        ofs << "component{\n";
255 >        os << "component{\n";
256          sprintf(buffer, "%d", i);
257 <        ofs << "type = " << molPrefix << buffer << ";\n";
258 <        ofs << "nMol = " << numMols[i]<< ";\n";
259 <        ofs << "}\n";
257 >        os << "type = " << molPrefix << buffer << ";\n";
258 >        os << "nMol = " << numMols[i]<< ";\n";
259 >        os << "}\n";
260      }
261   }
262   void OOPSEFormat::WriteINFile(OBMol& mol, ostream& ofs, vector<int>& indices)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines