| 1 | 
tim | 
741 | 
/********************************************************************** | 
| 2 | 
  | 
  | 
Copyright (C) 2000 by OpenEye Scientific Software, Inc. | 
| 3 | 
  | 
  | 
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison | 
| 4 | 
  | 
  | 
Some portions Copyright (C) 2004 by Chris Morley | 
| 5 | 
  | 
  | 
  | 
| 6 | 
  | 
  | 
This program is free software; you can redistribute it and/or modify | 
| 7 | 
  | 
  | 
it under the terms of the GNU General Public License as published by | 
| 8 | 
  | 
  | 
the Free Software Foundation version 2 of the License. | 
| 9 | 
  | 
  | 
  | 
| 10 | 
  | 
  | 
This program is distributed in the hope that it will be useful, | 
| 11 | 
  | 
  | 
but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 12 | 
  | 
  | 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 13 | 
  | 
  | 
GNU General Public License for more details. | 
| 14 | 
  | 
  | 
***********************************************************************/ | 
| 15 | 
  | 
  | 
 | 
| 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(__FUNCTION__, | 
| 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); | 
| 86 | 
  | 
  | 
    if(pmol==NULL) | 
| 87 | 
  | 
  | 
        return false; | 
| 88 | 
  | 
  | 
 | 
| 89 | 
  | 
  | 
    //Define some references so we can use the old parameter names | 
| 90 | 
  | 
  | 
    ostream &ofs = *pConv->GetOutStream(); | 
| 91 | 
  | 
  | 
    OBMol &mol = *pmol; | 
| 92 | 
  | 
  | 
 | 
| 93 | 
  | 
  | 
    unsigned int i; | 
| 94 | 
  | 
  | 
    char buffer[BUFF_SIZE]; | 
| 95 | 
  | 
  | 
    OBBond *bond; | 
| 96 | 
  | 
  | 
    vector<OBEdgeBase*>::iterator j; | 
| 97 | 
  | 
  | 
 | 
| 98 | 
  | 
  | 
    sprintf(buffer,"%6d %-20s   MM2 parameters",mol.NumAtoms(),mol.GetTitle()); | 
| 99 | 
  | 
  | 
    ofs << buffer << endl; | 
| 100 | 
  | 
  | 
 | 
| 101 | 
  | 
  | 
    ttab.SetFromType("INT"); | 
| 102 | 
  | 
  | 
 | 
| 103 | 
  | 
  | 
    OBAtom *atom; | 
| 104 | 
  | 
  | 
    string str,str1; | 
| 105 | 
  | 
  | 
    for(i = 1;i <= mol.NumAtoms(); i++) | 
| 106 | 
  | 
  | 
    { | 
| 107 | 
  | 
  | 
        atom = mol.GetAtom(i); | 
| 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", | 
| 112 | 
  | 
  | 
                i, | 
| 113 | 
  | 
  | 
                etab.GetSymbol(atom->GetAtomicNum()), | 
| 114 | 
  | 
  | 
                atom->GetX(), | 
| 115 | 
  | 
  | 
                atom->GetY(), | 
| 116 | 
  | 
  | 
                atom->GetZ(), | 
| 117 | 
  | 
  | 
                atoi((char*)str1.c_str())); | 
| 118 | 
  | 
  | 
        ofs << buffer; | 
| 119 | 
  | 
  | 
 | 
| 120 | 
  | 
  | 
        for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j)) | 
| 121 | 
  | 
  | 
        { | 
| 122 | 
  | 
  | 
            sprintf(buffer,"%6d", (bond->GetNbrAtom(atom))->GetIdx()); | 
| 123 | 
  | 
  | 
            ofs << buffer; | 
| 124 | 
  | 
  | 
        } | 
| 125 | 
  | 
  | 
 | 
| 126 | 
  | 
  | 
        ofs << endl; | 
| 127 | 
  | 
  | 
    } | 
| 128 | 
  | 
  | 
 | 
| 129 | 
  | 
  | 
    return(true); | 
| 130 | 
  | 
  | 
} | 
| 131 | 
  | 
  | 
 | 
| 132 | 
  | 
  | 
} //namespace OpenBabel |