本文整理汇总了C++中OBConversion类的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion类的具体用法?C++ OBConversion怎么用?C++ OBConversion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OBConversion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ob_strip_salts
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);
}
示例2: 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();
}
示例3: testIsomorphism1
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;
}
示例4: DoOption
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);
}
}
示例5: GetMol
// 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;
}
示例6: main
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;
}
示例7: OBConversion
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;
}
示例8: 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;
}
示例9: testPdbOccupancies
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);
}
示例10: ob_add_hydrogens
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);
}
示例11: testTetrahedralStereo1
void testTetrahedralStereo1()
{
cout << "testTetrahedralStereo1()" << endl;
// read a smiles string
OBMol mol;
OBConversion conv;
OB_REQUIRE( conv.SetInFormat("smi") );
cout << "smiles: C[[email protected]](O)N" << endl;
OB_REQUIRE( conv.ReadString(&mol, "C[[email protected]](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[[email protected]](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;
}
示例12: 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);
}
示例13: test_Issue134_InChI_addH
// 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[[email protected]@H](N)O");
}
示例14: testAutomorphismMask
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 );
}
}
示例15: 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);
}