Molecule * OpenbabelWrapper::openFile(const QString &fileName, const QString &fileType, const QString &fileOptions) { // Check that the file can be read from disk if (!canOpen(fileName, QFile::ReadOnly | QFile::Text)) return 0; // Construct the OpenBabel objects, set the file type OBConversion conv; OBFormat *inFormat; if (!fileType.isEmpty() && !conv.SetInFormat(fileType.toAscii().data())) // Input format not supported return 0; else { inFormat = conv.FormatFromExt(fileName.toAscii().data()); if (!conv.SetInFormat(inFormat)) // Input format not supported return 0; } // set any options if (!fileOptions.isEmpty()) { foreach(const QString &option, fileOptions.split('\n', QString::SkipEmptyParts)) { conv.AddOption(option.toAscii().data(), OBConversion::INOPTIONS); } }
extern "C" char * ob_strip_salts (char *smiles, int neutralize_residue) { OBAtom atom; OBMol mol, largestFragment; OBConversion conv; string tmpStr (smiles); string outstring; istringstream molstream1 (tmpStr); ostringstream molstream2; vector<OBMol> fragments; vector <OBMol>::const_iterator i; char *tmpMolfile; int max = 0; conv.SetInAndOutFormats ("SMI", "SMI"); conv.Read (&mol, &molstream1); fragments = mol.Separate(); for( i = fragments.begin(); i != fragments.end(); i++ ) { if (i->NumAtoms() > max) { max=i->NumAtoms(); largestFragment = *i; } } if(neutralize_residue != 0) { largestFragment.ConvertDativeBonds(); FOR_ATOMS_OF_MOL(atom, largestFragment) { atom->SetFormalCharge(0); }
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(); }
void testIsomorphism1() { OBMol mol; OBConversion conv; conv.SetInFormat("smi"); conv.ReadString(&mol, "CC1CCC(C)CC1"); OBQuery *query = CompileMoleculeQuery(&mol); OBIsomorphismMapper *mapper = OBIsomorphismMapper::GetInstance(query); OBIsomorphismMapper::Mappings maps; mapper->MapAll(&mol, maps); OB_ASSERT( maps.size() == 4 ); delete query; delete mapper; query = CompileSmilesQuery("C1(C)CCC(C)CC1"); mapper = OBIsomorphismMapper::GetInstance(query); OBIsomorphismMapper::Mapping map; mapper->MapFirst(&mol, map); OB_ASSERT( map.size() == 8 ); mapper->MapUnique(&mol, maps); OB_ASSERT( maps.size() == 1 ); mapper->MapAll(&mol, maps); OB_ASSERT( maps.size() == 4 ); delete query; delete mapper; }
void LinMorphExtension::loadFile(QString file) { qDebug("LinMorphExtension::loadFile()"); if (file.isEmpty()) return; if (!m_secondMolecule) m_secondMolecule = new Molecule; OBConversion conv; OBFormat *inFormat = OBConversion::FormatFromExt(( file.toAscii() ).data() ); if ( !inFormat || !conv.SetInFormat( inFormat ) ) { QMessageBox::warning( NULL, tr( "Avogadro" ), tr( "Cannot read file format of file %1." ) .arg( file ) ); return; } if (!conv.ReadFile(m_secondMolecule, file.toStdString())) { QMessageBox::warning( NULL, tr( "Avogadro" ), tr( "Read mol file %1 failed." ) .arg( file ) ); return; } qDebug("LinMorphExtension::loadFile complete"); computeConformers(m_secondMolecule); m_linMorphDialog->setFrame(1); m_timeLine->setFrameRange(1, m_frameCount); setDuration(m_linMorphDialog->fps()); }
void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, int& arg, int argc, char *argv[]) { while(p && *p) //can have multiple single char options { char ch[2]="?"; *ch = *p++; const char* txt=NULL; //Get the option text if needed int nParams = Conv.GetOptionParams(ch, typ); if(nParams) { if(*p) { txt = p; //use text immediately following the option letter p=NULL; //no more single char options } else if(arg<argc-1) { txt = argv[++arg]; //use text from next arg if(*txt=='-') { //...unless it is another option cerr << "Option -" << ch << " takes a parameter" << endl; exit(0); } } } Conv.AddOption(ch, typ, txt); } }
// 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; }
int main() { OBAtom a, b, c; a.SetAtomicNum(8); b.SetAtomicNum(6); c.SetAtomicNum(8); OBMol mol; mol.AddAtom(a); mol.AddAtom(b); mol.AddAtom(c); mol.AddBond(1,2,2); mol.AddBond(2,3,2); OBConversion conv; conv.SetOutFormat("SMI"); cout << conv.WriteString(&mol,1) << endl; OBSmartsPattern sp; sp.Init ("C~*"); sp.Match (mol,false); cout << sp.NumMatches() << endl; cout << sp.GetUMapList().size() << endl; return EXIT_SUCCESS; }
bool OpExtraOut::Do(OBBase* pOb, const char* OptionText, OpMap* pmap, OBConversion* pConv) { /* OptionText contains an output filename with a format extension. Make an OBConversion object with this as output destination. Make a copy the current OBConversion and replace the output format by an instance of ExtraFormat. This then does all the subsequent work. */ if(!pConv || !OptionText || *OptionText=='\0') return true; //silent no-op. false would prevent the main output if(pConv->IsFirstInput()) { OBConversion* pExtraConv = new OBConversion(*pConv); //copy ensures OBConversion::Index>-1 std::ofstream* ofs; if( (ofs = new std::ofstream(OptionText)) ) // extra parens to indicate truth value pExtraConv->SetOutStream(ofs); if(!ofs || !pExtraConv->SetOutFormat(OBConversion::FormatFromExt(OptionText))) { obErrorLog.ThrowError(__FUNCTION__, "Error setting up extra output file", obError); return true; } OBConversion* pOrigConv = new OBConversion(*pConv); //Make an instance of ExtraFormat and divert the output to it. It will delete itself. pConv->SetOutFormat(new ExtraFormat(pOrigConv, pExtraConv)); } return true; }
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; }
void testPdbOccupancies() { // See https://github.com/openbabel/openbabel/pull/1558 OBConversion conv; OBMol mol; conv.SetInFormat("cif"); conv.SetOutFormat("pdb"); conv.ReadFile(&mol, GetFilename("test08.cif")); string pdb = conv.WriteString(&mol); conv.AddOption("o", OBConversion::OUTOPTIONS); pdb = conv.WriteString(&mol); OB_ASSERT(pdb.find("HETATM 1 NA UNL 1 0.325 0.000 4.425 0.36") != string::npos); OB_ASSERT(pdb.find("HETATM 17 O UNL 8 1.954 8.956 3.035 1.00") != string::npos); OBMol mol_pdb; conv.SetInFormat("pdb"); conv.ReadFile(&mol_pdb, GetFilename("test09.pdb")); pdb = conv.WriteString(&mol_pdb); OB_ASSERT(pdb.find("HETATM 1 NA UNL 1 0.325 0.000 4.425 0.36") != string::npos); OB_ASSERT(pdb.find("HETATM 2 NA UNL 1 0.002 8.956 1.393 0.10") != string::npos); OB_ASSERT(pdb.find("HETATM 17 O UNL 8 1.954 8.956 3.035 1.00") != string::npos); }
extern "C" char * ob_add_hydrogens (char *smiles, int polaronly, int correct4PH) { OBMol mol; OBConversion conv; string tmpStr (smiles); string outstring; istringstream molstream1 (tmpStr); ostringstream molstream2; char *tmpMolfile; conv.SetInAndOutFormats ("SMI", "SMI"); conv.Read (&mol, &molstream1); mol.AddHydrogens (polaronly != 0, correct4PH != 0); conv.Write (&mol, &molstream2); outstring = molstream2.str (); // remove the trailling $$$$\n from the SDFile if (outstring.find ("$$$$\n", 0) != string::npos) { outstring = outstring.substr (0, outstring.length () - 5); } else if (outstring.find ("$$$$\r\n", 0) != string::npos) { outstring = outstring.substr (0, outstring.length () - 6); } tmpMolfile = strdup (outstring.c_str ()); return (tmpMolfile); }
void testTetrahedralStereo1() { cout << "testTetrahedralStereo1()" << endl; // read a smiles string OBMol mol; OBConversion conv; OB_REQUIRE( conv.SetInFormat("smi") ); cout << "smiles: C[C@H](O)N" << endl; OB_REQUIRE( conv.ReadString(&mol, "C[C@H](O)N") ); // get the stereo data OB_REQUIRE( mol.HasData(OBGenericDataType::StereoData) ); std::vector<OBGenericData *> stereoData = mol.GetAllData(OBGenericDataType::StereoData); OB_REQUIRE( stereoData.size() == 1 ); // convert to tetrahedral data OB_REQUIRE( ((OBStereoBase*)stereoData[0])->GetType() == OBStereo::Tetrahedral ); OBTetrahedralStereo *ts = dynamic_cast<OBTetrahedralStereo*>(stereoData[0]); OB_REQUIRE( ts ); // print the configuration cout << *ts << endl; // construct a valid configuration here // // C[C@H](O)N // 0 1 2 3 4 <- ids // OBTetrahedralStereo::Config cfg(1, 0, OBStereo::MakeRefs(4, 3, 2), OBStereo::Clockwise); // compare stereochemistry OB_REQUIRE( ts->GetConfig() == cfg ); cout << endl; }
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); }
// Reading an InChI and then adding hydrogens messed up the structure void test_Issue134_InChI_addH() { OBConversion conv; conv.SetInFormat("inchi"); OBMol mol; conv.ReadString(&mol, "InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m0/s1"); OB_ASSERT(!mol.HasData(OBGenericDataType::VirtualBondData)); mol.AddHydrogens(); conv.SetOutFormat("smi"); std::string res = conv.WriteString(&mol, true); OB_COMPARE(res, "C[C@@H](N)O"); }
void testAutomorphismMask() { // read file: 3 6-rings // // /\ /\ /\ // | | | | // \/ \/ \/ // cout << "testAutomorphismMask" << endl; OBMol mol; OBConversion conv; conv.SetInFormat("cml"); std::ifstream ifs(OBTestUtil::GetFilename("isomorphism1.cml").c_str()); OB_REQUIRE( ifs ); conv.Read(&mol, &ifs); OBIsomorphismMapper::Mappings maps; // First of all, how many automorphisms are there without any mask? // This takes about 20 seconds, so you may want to comment this out while debugging FindAutomorphisms(&mol, maps); cout << maps.size() << endl; OB_ASSERT( maps.size() == 4 ); // Now, let's remove the bridge (atomId 6) of the central ring. // // /\ /\ /\ // | | | | // \/ \/ // both rings can be flipped around exocyclic bond, the whole molecule can be mirrored // horizontally, this results in 2 x 2 x 2 = 8 automorphisms OBBitVec mask; mask.SetRangeOn(1, mol.NumAtoms()); mask.SetBitOff(6+1); FindAutomorphisms(&mol, maps, mask); cout << maps.size() << endl; for (unsigned int i = 0; i < maps.size(); ++i) { OBIsomorphismMapper::Mapping::const_iterator j; for (j = maps[i].begin(); j != maps[i].end(); ++j) cout << j->second << " "; cout << endl; } OB_ASSERT( maps.size() == 8 ); // Verify that atom Id 6 does not occur anywhere in the mappings OBIsomorphismMapper::Mappings::const_iterator a; OBIsomorphismMapper::Mapping::const_iterator b; for (a = maps.begin(); a != maps.end(); ++a) for (b = a->begin(); b!= a->end(); ++b) { OB_ASSERT( b->first != 6 ); OB_ASSERT( b->second != 6 ); } }
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); }
void testCIFMolecules() { // See https://github.com/openbabel/openbabel/pull/1558 OBConversion conv; OBMol mol; conv.SetInFormat("cif"); conv.SetOutFormat("smi"); // check for disconnected fragments conv.ReadFile(&mol, GetFilename("1519159.cif")); string smi = conv.WriteString(&mol); // never, never disconnected fragments from a molecule OB_ASSERT(smi.find(".") == string::npos); }
void testAutomorphismPreMapping() { cout << "testAutomorphismPreMapping" << endl; OBMol mol; OBConversion conv; conv.SetInFormat("smi"); conv.ReadString(&mol, "c1(C)c(C)c(C)c(C)c(C)c1"); Automorphisms aut; FindAutomorphisms((OBMol*)&mol, aut); cout << aut.size() << endl; OB_ASSERT( aut.size() == 2 ); }
void testIsomorphismMask() { // read file: 3 6-rings // // /\ /\ /\ // | | | | // \/ \/ \/ // OBMol mol; OBConversion conv; conv.SetInFormat("cml"); std::ifstream ifs(OBTestUtil::GetFilename("isomorphism1.cml").c_str()); OB_REQUIRE( ifs ); conv.Read(&mol, &ifs); OBQuery *query = CompileSmilesQuery("C1CCCCC1"); OBIsomorphismMapper *mapper = OBIsomorphismMapper::GetInstance(query); // no mask OBIsomorphismMapper::Mappings maps; mapper->MapUnique(&mol, maps); cout << maps.size() << endl; OB_ASSERT( maps.size() == 3 ); // mask first ring OBBitVec mask; for (int i = 0; i < 6; ++i) mask.SetBitOn(i+1); mapper->MapUnique(&mol, maps, mask); cout << maps.size() << endl; OB_ASSERT( maps.size() == 1 ); // mask second ring also for (int i = 6; i < 10; ++i) mask.SetBitOn(i+1); mapper->MapUnique(&mol, maps, mask); cout << maps.size() << endl; OB_ASSERT( maps.size() == 2 ); // just mask last ring (atomIds 7-8, 10-13) mask.Clear(); for (int i = 10; i < 14; ++i) mask.SetBitOn(i+1); mask.SetBitOn(7 + 1); mask.SetBitOn(8 + 1); mapper->MapUnique(&mol, maps, mask); cout << maps.size() << endl; OB_ASSERT( maps.size() == 1 ); // Should be same result as masking just the first ring delete query; delete mapper; }
extern "C" unsigned int ob_is_nostruct (char *molfile) { OBMol mol; OBConversion conv; string tmpStr (molfile); istringstream molstream (tmpStr); conv.SetInAndOutFormats ("MDL", "MDL"); conv.Read (&mol, &molstream); return (mol.Empty ())? 1 : 0; }
int main(int argc, char **argv) { if (argc < 2) { std::cout << "Usage: " << argv[0] << " <filename>" << std::endl; return 1; } // Read the file shared_ptr<OBMol> mol = GetMol(argv[1]); // Create the OBConformerSearch object OBConformerSearch cs; // Setup std::cout << "Setting up conformer searching..." << std::endl << " conformers: 30" << std::endl << " children: 5" << std::endl << " mutability: 5" << std::endl << " convergence: 25" << std::endl; cs.Setup(*mol.get(), 30, // numConformers 5, // numChildren 5, // mutability 25); // convergence // Perform searching cs.Search(); // Print the rotor keys RotorKeys keys = cs.GetRotorKeys(); for (RotorKeys::iterator key = keys.begin(); key != keys.end(); ++key) { for (unsigned int i = 1; i < key->size(); ++i) std::cout << key->at(i) << " "; std::cout << std::endl; } // Get the conformers cs.GetConformers(*mol.get()); std::cout << mol->NumConformers() << std::endl; OBConversion conv; conv.SetOutFormat("sdf"); for (unsigned int c = 0; c < mol->NumConformers(); ++c) { mol->SetConformer(c); conv.Write(mol.get(), &std::cerr); } }
void CheckValidDipeptide(OBConversion &conv, const string &test, unsigned int testCount) { OBMol mol; OBResidue *res; ostringstream os; mol.Clear(); conv.ReadString(&mol, test); chainsparser.PerceiveChains(mol); if (mol.NumResidues() != 2) { os << "not ok " << testCount << " # expected 2 residues, but found " << mol.NumResidues() << '\n'; os << "# "; FOR_RESIDUES_OF_MOL(res, mol) os << res->GetName() << " "; os << endl; BOOST_CHECK_MESSAGE( 0, os.str().c_str() ); } else { res = mol.GetResidue(0); BOOST_CHECK_MESSAGE( res, "Get first AA from dipeptide" ); res = mol.GetResidue(1); BOOST_CHECK_MESSAGE( res, "Get second AA from dipeptide" ); } }
// Delete hydrogens should not remove charged or isotopic hydrogens or [H][H] or [Cu][H][Cu] // or hydrogens with assigned atom classes void test_Issue178_DeleteHydrogens() { OBConversion conv; conv.SetInFormat("smi"); OBMol mol; // Test DeleteHydrogens() and DeleteNonPolarHydrogens() static const char *smi[] = { "C[H]", "[H][H]", "C[1H]", "C[H]C", "C[H+]" }; int numHs[] = { 0, 2, 1, 1, 1 }; for (int i = 0; i < 5; ++i) { for (int j = 0; j < 2; ++j) { conv.ReadString(&mol, smi[i]); if (j == 0) mol.DeleteHydrogens(); else mol.DeleteNonPolarHydrogens(); int myNumHs = 0; FOR_ATOMS_OF_MOL(atom, mol) if (atom->IsHydrogen()) myNumHs++; OB_COMPARE(myNumHs, numHs[i]); } } // Test DeletePolarHydrogens() static const char *smiB[] = { "N[H]", "[H][H]", "N[1H]", "N[H]C", "N[H+]" }; int numHsB[] = { 0, 2, 1, 1, 1 }; for (int i = 0; i < 5; ++i) { conv.ReadString(&mol, smiB[i]); mol.DeletePolarHydrogens(); int myNumHs = 0; FOR_ATOMS_OF_MOL(atom, mol) if (atom->IsHydrogen()) myNumHs++; OB_COMPARE(myNumHs, numHsB[i]); } // Test atom class // Currently, the SMILES parser does not retain atom classes for hydrogens on reading so... conv.ReadString(&mol, "C[H]"); OBAtomClassData *ac = new OBAtomClassData; ac->Add(2, 99); // Assign the hydrogen (atom 2) a class of 99 mol.SetData(ac); mol.DeleteHydrogens(); int myNumHs = 0; FOR_ATOMS_OF_MOL(atom, mol) if (atom->IsHydrogen()) myNumHs++; OB_COMPARE(myNumHs, 1); }
void testAlternativeOrigin() { // See https://github.com/openbabel/openbabel/pull/1558 OBConversion conv; OBMol mol; conv.SetInFormat("cif"); conv.ReadFile(&mol, GetFilename("test04.cif")); OBUnitCell* pUC = (OBUnitCell*)mol.GetData(OBGenericDataType::UnitCell); const SpaceGroup* pSG = pUC->GetSpaceGroup(); SpaceGroup* sg = new SpaceGroup(*pSG); pSG = SpaceGroup::Find(sg); string summary = obErrorLog.GetMessageSummary(); OB_ASSERT( summary.find("warning") == string::npos); OB_ASSERT( pSG != NULL ); OB_ASSERT( pSG->GetOriginAlternative() == 1); }
extern "C" char * ob_delete_hydrogens (char *smiles, int nonpolaronly) { OBMol mol; OBConversion conv; string tmpStr (smiles); string outstring; istringstream molstream1 (tmpStr); ostringstream molstream2; char *tmpMolfile; conv.SetInAndOutFormats ("SMI", "SMI"); conv.Read (&mol, &molstream1); if(mol.NumHvyAtoms () > 0) { if (nonpolaronly != 0) { mol.DeleteNonPolarHydrogens (); } else { mol.DeleteHydrogens (); } } else { cout << "Warning: Cannot remove hydrogens. Resulting molecule would be empty!" << endl; } conv.Write (&mol, &molstream2); outstring = molstream2.str (); // remove the trailling $$$$\n from the SDFile if (outstring.find ("$$$$\n", 0) != string::npos) { outstring = outstring.substr (0, outstring.length () - 5); } else if (outstring.find ("$$$$\r\n", 0) != string::npos) { outstring = outstring.substr (0, outstring.length () - 6); } tmpMolfile = strdup (outstring.c_str ()); return (tmpMolfile); }
/***************************************************************** * 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); }
extern "C" int ob_total_charge (char *smiles) { OBMol mol; OBConversion conv; string tmpStr (smiles); istringstream molstream (tmpStr); int totalcharge = 0; conv.SetInAndOutFormats ("SMI", "SMI"); conv.Read (&mol, &molstream); totalcharge = mol.GetTotalCharge (); return (totalcharge); }
extern "C" unsigned int ob_num_rotatable_bonds (char *smiles) { OBMol mol; OBConversion conv; string tmpStr (smiles); istringstream molstream (tmpStr); unsigned int numrotors = 0; conv.SetInAndOutFormats ("SMI", "SMI"); conv.Read (&mol, &molstream); numrotors = mol.NumRotors (); return (numrotors); }
extern "C" unsigned int ob_num_heavy_atoms (char *smiles) { OBMol mol; OBConversion conv; string tmpStr (smiles); istringstream molstream (tmpStr); unsigned int numheavyatoms = 0; conv.SetInAndOutFormats ("SMI", "SMI"); conv.Read (&mol, &molstream); numheavyatoms = mol.NumHvyAtoms (); return (numheavyatoms); }