本文整理汇总了C++中OBConversion::FormatFromExt方法的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion::FormatFromExt方法的具体用法?C++ OBConversion::FormatFromExt怎么用?C++ OBConversion::FormatFromExt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBConversion
的用法示例。
在下文中一共展示了OBConversion::FormatFromExt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ifs
// Helper function to read molecule from file
shared_ptr<OBMol> GetMol(const std::string &filename)
{
// Create the OBMol object.
shared_ptr<OBMol> mol(new OBMol);
// Create the OBConversion object.
OBConversion conv;
OBFormat *format = conv.FormatFromExt(filename.c_str());
if (!format || !conv.SetInFormat(format)) {
std::cout << "Could not find input format for file " << filename << std::endl;
return mol;
}
// Open the file.
std::ifstream ifs(filename.c_str());
if (!ifs) {
std::cout << "Could not open " << filename << " for reading." << std::endl;
return mol;
}
// Read the molecule.
if (!conv.Read(mol.get(), &ifs)) {
std::cout << "Could not read molecule from file " << filename << std::endl;
return mol;
}
return mol;
}
示例2: MakeQueriesFromMolInFile
bool MakeQueriesFromMolInFile(vector<OBQuery*>& queries, const std::string& filename, int* pnAtoms, bool noH)
{
OBMol patternMol;
patternMol.SetIsPatternStructure();
OBConversion patternConv;
OBFormat* pFormat;
//Need to distinguish between filename and SMARTS. Not infallable...
if( filename.empty() ||
filename.find('.')==string::npos ||
!(pFormat = patternConv.FormatFromExt(filename.c_str())) ||
!patternConv.SetInFormat(pFormat) ||
!patternConv.ReadFile(&patternMol, filename) ||
patternMol.NumAtoms()==0)
return false;
if(noH)
patternMol.DeleteHydrogens();
do
{
*pnAtoms = patternMol.NumHvyAtoms();
queries.push_back(CompileMoleculeQuery(&patternMol));
}while(patternConv.Read(&patternMol));
return true;
}
示例3: readOutputFile
void InputFileExtension::readOutputFile(const QString filename)
{
QApplication::setOverrideCursor(Qt::WaitCursor);
OBConversion conv;
OBFormat *inFormat = conv.FormatFromExt( filename.toAscii() );
if ( !inFormat || !conv.SetInFormat( inFormat ) ) {
QApplication::restoreOverrideCursor();
QMessageBox::warning(m_widget, tr("Avogadro"),
tr("Cannot read file format of file %1.").arg(filename));
return;
}
// TODO: Switch to MoleculeFile
ifstream ifs;
ifs.open(QFile::encodeName(filename));
if (!ifs) { // shouldn't happen, already checked file above
QApplication::restoreOverrideCursor();
QMessageBox::warning(m_widget, tr("Avogadro"),
tr("Cannot read file %1.").arg( filename ) );
return;
}
OBMol *obmol = new OBMol;
if (conv.Read(obmol, &ifs)) {
Molecule *mol = new Molecule;
mol->setOBMol(obmol);
mol->setFileName(filename);
emit moleculeChanged(mol, Extension::DeleteOld);
m_molecule = mol;
}
QApplication::restoreOverrideCursor();
}
示例4: main
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);
}
示例5: main
int main(int argc, char **argv)
{
OBFunctionFactory *factory = OBFunctionFactory::GetFactory("MMFF94");
OBFunction *function = factory->NewInstance();
if (!function) {
cout << "ERROR: could not find MMFF94 function" << endl;
return -1;
}
if (argc < 2) {
cout << "Usage: " << argv[0] << " <filename>" << endl;
return -1;
}
OBMol mol;
OBConversion conv;
OBFormat *format = conv.FormatFromExt(argv[1]);
if (!format || !conv.SetInFormat(format)) {
cout << "ERROR: could not find format for file " << argv[1] << endl;
return -1;
}
std::ifstream ifs;
ifs.open(argv[1]);
conv.Read(&mol, &ifs);
ifs.close();
cout << "# atoms = " << mol.NumAtoms() << endl;
function->GetLogFile()->SetOutputStream(&std::cout);
function->GetLogFile()->SetLogLevel(OBLogFile::Low);
// read options file
if (argc == 3) {
std::ifstream cifs;
cifs.open(argv[2]);
std::stringstream options;
std::string line;
while (std::getline(cifs, line))
options << line << std::endl;
function->SetOptions(options.str());
}
function->Setup(mol);
OBMinimize minimize(function);
minimize.SteepestDescent(50);
}
示例6: main
int main(int argc, char **argv)
{
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " filename" << std::endl;
return -1;
}
// read a molecule
OBConversion conv;
OBFormat *format = conv.FormatFromExt(argv[1]);
conv.SetInFormat(format);
std::string filename(argv[1]);
std::ifstream ifs;
ifs.open(filename.c_str());
if (!ifs) {
std::cerr << "Could not open " << filename << std::endl;
return -1;
}
CairoPainter *painter = new CairoPainter;
OBDepict depictor(painter);
string::size_type pos = filename.find_last_of(".");
if (pos != string::npos)
filename = filename.substr(0, pos);
OBMol mol;
unsigned int count = 1;
while (conv.Read(&mol, &ifs)) {
// depict the molecule
depictor.DrawMolecule(&mol);
depictor.AddAtomLabels(OBDepict::AtomSymmetryClass);
std::stringstream ss;
ss << filename << count << ".png";
painter->WriteImage(ss.str());
count++;
}
return 0;
}
示例7: verifyLSSR
bool verifyLSSR(const std::string &filename, const LSSR &ref)
{
cout << "Verify LSSR: " << filename << endl;
std::string file = OBTestUtil::GetFilename(filename);
// read a smiles string
OBMol mol;
OBConversion conv;
OBFormat *format = conv.FormatFromExt(file.c_str());
OB_REQUIRE( format );
OB_REQUIRE( conv.SetInFormat(format) );
std::ifstream ifs;
ifs.open(file.c_str());
OB_REQUIRE( ifs );
OB_REQUIRE( conv.Read(&mol, &ifs) );
std::vector<int> ringSizeCount(20, 0);
std::vector<OBRing*> lssr = mol.GetLSSR();
for (unsigned int i = 0; i < lssr.size(); ++i) {
ringSizeCount[lssr[i]->_path.size()]++;
}
/*
cout << "ringSize: ringCount" << endl;
cout << "3: " << ringSizeCount[3] << endl;
cout << "4: " << ringSizeCount[4] << endl;
cout << "5: " << ringSizeCount[5] << endl;
cout << "6: " << ringSizeCount[6] << endl;
*/
bool fail = false;
for (unsigned int i = 0; i < ref.size_count.size(); ++i) {
const LSSR::Size_Count &size_count = ref.size_count[i];
OB_ASSERT( ringSizeCount[size_count.ringSize] == size_count.ringCount );
}
return true;
}
示例8: doShuffleTestMultiFile
bool doShuffleTestMultiFile(const std::string &filename)
{
cout << "Shuffling: " << filename << endl;
std::string file = OBTestUtil::GetFilename(filename);
// read a smiles string
OBMol mol;
OBConversion conv;
OBFormat *format = conv.FormatFromExt(file.c_str());
OB_REQUIRE( format );
OB_REQUIRE( conv.SetInFormat(format) );
std::ifstream ifs;
ifs.open(file.c_str());
OB_REQUIRE( ifs );
bool result = true;
while (conv.Read(&mol, &ifs)) {
bool res = doShuffleTestMolecule(mol);
if (!res)
result = res;
}
return result;
}
示例9: main
int main(int argc,char **argv)
{
char *program_name= argv[0];
int c;
int verbose = 0;
bool hydrogens = false;
string basename, filename = "", option, option2, ff = "";
OBConversion conv;
if (argc < 2) {
cout << "Usage: obenergy [options] <filename>" << endl << endl;
cout << "options: description:" << endl << endl;
cout << " -v verbose: print out indivual energy interactions" << endl << endl;
cout << " -h add hydrogens before calculating energy" << endl << endl;
cout << " -ff ffid select a forcefield" << endl << endl;
cout << " available forcefields:" << endl << endl;
OBPlugin::List("forcefields", "verbose");
exit(-1);
} else {
int ifile = 1;
for (int i = 1; i < argc; i++) {
option = argv[i];
if (option == "-v") {
verbose = 1;
ifile++;
break;
}
if (option == "-h") {
hydrogens = true;
ifile++;
}
if ((option == "-ff") && (argc > (i+1))) {
ff = argv[i+1];
ifile += 2;
}
}
basename = filename = argv[ifile];
size_t extPos = filename.rfind('.');
size_t startPos = 0;
if (extPos!= string::npos) {
basename = filename.substr(startPos, extPos);
}
}
// 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!" << endl;
exit (-1);
}
ifstream ifs;
ofstream ofs;
// Read the file
ifs.open(filename.c_str());
if (!ifs) {
cerr << program_name << ": cannot read input file!" << endl;
exit (-1);
}
OBForceField* pFF = OBForceField::FindForceField(ff);
if (!pFF) {
cerr << program_name << ": could not find forcefield '" << ff << "'." <<endl;
exit (-1);
}
pFF->SetLogFile(&cout);
pFF->SetLogLevel(OBFF_LOGLVL_NONE);
// if (verbose)
// pFF->SetLogLevel(OBFF_LOGLVL_HIGH);
// else
// pFF->SetLogLevel(OBFF_LOGLVL_MEDIUM);
Timer totalTimer, readTimer, setupTimer, computeTimer;
double totalTime, readTime, setupTime, computeTime;
int nthreads = 1; // single core is just one thread
unsigned int totalSteps = 1; // total steps is only used when doing minimization
#ifdef _OPENMP // START OPENMP DEBUG
#pragma omp parallel default(none) shared(nthreads)
{
nthreads = omp_get_num_threads(); // determine the number of threads
} // parallel region completes
#endif // END OPENMP DEBUG
// This code only deals with creating a file to store the timings for
// the execution of the program along with other interesting statistics
char cwd[1024]; // a reasonably large current working directory (cwd)
char filepath[1100]; // a reasonably large file name plus cwd
const char * statsfile = "obenergy_runstats";
//.........这里部分代码省略.........
示例10: main
int main(int argc, char **argv)
{
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <molecule_file> <output_score_file>" << std::endl;
return 1;
}
unsigned long numAtoms = 0;
unsigned long numAromaticAtoms = 0;
unsigned long numCyclicAtoms = 0;
std::map<int, unsigned long> mass;
std::map<int, unsigned long> elem;
std::map<int, unsigned long> aromelem;
std::map<int, unsigned long> aliphelem;
std::map<int, unsigned long> hcount;
std::map<int, unsigned long> charge;
std::map<int, unsigned long> connect;
std::map<int, unsigned long> degree;
std::map<int, unsigned long> implicit;
std::map<int, unsigned long> rings;
std::map<int, unsigned long> size;
std::map<int, unsigned long> valence;
std::map<int, unsigned long> chiral;
std::map<int, unsigned long> hyb;
std::map<int, unsigned long> ringconnect;
unsigned long numBonds = 0;
unsigned long numSingleBonds = 0;
unsigned long numDoubleBonds = 0;
unsigned long numTripleBonds = 0;
unsigned long numAromaticBonds = 0;
unsigned long numRingBonds = 0;
OBConversion conv;
conv.SetInFormat(conv.FormatFromExt(argv[1]));
std::ifstream ifs(argv[1]);
conv.SetInStream(&ifs);
OBMol mol;
unsigned long molecule = 0;
while (conv.Read(&mol)) {
++molecule;
//if ((molecule % 1000) == 0)
// std::cout << molecule << std::endl;
FOR_ATOMS_OF_MOL (atom, mol) {
numAtoms++;
if (atom->IsAromatic()) {
numAromaticAtoms++;
aromelem[atom->GetAtomicNum()]++;
} else
aliphelem[atom->GetAtomicNum()]++;
if (atom->IsInRing())
numCyclicAtoms++;
mass[atom->GetIsotope()]++;
elem[atom->GetAtomicNum()]++;
hcount[atom->ExplicitHydrogenCount() + atom->ImplicitHydrogenCount()]++;
charge[atom->GetFormalCharge()]++;
connect[atom->GetImplicitValence()]++;
degree[atom->GetValence()]++;
implicit[atom->ImplicitHydrogenCount()]++;
rings[atom->MemberOfRingCount()]++;
for (int i = 3; i < 25; ++i)
if (atom->IsInRingSize(i))
size[i]++;
valence[atom->KBOSum() - (atom->GetSpinMultiplicity() ? atom->GetSpinMultiplicity() - 1 : 0)]++;
hyb[atom->GetHyb()]++;
ringconnect[atom->CountRingBonds()]++;
}
FOR_BONDS_OF_MOL (bond, mol) {
numBonds++;
if (bond->IsSingle())
numSingleBonds++;
else if (bond->IsDouble())
numDoubleBonds++;
else if (bond->IsTriple())
numTripleBonds++;
if (bond->IsAromatic())
numAromaticBonds++;
if (bond->IsInRing())
numRingBonds++;;
}
示例11: main
///////////////////////////////////////////////////////////////////////////////
//! \brief Generate rough 3D coordinates for SMILES (or other 0D files).
//
int main(int argc,char **argv)
{
char *program_name= argv[0];
int c;
string basename, filename = "", option, option2, ff = "MMFF94";
list<string> argl(argv+1, argv+argc);
list<string>::iterator optff = find(argl.begin(), argl.end(), "-ff");
if (optff != argl.end()) {
list<string>::iterator optffarg = optff;
++optffarg;
if (optffarg != argl.end()) {
ff = *optffarg;
argl.erase(optff,++optffarg);
} else {
argl.erase(optff);
}
}
if (argl.empty()) {
cout << "Usage: obgen <filename> [options]" << endl;
cout << endl;
cout << "options: description:" << endl;
cout << endl;
cout << " -ff select a forcefield" << endl;
cout << endl;
OBPlugin::List("forcefields", "verbose");
exit(-1);
}
basename = filename = *argl.begin();
size_t extPos = filename.rfind('.');
if (extPos!= string::npos) {
basename = filename.substr(0, extPos);
}
// Find Input filetype
OBConversion conv;
OBFormat *format_in = conv.FormatFromExt(filename.c_str());
OBFormat *format_out = conv.FindFormat("sdf");
if (!format_in || !format_out || !conv.SetInAndOutFormats(format_in, format_out)) {
cerr << program_name << ": cannot read input/output format!" << endl;
exit (-1);
}
ifstream ifs;
ofstream ofs;
// Read the file
ifs.open(filename.c_str());
if (!ifs) {
cerr << program_name << ": cannot read input file!" << endl;
exit (-1);
}
OBMol mol;
for (c=1;;c++) {
mol.Clear();
if (!conv.Read(&mol, &ifs))
break;
if (mol.Empty())
break;
OBForceField* pFF = OBForceField::FindForceField(ff);
if (!pFF) {
cerr << program_name << ": could not find forcefield '" << ff << "'." <<endl;
exit (-1);
}
//mol.AddHydrogens(false, true); // hydrogens must be added before Setup(mol) is called
pFF->SetLogFile(&cerr);
pFF->SetLogLevel(OBFF_LOGLVL_LOW);
//pFF->GenerateCoordinates();
OBBuilder builder;
builder.Build(mol);
mol.AddHydrogens(false, true); // hydrogens must be added before Setup(mol) is called
if (!pFF->Setup(mol)) {
cerr << program_name << ": could not setup force field." << endl;
exit (-1);
}
pFF->SteepestDescent(500, 1.0e-4);
pFF->WeightedRotorSearch(250, 50);
pFF->SteepestDescent(500, 1.0e-6);
pFF->UpdateCoordinates(mol);
//pFF->ValidateGradients();
//pFF->SetLogLevel(OBFF_LOGLVL_HIGH);
//.........这里部分代码省略.........
示例12: main
int main(int argc,char **argv)
{
char *program_name= argv[0];
int c;
char *FileIn = NULL;
if (argc != 2)
{
string err = "Usage: ";
err += program_name;
err += " <filename>\n"
"Output format:\n"
"name NAME\n"
"formula FORMULA\n"
"mol_weight MOLECULAR_WEIGHT\n"
"exact_mass ISOTOPIC MASS\n"
"canonical_SMILES STRING\n"
"InChI STRING\n"
"num_atoms NUM\n"
"num_bonds NUM\n"
"num_residues NUM\n"
"num_rotors NUM\n"
"sequence RESIDUE_SEQUENCE\n"
"num_rings NUMBER_OF_RING_(SSSR)\n"
"logP NUM\n"
"PSA POLAR_SURFACE_AREA\n"
"MR MOLAR REFRACTIVITY";
err += "$$$$";
// ThrowError(err); wasn't being output because error level too low
cerr << err; //Why not do directly
exit(-1);
}
else
{
FileIn = argv[1];
}
// Find Input filetype
OBConversion conv;
OBFormat *format = conv.FormatFromExt(FileIn);
if (!format || !conv.SetInFormat(format))
{
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;
OBFormat *canSMIFormat = conv.FindFormat("can");
OBFormat *inchiFormat = conv.FindFormat("inchi");
////////////////////////////////////////////////////////////////////////////
// List of properties
// Name
// Molecular weight (Standard molar mass given by IUPAC atomic masses)
// Number of rings : the size of the smallest set of smallest rings (SSSR)
//.....ADD YOURS HERE.....
for (c = 1;; ++c)
{
mol.Clear();
conv.Read(&mol, &ifs);
if (mol.Empty())
break;
if (!mol.HasHydrogensAdded())
mol.AddHydrogens();
// Print the properties
if (strlen(mol.GetTitle()) != 0)
cout << "name " << mol.GetTitle() << endl;
else
cout << "name " << FileIn << " " << c << endl;
cout << "formula " << mol.GetFormula() << endl;
cout << "mol_weight " << mol.GetMolWt() << endl;
cout << "exact_mass " << mol.GetExactMass() << endl;
string smilesString = "-";
if (canSMIFormat) {
conv.SetOutFormat(canSMIFormat);
smilesString = conv.WriteString(&mol);
if ( smilesString.length() == 0 )
{
smilesString = "-";
}
}
cout << "canonical_SMILES " << smilesString << endl;
//.........这里部分代码省略.........
示例13: ObtainTarget
bool FastSearchFormat::ObtainTarget(OBConversion* pConv, vector<OBMol>& patternMols, const string& indexname)
{
//Obtains an OBMol from:
// the filename in the -s option or
// the SMARTS string in the -s option or
// by converting the file in the -S or -aS options (deprecated).
// If there is no -s -S or -aS option, information on the index file is displayed.
OBMol patternMol;
patternMol.SetIsPatternStructure();
const char* p = pConv->IsOption("s",OBConversion::GENOPTIONS);
bool OldSOption=false;
//If no -s option, make OBMol from file in -S option or -aS option (both deprecated)
if(!p)
{
p = pConv->IsOption("S",OBConversion::GENOPTIONS);
if(!p)
p = pConv->IsOption("S",OBConversion::INOPTIONS);//for GUI mainly
OldSOption = true;
}
if(p)
{
vector<string> vec;
tokenize(vec, p);
//ignore leading ~ (not relevant to fastsearch)
if(vec[0][0]=='~')
vec[0].erase(0,1);
if(vec.size()>1 && vec[1]=="exact")
pConv->AddOption("e", OBConversion::INOPTIONS);
OBConversion patternConv;
OBFormat* pFormat;
//Interpret as a filename if possible
string& txt =vec [0];
if( txt.empty() ||
txt.find('.')==string::npos ||
!(pFormat = patternConv.FormatFromExt(txt.c_str())) ||
!patternConv.SetInFormat(pFormat) ||
!patternConv.ReadFile(&patternMol, txt) ||
patternMol.NumAtoms()==0)
//if false, have a valid patternMol from a file
{
//is SMARTS/SMILES
//Replace e.g. [#6] in SMARTS by C so that it can be converted as SMILES
//for the fingerprint phase, but allow more generality in the SMARTS phase.
for(;;)
{
string::size_type pos1, pos2;
pos1 = txt.find("[#");
if(pos1==string::npos)
break;
pos2 = txt.find(']');
int atno;
if(pos2!=string::npos && (atno = atoi(txt.substr(pos1+2, pos2-pos1-2).c_str())) && atno>0)
txt.replace(pos1, pos2-pos1+1, etab.GetSymbol(atno));
else
{
obErrorLog.ThrowError(__FUNCTION__,"Ill-formed [#n] atom in SMARTS", obError);
return false;
}
}
bool hasTildeBond;
if( (hasTildeBond = (txt.find('~')!=string::npos)) ) // extra parens to indicate truth value
{
//Find ~ bonds and make versions of query molecule with a single and aromatic bonds
//To avoid having to parse the SMILES here, replace ~ by $ (quadruple bond)
//and then replace this in patternMol. Check first that there are no $ already
//Sadly, isocynanides may have $ bonds.
if(txt.find('$')!=string::npos)
{
obErrorLog.ThrowError(__FUNCTION__,
"Cannot use ~ bonds in patterns with $ (quadruple) bonds.)", obError);
return false;
}
replace(txt.begin(),txt.end(), '~' , '$');
}
//read as standard SMILES
patternConv.SetInFormat("smi");
if(!patternConv.ReadString(&patternMol, vec[0]))
{
obErrorLog.ThrowError(__FUNCTION__,"Cannot read the SMILES string",obError);
return false;
}
if(hasTildeBond)
{
AddPattern(patternMols, patternMol, 0); //recursively add all combinations of tilde bond values
return true;
}
}
else
{
// target(s) are in a file
patternMols.push_back(patternMol);
while(patternConv.Read(&patternMol))
//.........这里部分代码省略.........
示例14: main
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)
{
//.........这里部分代码省略.........
示例15: readFile
bool OBReader::readFile(QString fileName)
{
using namespace OpenBabel;
OBConversion conv;
OBFormat *format = conv.FormatFromExt(fileName.toStdString());
if (!format || !conv.SetInFormat(format))
{
qDebug() << "Unsupported File Format.";
return false;
}
std::ifstream ifs;
ifs.open(fileName.toStdString());
if (!ifs)
{
qDebug() << "Could not open the file.";
return false;
}
OBMol obMol;
if (!conv.Read(&obMol, &ifs))
{
qDebug() << "Error occured while reading the file.";
return false;
}
if (!obMol.Has3D())
{
static bool showMsgBox = true;
if (showMsgBox)
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("OBReader"));
msgBox.setText(tr("No 3D coordinate values present in this file."));
msgBox.setInformativeText(tr("OBReader will generate the rough molecular geometry."));
msgBox.setCheckBox(new QCheckBox(tr("Don’t show this message again.")));
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
showMsgBox = !msgBox.checkBox()->isChecked();
}
if (!buildGeometry(&obMol))
{
qDebug() << "Error in buildGeometry()";
return false;
}
}
if (!toMolecule(&obMol))
{
qDebug() << "Could not convert OBMol to Molecule.";
return false;
}
return true;
}