Exemple #1
0
  bool OutputFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
  {
    // so we want to read through the file until we can figure out
    // what program actually created it
    // if we get to the end, emit a warning
    istream &ifs = *pConv->GetInStream();
    char buffer[BUFF_SIZE];
    OBFormat *pFormat = NULL;
    std::string formatName;

    // the detection strings are from the Chemical MIME project
    // http://chemical-mime.sourceforge.net/chemical-mime-data.html
    while (ifs.getline(buffer,BUFF_SIZE)) {
      if ((strstr(buffer,"GAMESS execution script") != NULL) ||
          (strstr(buffer,"PC GAMESS") != NULL) ||
          (strstr(buffer,"GAMESS VERSION") != NULL)) {
        // GAMESS output
        formatName = "gamout";
        break;
      } else if (strstr(buffer,"===  G A M E S S - U K    === ") != NULL) {
        // GAMESS-UK output
        formatName = "gukout";
        break;
      } else if (strstr(buffer,"Gaussian, Inc") != NULL) {
        // Gaussian output
        formatName = "g03";
        break;
      } else if (strstr(buffer,"GENERAL UTILITY LATTICE PROGRAM") != NULL) {
        // GULP output -- not currently supported
        break;
      } else if (strstr(buffer,"MOPAC") != NULL) {
        // MOPAC output
        formatName = "mopout";
        break;
      } else if (strstr(buffer,"Program PWSCF") != NULL) {
        // PWSCF
        formatName = "pwscf";
        break;
      } else if (strstr(buffer,"Welcome to Q-Chem") != NULL) {
        // Q-Chem output
        formatName = "qcout";
        break;
      } else if (strstr(buffer,"Amsterdam Density Functional") != NULL) {
        // ADF output
        // Determine the kind of ADF output
        while (ifs.getline(buffer, BUFF_SIZE)) {
          if (strstr(buffer, "|     A D F     |") != NULL) {
            formatName = "adfout";
            break;
          } else if (strstr(buffer, "|     B A N D     |") != NULL) {
            formatName = "adfband";
            break;
          } else if (strstr(buffer, "|     D F T B     |") != NULL) {
            formatName = "adfdftb";
            break;
          } else if (strstr(buffer, "DFTB Engine") != NULL) {
            // "|     D F T B     |" is no longer printed in ADF 2018
            // Hopefully, "DFTB Engine" will work fine...
            formatName = "adfdftb";
            break;
          }
        }
        break;
      } else if (strstr(buffer,"Northwest Computational Chemistry") != NULL) {
        // NWChem output
        formatName = "nwo";
        break;
      } else if (strstr(buffer,"MPQC: Massively Parallel Quantum Chemistry") != NULL) {
        // MPQC output
        formatName = "mpqc";
        break;
      } else if (strstr(buffer,"PROGRAM SYSTEM MOLPRO") != NULL) {
        // MOLPRO output
        formatName = "mpo";
        break;
      } else if ((strstr(buffer,"Schrodinger, Inc.") != NULL) &&
                 (strstr(buffer,"Jaguar") != NULL)) {
        // Jaguar
        formatName = "jout";
        break;
      } else if (strstr(buffer, "ABINIT") != NULL) {
        // Abinit
        formatName = "abinit";
        break;
      } else if (strstr(buffer, "ACES2") != NULL) {
        // ACESII
        formatName = "acesout";
        break;
      } else if (strstr(buffer, "CRYSTAL06") != NULL ||
                 strstr(buffer, "CRYSTAL09") != NULL) {
        // CRYSTAL09
        formatName = "c09out";
        break;
      } else if (strstr(buffer, "* O   R   C   A *") != NULL) {
        // ORCA
        formatName = "orca";
        break;
      } else if (strstr(buffer, "WELCOME TO SIESTA") != NULL) {
        // SIESTA
        formatName = "siesta";
        break;
      }
    }

    // if we assigned something above, let's try to find it
    if (formatName.length())
      pFormat = pConv->FindFormat(formatName);

    if (pFormat) {
      ifs.seekg (0, ios::beg); // reset the stream to the beginning
      ifs.clear();
      bool success = pFormat->ReadMolecule(pOb, pConv);

      // Tag the molecule with the format (e.g., if a program wants to know the kind of "out" or "log" file)
      // We have to do this *after* ReadMolecule returns, or the data might be cleared
      if (pOb) {
        OBPairData *dp = new OBPairData;
        dp->SetAttribute("File Format");
        dp->SetValue(formatName);
        dp->SetOrigin(fileformatInput);
        pOb->SetData(dp);
      }

      return success;
    }

    obErrorLog.ThrowError(__FUNCTION__,
                          "Problems reading an output file: Could not determine the format of this file. Please report it to the openbabel-discuss @ lists.sourceforge.net mailing list.", obError);
    return(false); // we couldn't figure out the format
  }
