Skip to content

Instantly share code, notes, and snippets.

@andersx
Created February 1, 2017 12:14
Show Gist options
  • Select an option

  • Save andersx/92550e6b8e1362ed0cf4327666feca54 to your computer and use it in GitHub Desktop.

Select an option

Save andersx/92550e6b8e1362ed0cf4327666feca54 to your computer and use it in GitHub Desktop.
Example to run mopac and get energy via C++
double calc_mopac_energy(OpenBabel::OBMol &mol) {
OpenBabel::OBConversion conv;
conv.SetInAndOutFormats("moo", "mop");
std::remove("temp.mop");
std::remove("temp.out");
std::remove("temp.arc");
std::ofstream ofs("temp.mop");
conv.Write(&mol, &ofs);
system("./run_mopac");
ofs.close();
std::ifstream ifs;
OpenBabel::OBMol molout;
ifs.open("temp.out");
conv.Read(&molout, &ifs);
ifs.close();
return molout.GetEnergy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment