本文整理汇总了C++中OBMol::GetExactMass方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::GetExactMass方法的具体用法?C++ OBMol::GetExactMass怎么用?C++ OBMol::GetExactMass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::GetExactMass方法的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: WriteReport
bool WriteReport(ostream &ofs,OBMol &mol)
{
char buffer[BUFF_SIZE];
ofs << "FILENAME: " << mol.GetTitle() << endl;
ofs << "MASS: ";
sprintf(buffer, "%5.4f", mol.GetMolWt());
ofs << buffer << endl;
ofs << "EXACT MASS: ";
sprintf(buffer, "%5.7f", mol.GetExactMass());
ofs << buffer << endl;
if (mol.GetTotalCharge() != 0)
{
ofs << "TOTAL CHARGE: ";
sprintf(buffer, "%d", mol.GetTotalCharge());
ofs << buffer << endl;
}
if (mol.GetTotalSpinMultiplicity() != 1)
{
ofs << "TOTAL SPIN: ";
sprintf(buffer, "%d", mol.GetTotalSpinMultiplicity());
ofs << buffer << endl;
}
ofs << "INTERATOMIC DISTANCES" << endl;
WriteDistanceMatrix(ofs, mol);
ofs << endl << endl << "ATOMIC CHARGES" << endl;
WriteCharges(ofs, mol);
ofs << endl << endl << "BOND ANGLES" << endl;
WriteAngles(ofs, mol);
ofs << endl << endl << "TORSION ANGLES" << endl;
WriteTorsions(ofs, mol);
if (mol.IsChiral())
{
ofs << endl << endl << "CHIRAL ATOMS" << endl;
WriteChiral(ofs, mol);
}
if (mol.HasData(obCommentData)) {
ofs << endl << endl << "COMMENTS" << endl;
OBCommentData *cd = (OBCommentData*)mol.GetData(obCommentData);
ofs << cd->GetData() << endl;
}
ofs << endl << endl;
return(true);
}
示例3: main
//.........这里部分代码省略.........
// A third file is created to store information on the memory allocation of data structures
// from the MMFF94 calculation routines. breakdown of memory allocated for each calculation type
char filepath3[1100];
std::ofstream output3;
sprintf(filepath3, "%s/%s_%s_t%d_malloc.mat", cwd, statsfile, ff.c_str(), nthreads);
std::cout << "Writing memory allocation breakdown detail file to: " << filepath3 << std::endl;
output3.open(filepath3, ios::out | ios::app ); // The file is open in append mode
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
output3 << "#METHOD: " << ff << " THREADS: " << nthreads << " DATASET: " << filename.c_str() << std::endl;
output3 << "#ATOMS M_BOND M_ANGLE M_STRBND M_TORSION M_OOP M_VDW M_ELEC C_BOND C_ANGLE C_STRBND C_TORSION C_OOP C_VDW C_ELEC" << std::endl;
double bondCalcTime, angleCalcTime, strbndCalcTime, torsionCalcTime, oopCalcTime, vdwCalcTime, electrostaticCalcTime;
int numPairsVDW, numPairsElectrostatic;
OBMol mol;
double energy;
for (c=1;;c++) {
mol.Clear();
totalTimer.start();
readTimer.start();
if (!conv.Read(&mol, &ifs))
break;
if (mol.Empty())
break;
if (hydrogens)
mol.AddHydrogens();
readTime = readTimer.get();
setupTimer.start();
if (!pFF->Setup(mol)) {
cerr << program_name << ": could not setup force field." << endl;
exit (-1);
}
setupTime = setupTimer.get();
computeTimer.start();
energy = pFF->Energy(false);
computeTime = computeTimer.get();
totalTime = totalTimer.get();
// THREADS ENERGY MOL_MASS NUM_ATOMS NUM_ROTORS NUM_CONF TOT_TIME TIME_READ TIME_SETUP TIME_COMPUTE STEPS #MOL_NAME
output << nthreads << " " << energy << " " << mol.GetExactMass() << " " << mol.NumAtoms()
<< " " << mol.NumRotors() << " " << mol.NumConformers() << " "
<< totalTime << " " << readTime << " " << " " << setupTime << " " << computeTime << " "
<< totalSteps << " #" << mol.GetTitle() // comment added to avoid errors when reading matrix in Octave
<< std::endl;
map<string, double> timings = pFF->getTimings();
map<string, size_t> memalloc = pFF->getAllocatedMemory();
MapKeys mk;
// 1 2 3 4 5 6 7 8 9 10 11 12
// E_BOND E_ANGLE E_STRBND E_TORSION E_OOP E_VDW E_ELEC N_ATOMS PAIRS_VDW PAIRS_ELEC MEM_VDW MEM_ELEC
output2 << timings[mk.TIME_BOND_CALCULATIONS] << " " // 1
<< timings[mk.TIME_ANGLE_CALCULATIONS] << " " // 2
<< timings[mk.TIME_STRBND_CALCULATIONS] << " " // 3
<< timings[mk.TIME_TORSION_CALCULATIONS] << " " // 4
<< timings[mk.TIME_OOP_CALCULATIONS] << " " // 5
<< timings[mk.TIME_VDW_CALCULATIONS] << " " // 6
<< timings[mk.TIME_ELECTROSTATIC_CALCULATIONS] << " " // 7
<< mol.NumAtoms() << " " // 8
<< timings[mk.TOTAL_VDW_CALCULATIONS] << " " // 9
<< timings[mk.TOTAL_ELECTROSTATIC_CALCULATIONS] << " " // 10
<< memalloc[mk.MEM_VDW_CALCULATIONS] << " " // 11
<< memalloc[mk.MEM_ELECTROSTATIC_CALCULATIONS] << std::endl; // 12
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// ATOMS M_BOND M_ANGLE M_STRBND M_TORSION M_OOP M_VDW M_ELEC C_BOND C_ANGLE C_STRBND C_TORSION C_OOP C_VDW C_ELEC
output3 << mol.NumAtoms() << " " // 1
<< memalloc[mk.MEM_BOND_CALCULATIONS] << " " // 2
<< memalloc[mk.MEM_ANGLE_CALCULATIONS] << " " // 3
<< memalloc[mk.MEM_STRBND_CALCULATIONS] << " " // 4
<< memalloc[mk.MEM_TORSION_CALCULATIONS] << " " // 5
<< memalloc[mk.MEM_OOP_CALCULATIONS] << " " // 6
<< memalloc[mk.MEM_VDW_CALCULATIONS] << " " // 7
<< memalloc[mk.MEM_ELECTROSTATIC_CALCULATIONS] << " " // 8
<< timings[mk.TOTAL_BOND_CALCULATIONS] << " " // 9
<< timings[mk.TOTAL_ANGLE_CALCULATIONS] << " " // 10
<< timings[mk.TOTAL_STRBND_CALCULATIONS] << " " // 11
<< timings[mk.TOTAL_TORSION_CALCULATIONS] << " " // 12
<< timings[mk.TOTAL_OOP_CALCULATIONS] << " " // 13
<< timings[mk.TOTAL_VDW_CALCULATIONS] << " " // 14
<< timings[mk.TOTAL_ELECTROSTATIC_CALCULATIONS] << " " // 15
<< std::endl;
if (!isfinite(energy)) {
cerr << " Title: " << mol.GetTitle() << endl;
FOR_ATOMS_OF_MOL(atom, mol) {
cerr << " x: " << atom->x() << " y: " << atom->y() << " z: " << atom->z() << endl;
}
}
} // end for loop
示例4: 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
//.........这里部分代码省略.........
示例5: 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);
}
}
示例6: 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;
//.........这里部分代码省略.........