Esempio n. 1
0
int main(int argc,char **argv)
{
  char *program_name= argv[0];
  int c;
  char *FileIn = NULL;

  if (argc != 2) {
    cerr << " Usage: " << program_name << " <input file>\n";
    exit(-1);
  }
  else {
      FileIn  = argv[1];
  }

  // Find Input filetype
  OBConversion conv(&cin, &cout);
  OBFormat *inFormat = conv.FormatFromExt(FileIn);

  if (!inFormat || !conv.SetInFormat(inFormat)) {
    cerr << program_name << ": cannot read input format!" << endl;
    exit (-1);
  }
  // If we can't also use this for an output format, use XYZ
  if (!conv.SetOutFormat(inFormat))
    conv.SetOutFormat(conv.FindFormat("xyz"));

  ifstream ifs;

  // Read the file
  ifs.open(FileIn);
  if (!ifs) {
    cerr << program_name << ": cannot read input file!" << endl;
    exit (-1);
  }

  OBMol mol;
  OBPointGroup pg;

  for (c = 1;; ++c)
    {
      mol.Clear();
      conv.Read(&mol, &ifs);
      if (mol.Empty())
        break;

      // not needed by OBPointGroup, but useful for external programs
      pg.Setup(&mol);
      cerr << "Point Group: " << pg.IdentifyPointGroup() << endl;
      pg.Symmetrize(&mol);

      conv.Write(&mol, &cout);

    } // end for loop

  return(1);
}
Esempio n. 2
0
int main(int argc,char **argv)
{
  char *program_name= argv[0];
  int c;
  char *FileIn = NULL;

  if (argc != 2) {
    cerr << " Usage: " << program_name << " <input file>\n";
    exit(-1);
  }
  else {
      FileIn  = argv[1];
  }

  // Find Input filetype
  OBConversion conv;
  OBFormat *inFormat = conv.FormatFromExt(FileIn);
    
  if (!inFormat || !conv.SetInFormat(inFormat)) {
    cerr << program_name << ": cannot read input format!" << endl;
    exit (-1);
  }

  ifstream ifs;

  // Read the file
  ifs.open(FileIn);
  if (!ifs) {
    cerr << program_name << ": cannot read input file!" << endl;
    exit (-1);
  }

  OBMol mol;
  OBPointGroup pg;

  for (c = 1;; ++c)
    {
      mol.Clear();
      conv.Read(&mol, &ifs);
      if (mol.Empty())
        break;
      
      // not needed by OBPointGroup, but useful for external programs
      mol.Center();
      mol.ToInertialFrame();

      pg.Setup(&mol);
      cout << "Point Group: " << pg.IdentifyPointGroup() << endl;

    } // end for loop
  
  return(1);
}
Esempio n. 3
0
int main(int argc,char **argv)
{
  char  *program_name = argv[0];
  int    Nsymm = 0, Nrot = 0;
  bool   bKJ   = false;
  double dBdT  = 0;
  string filename, option;
  OBConversion conv;
  double unit_factor = 1;
  string e_unit("kcal/mol");
  string s_unit("cal/mol K");
  
  if (argc < 2) {
    cout << "Usage: obthermo [options] <filename>" << endl;
    cout << endl;
    cout << "options:      description:" << endl;
    cout << endl;
    cout << "  --symm N    override symmetry number used in input file" << endl;
    cout << endl;
    cout << "  --nrot N    number of rotatable bonds for conformational entropy" << endl;
    cout << endl;
    cout << "  --dbdt x    temperature derivative of second virial coefficient for cp calculation" << endl;
    cout << endl;
    cout << "  --kj        output kJ/mol related units (default kcal/mol)" << endl;
    cout << endl;
    exit(-1);
  } else {
    int i;
    for (i = 1; i < argc; ) {
      option = argv[i];

      if ((option == "--symm") && (argc > (i+1))) {
        Nsymm = atoi(argv[i+1]);
        if (Nsymm < 1) {
            cerr << program_name << ": the symmetry number should be >= 1!" << endl;
            exit(-1);
        }
        i += 2;
      }
      else if ((option == "--nrot") && (argc > (i+1))) {
        Nrot = atoi(argv[i+1]);
        if (Nrot < 0) {
            cerr << program_name << ": the number of rotatable bonds should be >= 0!" << endl;
            exit(-1);
        }
        i += 2;
      }
      else if ((option == "--dbdt") && (argc > (i+1))) {
        dBdT = atof(argv[i+1]);
        if (dBdT < 0) {
            cerr << program_name << ": the derivative of the second virial coefficient with respect to temperature should be >= 0!" << endl;
            exit(-1);
        }
        i += 2;
      }
      else if (option == "--kj") {
        bKJ          = true;
        unit_factor  = 4.184;
        e_unit.assign("kJ/mol");
        s_unit.assign("J/mol K");
        i += 1;
      }
      else {
        filename.assign(argv[i]);
        i += 1;
      }
    }
  }
  if (filename.size() == 0) {
    cerr << program_name << ": no filename specified" << endl;
    exit (-1);
  }
  // Find Input filetype
  OBFormat *format_in = conv.FormatFromExt(filename.c_str());

  if (!format_in || !conv.SetInFormat(format_in)) {
    cerr << program_name << ": cannot read input format in file \"" << filename << "\"" << endl;
    exit (-1);
  }

  ifstream ifs;

  // Read the file
  ifs.open(filename.c_str());
  if (!ifs) {
    cerr << program_name << ": cannot read input file!" << endl;
    exit (-1);
  }
  OBMol mol;
  if ((conv.Read(&mol, &ifs)) && ! mol.Empty())
  {
      OBPointGroup obPG;
      double temperature, DeltaHf0, DeltaHfT, DeltaGfT, DeltaSfT, S0T, CVT, CPT, ZPVE;
      std::vector<double> Scomponents;
      
      obPG.Setup(&mol);
      printf("obthermo - extract thermochemistry data from quantum chemistry logfiles\n");
      printf("Number of rotatable bonds: %d\n", Nrot);
      if (dBdT == 0)
      {
          printf("Please supply --dbdt option to get reliable heat capacity at constant pressure.\n");
      }
      printf("Point group according to OpenBabel: %s\n", 
             obPG.IdentifyPointGroup());
      bool bVerbose = true;
      if (extract_thermochemistry(mol, 
                                  bVerbose,
                                  &Nsymm,
                                  Nrot,
                                  dBdT,
                                  &temperature,
                                  &DeltaHf0,
                                  &DeltaHfT,
                                  &DeltaGfT,
                                  &DeltaSfT,
                                  &S0T,
                                  &CVT,
                                  &CPT,
                                  Scomponents,
                                  &ZPVE))
      {
          double Rgas  = 1.9872041; // cal/mol K
          printf("DeltaHform(0K)  %10g  %s\n", DeltaHf0*unit_factor, e_unit.c_str());
          printf("Temperature     %10g  K\n", temperature);
          printf("DeltaHform(T)   %10g  %s\n", DeltaHfT*unit_factor, e_unit.c_str());
          printf("DeltaGform(T)   %10g  %s\n", DeltaGfT*unit_factor, e_unit.c_str());
          printf("DeltaSform(T)   %10g  %s\n", DeltaSfT*unit_factor, s_unit.c_str());
          printf("cv(T)           %10g  %s\n", CVT*unit_factor, s_unit.c_str());
          printf("cp(T)           %10g  %s\n", CPT*unit_factor, s_unit.c_str());
          printf("Strans(T)       %10g  %s\n", Scomponents[0]*unit_factor, s_unit.c_str());
          printf("Srot(T)         %10g  %s\n", Scomponents[1]*unit_factor, s_unit.c_str());
          printf("Svib(T)         %10g  %s\n", Scomponents[2]*unit_factor, s_unit.c_str());
          if (Scomponents[3] != 0) 
          {
              printf("Ssymm           %10g  %s\n", Scomponents[3]*unit_factor, s_unit.c_str());
          }
          if (Scomponents[4] != 0) 
          {
              printf("Sconf           %10g  %s\n", Scomponents[4]*unit_factor, s_unit.c_str());
          }
          printf("S0(T)           %10g  %s\n", S0T*unit_factor, s_unit.c_str());
      }
      else
      {
          printf("Could not find all necessary information to determine thermochemistry values.\n");
      }
  }
  ifs.close();
  
  return 0;
}
Esempio n. 4
0
static int extract_thermo(OpenBabel::OBMol *mol,string method,double temperature,
                          double ezpe,double Hcorr,double Gcorr,double E0,double CV,
                          int RotSymNum,std::vector<double> Scomponents)
{
    // Initiate correction database
    OpenBabel::OBAtomicHeatOfFormationTable *ahof = new OpenBabel::OBAtomicHeatOfFormationTable();
    OpenBabel::OBAtomIterator OBai;
    OpenBabel::OBAtom *OBa;
    OpenBabel::OBElementTable *OBet;
    char valbuf[128];
    int ii,atomid,atomicnumber,found,foundall;
    double dhofM0, dhofMT, S0MT, DeltaSMT;
    double eFactor = HARTEE_TO_KCALPERMOL;

    OBet = new OpenBabel::OBElementTable();

    // Now loop over atoms in order to correct the Delta H formation
    OBai     = mol->BeginAtoms();
    atomid   = 0;
    foundall = 0;
    dhofM0   = E0*eFactor;
    dhofMT   = dhofM0+(Hcorr-ezpe)*eFactor;
    S0MT     = 0;
    if (temperature > 0)
    {
        // Multiply by 1000 to make the unit cal/mol K
        S0MT += 1000*eFactor*(Hcorr-Gcorr)/temperature;
    }

    // Check for symmetry
    OBPointGroup obPG;

    obPG.Setup(mol);
    const char *pg = obPG.IdentifyPointGroup();

    double Rgas = 1.9872041; // cal/mol K http://en.wikipedia.org/wiki/Gas_constant
    double Srot = -Rgas * log(RotSymNum);

    //printf("DHf(M,0) = %g, DHf(M,T) = %g, S0(M,T) = %g\nPoint group = %s RotSymNum = %d Srot = %g\n",
    //       dhofM0, dhofMT, S0MT, pg, RotSymNum, Srot);
    if (RotSymNum > 1)
    {
        // We assume Gaussian has done this correctly!
        Srot = 0;
    }
    S0MT     += Srot;
    DeltaSMT  = S0MT;

    for (OBa = mol->BeginAtom(OBai); (NULL != OBa); OBa = mol->NextAtom(OBai))
    {
        double dhfx0, dhfxT, S0xT;
        atomicnumber = OBa->GetAtomicNum();
        found = ahof->GetHeatOfFormation(OBet->GetSymbol(atomicnumber),
                                         0,
                                         method,
                                         temperature,
                                         &dhfx0, &dhfxT, &S0xT);
        if (1 == found)
        {
            dhofM0 += dhfx0;
            dhofMT += dhfxT;
            DeltaSMT += S0xT;
            foundall ++;
        }
        atomid++;
    }
    if (foundall == atomid)
    {
        std::string attr[5];
        double result[5];
        char buf[32];

        attr[0].assign("DeltaHform(0K)");
        result[0] = dhofM0;
        snprintf(buf, sizeof(buf), "DeltaHform(%gK)", temperature);
        attr[1].assign(buf);
        result[1] = dhofMT;
        snprintf(buf, sizeof(buf), "DeltaSform(%gK)", temperature);
        attr[2].assign(buf);
        result[2] = DeltaSMT;
        snprintf(buf, sizeof(buf), "DeltaGform(%gK)", temperature);
        attr[3].assign(buf);
        result[3] = dhofMT - temperature*result[2]/1000;
        snprintf(buf, sizeof(buf), "S0(%gK)", temperature);
        attr[4].assign(buf);
        result[4] = S0MT;

        add_unique_pairdata_to_mol(mol, "method", method, 0);
        for(ii=0; (ii<5); ii++)
        {
            // Add to molecule properties
            sprintf(valbuf,"%f", result[ii]);
            add_unique_pairdata_to_mol(mol, attr[ii], valbuf, 0);
        }
        sprintf(valbuf, "%f", CV);
        add_unique_pairdata_to_mol(mol, "cv", valbuf, 0);
        sprintf(valbuf, "%f", CV+Rgas);
        add_unique_pairdata_to_mol(mol, "cp", valbuf, 0);
        // Entropy components
        if (Scomponents.size() == 3)
        {
            const char *comps[3] = { "Strans", "Srot", "Svib" };
            for(int i=0; (i<3); i++)
            {
                sprintf(valbuf, "%f", Scomponents[i]);
                add_unique_pairdata_to_mol(mol, comps[i], valbuf, 0);
            }
        }
        // Finally store the energy in internal data structures as well.
        mol->SetEnergy(dhofMT);
    }
    else
    {
        // Debug message?
    }
    // Clean up
    delete OBet;
    delete ahof;

    if (foundall == atomid)
        return 1;
    else
        return 0;
}