本文整理汇总了C++中OBMol::GetFormula方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::GetFormula方法的具体用法?C++ OBMol::GetFormula怎么用?C++ OBMol::GetFormula使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::GetFormula方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateFormulaReference
void GenerateFormulaReference()
{
std::ifstream ifs;
if (!SafeOpen(ifs, smilestypes_file.c_str()))
return;
std::ofstream ofs;
if (!SafeOpen(ofs, results_file.c_str()))
return;
OBMol mol;
OBConversion conv(&ifs, &cout);
if(! conv.SetInAndOutFormats("SMI","SMI"))
{
cerr << "SMILES format is not loaded" << endl;
return;
}
for (;ifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
//write out formula, molecular weight and exact mass
ofs << mol.GetFormula() << " " << mol.GetMolWt() << " "
<< mol.GetExactMass() << endl;
}
cerr << " Molecular formula results written successfully" << endl;
return;
}
示例2: tmpStr
extern "C" char *
ob_hillformula (char *smiles)
{
string tmpStr (smiles);
istringstream molstream (tmpStr);
string molfmla;
OBMol mol;
OBConversion conv;
char *tmpFormula;
conv.SetInAndOutFormats ("SMI", "SMI");
conv.Read (&mol, &molstream);
molfmla = mol.GetFormula ();
tmpFormula = strdup (molfmla.c_str ());
return (tmpFormula);
}
示例3: main
int main(int argc,char *argv[])
{
// turn off slow sync with C-style output (we don't use it anyway).
std::ios::sync_with_stdio(false);
if (argc != 1)
{
if (strncmp(argv[1], "-g", 2))
{
cout << "Usage: formula" << endl;
cout << " Tests Open Babel molecular formula, weight, and exact mass." << endl;
return 0;
}
else
{
GenerateFormulaReference();
return 0;
}
}
cout << "# Testing molecular formulas..." << endl;
std::ifstream mifs;
if (!SafeOpen(mifs, smilestypes_file.c_str()))
{
cout << "Bail out! Cannot read file " << smilestypes_file << endl;
return -1; // test failed
}
std::ifstream rifs;
if (!SafeOpen(rifs, results_file.c_str()))
{
cout << "Bail out! Cannot read file " << results_file << endl;
return -1; // test failed
}
char buffer[BUFF_SIZE];
vector<string> vs;
OBMol mol;
OBConversion conv(&mifs, &cout);
unsigned int currentTest = 0;
// double mass;
if(! conv.SetInAndOutFormats("SMI","SMI"))
{
cout << "Bail out! SMILES format is not loaded" << endl;
return -1;
}
for (;mifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
if (!rifs.getline(buffer,BUFF_SIZE))
{
cout << "Bail out! error reading reference data" << endl;
return -1; // test failed
}
tokenize(vs,buffer);
if (vs.size() != 3)
{
cout << "Bail out! Reference data has incorrect format" << endl;
return -1; // test failed
}
if (vs[0] != mol.GetFormula())
{
cout << "not ok " << ++currentTest << " # molecular formula incorrect"
<< " for molecule " << mol.GetTitle() << "\n";
}
else
cout << "ok " << ++currentTest << " # molecular formula\n";
if ( fabs(atof(vs[1].c_str()) - mol.GetMolWt() ) > 1.0e-3)
{
cout << "not ok " << ++currentTest << " # molecular weight incorrect"
<< " for molecule " << mol.GetTitle() << "\n";
cout << "# Expected " << atof(vs[1].c_str()) << " found " <<
mol.GetMolWt() << "\n";
}
else
cout << "ok " << ++currentTest << " # molecular weight\n";
if ( fabs(atof(vs[2].c_str()) - mol.GetExactMass() ) > 1.0e-3)
{
cout << "not ok " << ++currentTest << " # exact mass incorrect"
<< " for molecule " << mol.GetTitle() << "\n";
cout << "# Expected " << atof(vs[2].c_str()) << " found " <<
mol.GetExactMass() << "\n";
}
else
cout << "ok " << ++currentTest << " # molecular exact mass\n";
// now after adding explict hydrogens -- should be identical
// since we'll add hydrogens that were implicit before
//.........这里部分代码省略.........
示例4: formula_test
void formula_test()
{
#ifdef TESTDATADIR
string testdatadir = TESTDATADIR;
string results_file = testdatadir + "formularesults.txt";
string smilestypes_file = testdatadir + "attype.00.smi";
#else
string results_file = "files/formularesults.txt";
string smilestypes_file = "files/attype.00.smi";
#endif
cout << "# Testing molecular formulas..." << endl;
std::ifstream mifs;
BOOST_REQUIRE_MESSAGE( SafeOpen(mifs, smilestypes_file.c_str()), "Bail out! Cannot read file " );
std::ifstream rifs;
BOOST_REQUIRE_MESSAGE( SafeOpen(rifs, results_file.c_str()), "Bail out! Cannot read file " );
char buffer[BUFF_SIZE];
char message[BUFF_SIZE];
vector<string> vs;
OBMol mol;
OBConversion conv(&mifs, &cout);
unsigned int currentTest = 0;
// double mass;
BOOST_REQUIRE_MESSAGE( conv.SetInAndOutFormats("SMI","SMI"), "Bail out! SMILES format is not loaded" );
for (;mifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
BOOST_REQUIRE_MESSAGE( rifs.getline(buffer,BUFF_SIZE), "Bail out! error reading reference data" );
tokenize(vs,buffer);
BOOST_REQUIRE_MESSAGE( vs.size() == 3, "Bail out! Reference data has incorrect format" );
currentTest++;
snprintf(message, BUFF_SIZE, "not ok %d # molecular formula incorrect for molecule %s"
" # Expected %s, found %s", currentTest, mol.GetTitle(),
vs[0].c_str(), mol.GetFormula().c_str());
BOOST_CHECK_MESSAGE(vs[0] == mol.GetFormula(), message );
currentTest++;
snprintf(message, BUFF_SIZE, "not ok %d # molecular weight incorrect for molecule %s"
" # Expected %f, found %f ", currentTest, mol.GetTitle(),
atof(vs[1].c_str()), mol.GetMolWt());
BOOST_CHECK_MESSAGE( fabs(atof(vs[1].c_str()) - mol.GetMolWt() ) < 1.0e-3, message );
currentTest++;
snprintf(message, BUFF_SIZE, "not ok %d # exact mass incorrect for molecule %s"
" # Expected %f, found %f ", currentTest, mol.GetTitle(),
atof(vs[2].c_str()), mol.GetExactMass());
BOOST_CHECK_MESSAGE( fabs(atof(vs[2].c_str()) - mol.GetExactMass() ) < 1.0e-3, message );
// now after adding explict hydrogens -- should be identical
// since we'll add hydrogens that were implicit before
// PR#1485580
BOOST_CHECK( mol.AddHydrogens() );
currentTest++;
snprintf(message, BUFF_SIZE, "not ok %d # molecular formula incorrect for "
"hydrogen-added molecule %s", currentTest, mol.GetTitle());
BOOST_CHECK_MESSAGE(vs[0] == mol.GetFormula(), message);
currentTest++;
snprintf(message, BUFF_SIZE, "not ok %d # molecular weight incorrect for hydrogen-added "
"molecule %s # Expected %f, found %f ", currentTest, mol.GetTitle(),
atof(vs[1].c_str()), mol.GetMolWt());
BOOST_CHECK_MESSAGE( fabs(atof(vs[1].c_str()) - mol.GetMolWt() ) < 1.0e-3, message);
currentTest++;
snprintf(message, BUFF_SIZE, "not ok %d # exact mass incorrect for hydrogen-added "
"molecule %s # Expected %f, found %f ", currentTest, mol.GetTitle(),
atof(vs[2].c_str()), mol.GetExactMass());
BOOST_CHECK_MESSAGE( fabs(atof(vs[2].c_str()) - mol.GetExactMass() ) < 1.0e-3, message);
}
}
示例5: 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;
//.........这里部分代码省略.........
示例6: mol
//.........这里部分代码省略.........
doubleBondMol.BeginModify();
a1 = doubleBondMol.NewAtom();
a1->SetVector(0.0, 0.0, 0.0);
a1->SetAtomicNum(6);
a2 = doubleBondMol.NewAtom();
a2->SetVector(1.6, 0.0, 0.0);
a2->SetAtomicNum(6);
b = doubleBondMol.NewBond();
b->SetBegin(a1);
b->SetEnd(a2);
a1->AddBond(b);
a2->AddBond(b);
doubleBondMol.EndModify();
cout << "ok 9" << endl;
// test AddHydrogens
OBMol testMolH;
testMolH.BeginModify();
OBAtom *testAtom = testMolH.NewAtom();
testAtom->SetVector(0.5f, 0.5f, 0.5f);
testAtom->SetAtomicNum(6);
testAtom->SetImplicitHCount(4);
testMolH.EndModify();
testMolH.AddHydrogens();
if (testMolH.NumAtoms() == 5) {
cout << "ok 10" << endl;
} else {
cout << "not ok 10" << endl;
}
// test AddHydrogens (pr #1665519)
OBMol testMolH2;
OBAtom *testAtom2 = testMolH2.NewAtom();
testAtom2->SetVector(0.5f, 0.5f, 0.5f);
testAtom2->SetAtomicNum(6);
testAtom2->SetImplicitHCount(4);
testMolH2.AddHydrogens();
if (testMolH2.NumAtoms() == 5) {
cout << "ok 11" << endl;
} else {
cout << "not ok 11 # hydrogen additions" << endl;
}
// Attempt to write an empty InChI (PR#2864334)
pFormat = conv.FindFormat("InChI");
if ( pFormat != NULL && conv.SetOutFormat(pFormat))
{
if (conv.Write(&emptyMol))
cout << "ok 12" << endl;
else
cout << "not ok 12 # failed empty InChI" << endl;
}
OBMol testMolFormula;
string formula("C6");
testMolFormula.SetFormula(formula);
if ( testMolFormula.GetFormula() == formula ) {
cout << "ok 13" << endl;
} else {
cout << "not ok 13 # SetFormula "<< endl;
}
// Reset the formula to test for a double delete error
testMolFormula.SetFormula(formula);
// Test molecular formulas with large atomic numbers
OBMol testLgAtNo;
testLgAtNo.BeginModify();
OBAtom *lgAtom = testLgAtNo.NewAtom();
lgAtom->SetAtomicNum(118);
// Undefined atomic numbers should be ignored with an obWarning instead of segfault
lgAtom = testLgAtNo.NewAtom();
lgAtom->SetAtomicNum(200);
lgAtom = testLgAtNo.NewAtom();
lgAtom->SetAtomicNum(1);
lgAtom->SetIsotope(2);
testLgAtNo.EndModify();
if ( testLgAtNo.GetFormula() == "DOg" ) {
cout << "ok 14" << endl;
} else {
cout << "not ok 14" << endl;
}
double dihedral = CalcTorsionAngle(vector3(-1., -1., 0.),
vector3(-1., 0., 0.),
vector3( 1., 0., 0.),
vector3( 1., 1., 0.));
double dihedral_error = fabs(dihedral) - 180.0;
if (fabs(dihedral_error) < 0.001) {
std::cout << "ok 15 " << dihedral_error << std::endl;
} else {
std::cout << "not ok 15 # CalcTorsionAngle " << dihedral << "!= 180.0" << std::endl;
}
cout << "1..15\n"; // total number of tests for Perl's "prove" tool
return(0);
}