本文整理汇总了C++中OBMol::GetMolWt方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::GetMolWt方法的具体用法?C++ OBMol::GetMolWt怎么用?C++ OBMol::GetMolWt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::GetMolWt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: generateCovarMatrixFromMolecule
void generateCovarMatrixFromMolecule(vector<double> &matrix, OBMol &molecule) {
double uX = 0, uY = 0, uZ = 0, *moleculeCoords = molecule.GetCoordinates();
for (unsigned int i=0; i < 3 * molecule.NumAtoms(); i+=3) {
uX += moleculeCoords[i];
uY += moleculeCoords[i+1];
uZ += moleculeCoords[i+2];
}
uX /= molecule.NumAtoms();
uY /= molecule.NumAtoms();
uZ /= molecule.NumAtoms();
double cXX = 0, cYY = 0, cZZ = 0, cXY = 0, cXZ = 0, cYZ = 0;
for (unsigned int i=0; i < 3 * molecule.NumAtoms(); i+=3) {
double atomWeight = molecule.GetAtom(i/3 + 1)->GetAtomicMass(); // getAtoms is 1-based instead of 0-based
cXX += pow(moleculeCoords[i] - uX, 2) * atomWeight;
cYY += pow(moleculeCoords[i+1] - uY, 2) * atomWeight;
cZZ += pow(moleculeCoords[i+2] - uZ, 2) * atomWeight;
cXY += (moleculeCoords[i] - uX) * (moleculeCoords[i+1] - uY) * atomWeight;
cXZ += (moleculeCoords[i] - uX) * (moleculeCoords[i+2] - uZ) * atomWeight;
cYZ += (moleculeCoords[i+1] - uY) * (moleculeCoords[i+2] - uZ) * atomWeight;
}
matrix.clear();
matrix.resize(9);
matrix[0] = cXX;
matrix[1] = matrix[3] = cXY;
matrix[2] = matrix[6] = cXZ;
matrix[4] = cYY;
matrix[5] = matrix[7] = cYZ;
matrix[8] = cZZ;
for (unsigned int i=0; i < matrix.size(); i++) matrix[i] /= molecule.GetMolWt();
}
示例3: Predict
double Predict(OBBase* pOb)
{
OBMol* pmol = dynamic_cast<OBMol*> (pOb);
if(!pmol)
return 0;
return pmol->GetMolWt();
}
示例4: runConformerComparisons
void runConformerComparisons(OBMol &moleculeA, OBMol &moleculeB, bool verbose=false) { // A is the target and B is the reference
vector< vector<double> > coordAs, coordBs, comAs, comBs, eVectAs, eVectBs;
vector<double> VDWsA, VDWsB, massesA, massesB, currentPCACoordA, currentSDCoordA, bestCoordsA;
vector< vector<double> > atomMatchScoringTable;
double molecularWeightA = moleculeA.GetMolWt(), molecularWeightB = moleculeB.GetMolWt();
double bestVolumeOverlap = -(numeric_limits<double>::max)();
int bestJ = -1, bestI = -1, stepCount = 0;
generateVDWRadiusListFromMolecule(VDWsA, moleculeA);
generateVDWRadiusListFromMolecule(VDWsB, moleculeB);
generateAtomicMassesListFromMolecule(massesA, moleculeA);
generateAtomicMassesListFromMolecule(massesB, moleculeB);
generateCoordsMatrixFromMoleculeConformers(coordAs, moleculeA);
generateCoordsMatrixFromMoleculeConformers(coordBs, moleculeB);
getMoleculeConformerCenterCoords(comAs, moleculeA);
getMoleculeConformerCenterCoords(comBs, moleculeB);
generateAtomMatchScoringTableFromTwoMolecules(atomMatchScoringTable, moleculeA, moleculeB);
eVectAs.resize( moleculeA.NumConformers() ), eVectBs.resize( moleculeB.NumConformers() );
for (unsigned int k=0; k < moleculeA.NumConformers(); k++) getPCAEigenMatrix(eVectAs[k], coordAs[k], massesA, molecularWeightA);
for (unsigned int k=0; k < moleculeB.NumConformers(); k++) getPCAEigenMatrix(eVectBs[k], coordBs[k], massesB, molecularWeightB);
cout << "Finished setting up data; running search...\n";
for (unsigned int j=0; j < moleculeB.NumConformers(); j++) {
for (unsigned int i=0; i < moleculeA.NumConformers(); i++) {
PCAEngine(currentPCACoordA, coordAs[i], coordBs[j], eVectAs[i], eVectBs[j], comAs[i], comBs[j], VDWsA, VDWsB, atomMatchScoringTable);
double currentVolumeOverlap = steepestDescentEngine(currentSDCoordA, currentPCACoordA, coordBs[j], VDWsA, VDWsB, comAs[i], atomMatchScoringTable, 1.0, 10.0 * M_PI / 180.0);
if (currentVolumeOverlap > bestVolumeOverlap) {
bestVolumeOverlap = currentVolumeOverlap;
bestCoordsA = currentSDCoordA;
bestI = i;
bestJ = j;
}
RANKS_AND_COORDS.push_back(RanksAndCoords(currentVolumeOverlap, i, j, currentSDCoordA));
cout << "ROUND " << ++stepCount << " A#" << i << " and B#" << j << " = " << currentVolumeOverlap << endl;
}
}
cout << "\nThe best overlap is between conformer A#" << bestI << " and B#" << bestJ << ", which, after PCA followed by Steepest Descent, produces a volume overlap of " << bestVolumeOverlap << endl;
//saveCoordsMatrixToMolecule(moleculeA, bestCoordsA);
addConformerToMolecule(moleculeA, bestCoordsA);
moleculeA.SetConformer(moleculeA.NumConformers() - 1);
moleculeB.SetConformer(bestJ);
MOLECULE_CONFORMER = bestJ;
}
示例5: tmpStr
/*****************************************************************
* This function Copyright (c) 2004
* by Bayer Business Services GmbH
*****************************************************************/
extern "C" double
ob_molweight (char *smiles)
{
OBMol mol;
OBConversion conv;
string tmpStr (smiles);
istringstream molstream (tmpStr);
double molweight = 0.0;
conv.SetInAndOutFormats ("SMI", "SMI");
conv.Read (&mol, &molstream);
molweight = mol.GetMolWt ();
return (molweight);
}
示例6: 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);
}
示例7: Predict
virtual double Predict(OBBase *pOb, string *param = NULL) {
OBMol *pmol = dynamic_cast<OBMol *>(pOb);
if (!pmol)
return 0;
return pmol->GetMolWt();
}
示例8: 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
//.........这里部分代码省略.........
示例9: 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);
}
}
示例10: 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;
//.........这里部分代码省略.........