bool CMLReactFormat::DoElement(const string& name)
{
  double val;

  if(name=="reaction")
  {
    _spmol.reset();
    _preact->SetTitle(_pxmlConv->GetAttribute("id"));
  }

  else if(name=="molecule")
  {
    string reference = _pxmlConv->GetAttribute("ref");
    if(!reference.empty())
    {
      _spmol = IMols[reference];
      pmol = _spmol.get();
      if(!pmol)
      {
        cerr << " Molecule reference \"" << reference <<"\" not found" << endl;
        return false;
      }
    }
    else
    {
      shared_ptr<OBMol> sp(new OBMol);	
      OBFormat* pCMLFormat = OBConversion::FindFormat("cml");
      if(!pCMLFormat)
        return false;
      _pxmlConv->_SkipNextRead=true;
      pCMLFormat->ReadMolecule(sp.get(), _pxmlConv);

      //Store smart pointers to all molecules in map
      _spmol=sp;
      AddMolToList(_spmol,IMols);
    }
  }
  else if(name=="rateParameters")
  {
    _pRD = new OBRateData; //to store rate constant data
   _preact->SetData(_pRD);

    string rt = _pxmlConv->GetAttribute("reactionType");
    OBRateData::reaction_type enumrt=OBRateData::ARRHENIUS;
    if(rt=="arrhenius")       enumrt=OBRateData::ARRHENIUS;
    else if(rt=="lindermann") enumrt=OBRateData::LINDERMANN;
    else if(rt=="troe")       enumrt=OBRateData::TROE;
    else if(rt=="sri")        enumrt=OBRateData::SRI;
    else if(rt=="threeBody")  enumrt=OBRateData::THREEBODY;
    else
      obErrorLog.ThrowError(__FUNCTION__, rt + " is not a known reactionType", obWarning);
    _pRD->ReactionType = enumrt;

    if(_pxmlConv->GetAttribute("reversible")=="true")
      _preact->SetReversible();
  }

  else if(_pRD && name=="A")
  {
    if(_pxmlConv->GetContentDouble(val))
      _pRD->SetRate(OBRateData::A, val);
  }
  else if(_pRD && name=="n")
  {
    if(_pxmlConv->GetContentDouble(val))
      _pRD->SetRate(OBRateData::n, val);
  }
  else if(_pRD && name=="E")
  {
    if(_pxmlConv->GetContentDouble(val))
      _pRD->SetRate(OBRateData::E, val);
  }
  else if(_pRD && name=="loA")
  {
    if(_pxmlConv->GetContentDouble(val))
      _pRD->SetLoRate(OBRateData::A, val);
  }
  else if(_pRD && name=="lon")
  {
    if(_pxmlConv->GetContentDouble(val))
      _pRD->SetLoRate(OBRateData::n, val);
  }
  else if(_pRD && name=="loE")
  {
    if(_pxmlConv->GetContentDouble(val))
      _pRD->SetLoRate(OBRateData::E, val);
  }
  else if(_pRD && name=="troeParams")
  {
    string txt(_pxmlConv->GetContent());
    if(!txt.empty())
    {
      stringstream ss(txt);
      for(int i=0;i<4;++i)
      {
        ss >>val;
        _pRD->SetTroeParams(i, val);
      }
    }
Exemple #3
0
bool RXNFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
    OBMol* pmol = pOb->CastAndClear<OBMol>();
    if (pmol == NULL)
      return false;

    OBFormat* pMolFormat = pConv->FindFormat("MOL");
    if (pMolFormat==NULL)
      return false;

    istream &ifs = *pConv->GetInStream();
    string ln;
    // When MDLFormat reads the last product it may also read and discard
    // the line with $RXN for the next reaction. But it then sets $RXNread option.
    if(pConv->IsOption("$RXNread"))
      pConv->RemoveOption("$RXNread", OBConversion::OUTOPTIONS);
    else
    {
      if (!getline(ifs,ln))
        return(false);
      if(Trim(ln).find("$RXN")!=0)
        return false; //Has to start with $RXN
    }
    if (!getline(ifs,ln))
      return false; //reaction title
    pmol->SetTitle(Trim(ln));

    if (!getline(ifs,ln))
      return false; //creator
    if (!getline(ifs, ln))
      return false; //comment
    // Originally the comment was added to the reaction via:
    //     pmol->SetComment(Trim(ln));

    if (!getline(ifs, ln))
      return false; // num reactants, products, and optionally agents

    unsigned int nReactants = 0, nProducts = 0, nAgents = 0;
    bool ok = ParseComponent(ln.c_str() + 0, &nReactants);
    if (!ok)
      return false;
    ok = ParseComponent(ln.c_str() + 3, &nProducts);
    if (!ok)
      return false;
    if (ln[6] != '\0') { // optional agents
      ok = ParseComponent(ln.c_str() + 6, &nAgents);
      if (!ok)
        return false;
    }

    if(nReactants + nProducts + nAgents)
    {
      //Read the first $MOL. The others are read at the end of the previous MOL
      if(!getline(ifs, ln))
        return false;
      if(Trim(ln).find("$MOL")==string::npos)
        return false;
    }

    OBReactionFacade rxnfacade(pmol);

    // Note: If we supported it, we could read each of the rxn components directly
    // into the returned OBMol instead of having to do a copy. Unfortunately,
    // this isn't possible at the moment (MOL format will need some work first).
    // Here is some example code to do it:
    //
    //unsigned int old_numatoms = 0;
    //unsigned int compid = 1;
    //for (int i = 0; i<nReactants; i++)
    //{
    //  //Read a MOL file	using the same OBConversion object but with a different format
    //  if (!pMolFormat->ReadMolecule(pmol, pConv))
    //    obErrorLog.ThrowError(__FUNCTION__, "Failed to read a reactant", obWarning);
    //  unsigned int numatoms = pmol->NumAtoms();
    //  for (unsigned int idx = old_numatoms + 1; idx <= numatoms; ++idx) {
    //    OBAtom* atom = pmol->GetAtom(idx);
    //    rxnfacade.SetRole(atom, REACTANT);
    //    rxnfacade.SetComponentId(atom, compid);
    //  }
    //  old_numatoms = numatoms;
    //  compid++;
    //}

    const char* type[3] = {"a reactant", "a product", "an agent"};
    OBReactionRole role;
    unsigned int num_components;
    for(unsigned int N=0; N<3; N++) {
      switch(N) {
      case 0:
        role = REACTANT;
        num_components = nReactants;
        break;
      case 1:
        role = PRODUCT;
        num_components = nProducts;
        break;
      case 2:
        role = AGENT;
        num_components = nAgents;
        break;
      }
      for (int i=0; i<num_components; i++)
      {
        //Read a MOL file	using the same OBConversion object but with a different format
        OBMol mol;
        if (!pMolFormat->ReadMolecule(&mol, pConv)) {
          std::string error = "Failed to read ";
          error += type[N];
          obErrorLog.ThrowError(__FUNCTION__, error, obWarning);
          continue;
        }
        if (mol.NumAtoms() == 0) {
          OBAtom* dummy = mol.NewAtom(); // Treat the empty OBMol as having a single dummy atom
          OBPairData *pd = new OBPairData();
          pd->SetAttribute("rxndummy");
          pd->SetValue("");
          pd->SetOrigin(fileformatInput);
          dummy->SetData(pd);
        }

        rxnfacade.AddComponent(&mol, role);
      }
    }

    pmol->SetIsReaction();
    return true;
}
Exemple #4
0
  bool PQSFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
  {

    OBMol* pmol = pOb->CastAndClear<OBMol>();
    if(pmol==NULL)
      return false;

    //Define some references so we can use the old parameter names
    istream &ifs = *pConv->GetInStream();
    OBMol &mol = *pmol;
    const char* title = pConv->GetTitle();

    char buffer[BUFF_SIZE];
    char coord_file[256];
    char full_coord_path[256]="\0";
    ifstream coordFileStream;
    double bohr_to_angstrom=1.0;
    unsigned int input_style, atom_count=0; //CM i removed
    bool geom_found;

    geom_found=false;
    while (!geom_found && ifs.getline(buffer,BUFF_SIZE))
      {
        lowerit(buffer);      //look for geom except in title or text
        if (strstr(buffer,"geom")!=NULL &&
            (strncmp(buffer,"text",4)!=0 && strncmp(buffer,"titl",4)!=0))
          {
            geom_found=true;
            lowerit(buffer);

            if (strstr(buffer,"bohr")!=NULL)
              bohr_to_angstrom=0.529177249;
            else
              bohr_to_angstrom=1.0;
            input_style=0;
            if (strstr(buffer,"=tx90")!=NULL)
              input_style=1;
            if (strstr(buffer,"=tx92")!=NULL)
              input_style=0;
            if (strstr(buffer,"=pqs" )!=NULL)
              input_style=0;

            if (strstr(buffer,"file=")!=NULL)
              {  //external geometry file
                strncpy(coord_file,strstr(buffer,"file=")+5, sizeof(coord_file));
                coord_file[sizeof(coord_file) - 1] = '\0';
                if (strrchr(coord_file,' ')!=NULL)
                  *strrchr(coord_file,' ')='\0';
                if (coord_file[0]!='/')
                  {
                    strncpy(full_coord_path,title, sizeof(full_coord_path));
                    full_coord_path[sizeof(full_coord_path)-1] = '\0';
                    if (strrchr(full_coord_path,'/')!=NULL)
                      *(strrchr(full_coord_path,'/')+1)='\0';
                    else
                      full_coord_path[0] = '\0';
                  }
                strcat(full_coord_path,coord_file);
                full_coord_path[sizeof(full_coord_path) - 1] = '\0';
                stringstream errorMsg;
                errorMsg <<"External geometry file referenced: "<< \
                  full_coord_path<<endl;
                obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obInfo);

                coordFileStream.open(full_coord_path);
                if (!coordFileStream)
                  {
                    obErrorLog.ThrowError(__FUNCTION__, "Cannot read external geometry file!", obError);
                    return(false);
                    //                    exit (-1);
                  }
                else
                  {
                    ifs.seekg(0, ios::end); //move .inp file pointer to the end of file

                    //New framework mods
                    OBConversion coordconv(&coordFileStream);
                    OBFormat* pFormat;
                    if (strstr(buffer,"=car" )!=NULL)
                      pFormat =OBConversion::FindFormat("BIOSYM");
                    if (strstr(buffer,"=hin" )!=NULL)
                      pFormat = OBConversion::FindFormat("HIN");
                    if (strstr(buffer,"=pdb" )!=NULL)
                      pFormat = OBConversion::FindFormat("PDB");
                    if (strstr(buffer,"=mop" )!=NULL)
                      pFormat = OBConversion::FindFormat("MOPAC");
                    return pFormat->ReadMolecule(&mol,&coordconv);

                    /*         if (strstr(buffer,"=car" )!=NULL)
                               return ReadBiosymCAR(coordFileStream, mol, title);
                               if (strstr(buffer,"=hin" )!=NULL)
                               return ReadHIN(coordFileStream, mol, title);
                               if (strstr(buffer,"=pdb" )!=NULL)
                               return ReadPDB(coordFileStream, mol, title);
                               if (strstr(buffer,"=mop" )!=NULL)
                               return ReadMOPAC(coordFileStream, mol, title);
                    */
                    //end new framework mods

                    //probably pqs's own xyz format
                    atom_count=ReadPQS_geom(coordFileStream,mol,title,
                                            input_style,bohr_to_angstrom);
                  }
              }
          }
      }

    if (geom_found)
      {
        if (atom_count==0)        //read directly form .inp file
          atom_count=ReadPQS_geom(ifs,mol,title,input_style,bohr_to_angstrom);
        if (atom_count==0)
          {   //try .coord file
            strncpy(coord_file,title, sizeof(coord_file));
            coord_file[sizeof(coord_file) - 1] = '\0';
            if (strrchr(coord_file,'.')!=NULL)
              *strrchr(coord_file,'.')='\0';
            strcat(coord_file,".coord");
            coordFileStream.open(coord_file);
            if (!coordFileStream)
              {
                stringstream errorMsg;
                errorMsg <<"ReadPQS: cannot read external "<<coord_file<<" file!"<<endl;
                obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obError);
                return(false);
                //                exit (-1);
              }
            else
              atom_count=ReadPQS_geom(coordFileStream,mol,title,0,
                                      bohr_to_angstrom);
          }
      }
    else
      obErrorLog.ThrowError(__FUNCTION__, "Error reading PQS file.  GEOM card not found!", obWarning);

    ifs.seekg(0, ios::end); //move .inp file pointer to the end of file
    if (atom_count>0)
      return true;
    else
      return false;
  }