本文整理汇总了C++中OBConversion::SetOutFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion::SetOutFormat方法的具体用法?C++ OBConversion::SetOutFormat怎么用?C++ OBConversion::SetOutFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBConversion
的用法示例。
在下文中一共展示了OBConversion::SetOutFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: Do
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;
}
示例3: 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);
}
示例4: testSpaceGroupClean
void testSpaceGroupClean()
{
// See https://github.com/openbabel/openbabel/pull/254
OBConversion conv;
OBMol mol;
conv.SetInFormat("cif");
conv.SetOutFormat("pdb");
conv.ReadFile(&mol, GetFilename("test02.cif"));
OBUnitCell* pUC = (OBUnitCell*)mol.GetData(OBGenericDataType::UnitCell);
const SpaceGroup* pSG = pUC->GetSpaceGroup();
SpaceGroup* sg = new SpaceGroup(*pSG);
pSG = SpaceGroup::Find(sg);
OB_ASSERT( pSG != NULL );
// Check also for errors and warnings
string summary = obErrorLog.GetMessageSummary();
OB_ASSERT( summary.find("error") == string::npos);
OB_ASSERT( summary.find("warning") == string::npos);
OB_ASSERT( pSG->GetId() == 166 );
string pdb = conv.WriteString(&mol);
pdb = conv.WriteString(&mol);
OB_ASSERT(pdb.find("H -3 m") != string::npos);
}
示例5: 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");
}
示例6: testCIFMolecules
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);
}
示例7: testPdbRemSpacesHMName
void testPdbRemSpacesHMName()
{
// See https://github.com/openbabel/openbabel/pull/1558
OBConversion conv;
OBMol mol;
conv.SetInFormat("cif");
conv.SetOutFormat("pdb");
conv.ReadFile(&mol, GetFilename("test07.cif"));
string pdb = conv.WriteString(&mol);
conv.AddOption("o", OBConversion::OUTOPTIONS);
pdb = conv.WriteString(&mol);
OB_ASSERT(pdb.find("I41/amd:2") != string::npos);
}
示例8: testPdbOutHexagonalAlternativeOrigin2
void testPdbOutHexagonalAlternativeOrigin2()
{
// See https://github.com/openbabel/openbabel/pull/1558
OBConversion conv;
OBMol mol;
conv.SetInFormat("cif");
conv.SetOutFormat("pdb");
conv.ReadFile(&mol, GetFilename("test06.cif"));
string pdb = conv.WriteString(&mol);
conv.AddOption("o", OBConversion::OUTOPTIONS);
pdb = conv.WriteString(&mol);
OB_ASSERT(pdb.find("H -3 m") != string::npos);
}
示例9: test_Issue135_UniversalSmiles
// A segfault was occuring when a Universal SMILES was output after an InChIfied SMILES.
// This was due to short-circuit caching of InChIs on reading. The fix was to limit
// the situations when the cached value was used, but also to delete the cached value
// in this particular instance.
void test_Issue135_UniversalSmiles()
{
// Test writing U smiles after I smiles
OBConversion conv;
conv.SetInFormat("smi");
OBMol mol;
conv.ReadString(&mol, "C(=O)([O-])C(=O)O");
conv.SetOutFormat("smi");
conv.SetOptions("I", OBConversion::OUTOPTIONS);
std::string res = conv.WriteString(&mol, true);
OB_COMPARE(res, "C(=O)(C(=O)O)[O-]");
conv.SetOptions("U", OBConversion::OUTOPTIONS);
res = conv.WriteString(&mol, true);
OB_COMPARE(res, "C(=O)(C(=O)[O-])O");
}
示例10: main
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);
}
}
示例11: main
int main(int argc, char **argv)
{
// Define location of file formats for testing
#ifdef FORMATDIR
char env[BUFF_SIZE];
snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
putenv(env);
#endif
std::ifstream ifs(GetFilename("canonstable.can").c_str());
OB_REQUIRE( ifs );
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.SetOutFormat("can");
std::string line;
while (std::getline(ifs, line)) {
OB_REQUIRE( conv.ReadString(&mol, line.c_str()) );
std::vector<OBAtom*> atoms;
FOR_ATOMS_OF_MOL(atom, mol)
atoms.push_back(&*atom);
for (int i = 0; i < 5; ++i) {
// shuffle the atoms
std::random_shuffle(atoms.begin(), atoms.end());
mol.RenumberAtoms(atoms);
// get can smiles
mol.SetTitle("");
std::string cansmi = conv.WriteString(&mol, true);
// comapare with ref
if (cansmi != line) {
cout << "ref = " << line << endl;
cout << "can = " << cansmi << endl;
OB_ASSERT( cansmi == line );
}
}
}
return 0;
}
示例12: testPdbOutAlternativeOrigin
void testPdbOutAlternativeOrigin()
{
// See https://github.com/openbabel/openbabel/pull/1558
OBConversion conv;
OBMol mol;
conv.SetInFormat("cif");
conv.SetOutFormat("pdb");
conv.ReadFile(&mol, GetFilename("test04.cif"));
string pdb = conv.WriteString(&mol);
// ending space is needed to check that there is no origin set
OB_ASSERT(pdb.find("P 4/n b m ") != string::npos);
conv.AddOption("o", OBConversion::OUTOPTIONS);
pdb = conv.WriteString(&mol);
OB_ASSERT(pdb.find("P 4/n b m:1") != string::npos);
}
示例13: ProcessVec
bool OpReadConformers::ProcessVec(std::vector<OBBase*>& vec)
{
// DeferredFormat collects all the molecules, they are processed here, and Deferred Format outputs them
OBConversion smconv;
smconv.AddOption("n");
if(!smconv.SetOutFormat("smi"))
{
obErrorLog.ThrowError(__FUNCTION__, "SmilesFormat is not loaded" , obError, onceOnly);
return false;
}
std::string smiles, stored_smiles;
OBMol* stored_pmol=NULL;
std::vector<OBBase*>::iterator iter;
for(iter= vec.begin();iter!=vec.end();++iter)
{
OBMol* pmol = dynamic_cast<OBMol*>(*iter);
if(!pmol)
continue;
smiles = smconv.WriteString(pmol);
Trim(smiles);
if(stored_smiles==smiles)
{
//add the coordinates of the current mol to the stored one as a conformer, and delete current mol
double *confCoord = new double [pmol->NumAtoms() * 3];
memcpy((char*)confCoord,(char*)pmol->GetCoordinates(),sizeof(double)*3*pmol->NumAtoms());
stored_pmol->AddConformer(confCoord);
delete pmol;
*iter = NULL;
}
else
{
stored_pmol = pmol;
stored_smiles = smiles;
}
}
//erase the NULLS
vec.erase(std::remove(vec.begin(),vec.end(), (void*)NULL), vec.end());
return true;
}
示例14: ObtainTarget
//.........这里部分代码省略.........
//Interpret as a filename if possible
string& txt =vec [0];
if( txt.empty() ||
txt.find('.')==string::npos ||
!(pFormat = patternConv.FormatFromExt(txt.c_str())) ||
!patternConv.SetInFormat(pFormat) ||
!patternConv.ReadFile(&patternMol, txt) ||
patternMol.NumAtoms()==0)
//if false, have a valid patternMol from a file
{
//is SMARTS/SMILES
//Replace e.g. [#6] in SMARTS by C so that it can be converted as SMILES
//for the fingerprint phase, but allow more generality in the SMARTS phase.
for(;;)
{
string::size_type pos1, pos2;
pos1 = txt.find("[#");
if(pos1==string::npos)
break;
pos2 = txt.find(']');
int atno;
if(pos2!=string::npos && (atno = atoi(txt.substr(pos1+2, pos2-pos1-2).c_str())) && atno>0)
txt.replace(pos1, pos2-pos1+1, etab.GetSymbol(atno));
else
{
obErrorLog.ThrowError(__FUNCTION__,"Ill-formed [#n] atom in SMARTS", obError);
return false;
}
}
bool hasTildeBond;
if( (hasTildeBond = (txt.find('~')!=string::npos)) ) // extra parens to indicate truth value
{
//Find ~ bonds and make versions of query molecule with a single and aromatic bonds
//To avoid having to parse the SMILES here, replace ~ by $ (quadruple bond)
//and then replace this in patternMol. Check first that there are no $ already
//Sadly, isocynanides may have $ bonds.
if(txt.find('$')!=string::npos)
{
obErrorLog.ThrowError(__FUNCTION__,
"Cannot use ~ bonds in patterns with $ (quadruple) bonds.)", obError);
return false;
}
replace(txt.begin(),txt.end(), '~' , '$');
}
//read as standard SMILES
patternConv.SetInFormat("smi");
if(!patternConv.ReadString(&patternMol, vec[0]))
{
obErrorLog.ThrowError(__FUNCTION__,"Cannot read the SMILES string",obError);
return false;
}
if(hasTildeBond)
{
AddPattern(patternMols, patternMol, 0); //recursively add all combinations of tilde bond values
return true;
}
}
else
{
// target(s) are in a file
patternMols.push_back(patternMol);
while(patternConv.Read(&patternMol))
patternMols.push_back(patternMol);
return true;
}
}
if(OldSOption) //only when using deprecated -S and -aS options
{
//make -s option for later SMARTS test
OBConversion conv;
if(conv.SetOutFormat("smi"))
{
string optiontext = conv.WriteString(&patternMol, true);
pConv->AddOption("s", OBConversion::GENOPTIONS, optiontext.c_str());
}
}
if(!p)
{
//neither -s or -S options provided. Output info rather than doing search
const FptIndexHeader& header = fs.GetIndexHeader();
string id(header.fpid);
if(id.empty())
id = "default";
clog << indexname << " is an index of\n " << header.datafilename
<< ".\n It contains " << header.nEntries
<< " molecules. The fingerprint type is " << id << " with "
<< OBFingerprint::Getbitsperint() * header.words << " bits.\n"
<< "Typical usage for a substructure search:\n"
<< "obabel indexfile.fs -osmi -sSMILES\n"
<< "(-s option in GUI is 'Convert only if match SMARTS or mols in file')" << endl;
return false;
}
patternMols.push_back(patternMol);
return true;
}
示例15: main
///////////////////////////////////////////////////////////////////////////////
//! \brief compute rms between chemically identical molecules
int main(int argc, char **argv)
{
bool firstOnly = false;
if (argc != 3 && argc != 4)
{
cerr << "Usage: " << argv[0]
<< " [-firstonly] <reference structure(s)> <comparison structure(s)>\n";
cerr << "Computes the heavy-atom RMSD of identical compound structures.\n";
cerr << "Structures in multi-structure files are compared one-by-one unless -firstonly\n"
<< "is passed, in which case only the first structure in the reference file is used.\n";
exit(-1);
}
char *fileRef = argv[1];
char *fileTest = argv[2];
if (argc == 4)
{
//if iterate is passed as first command, try to match structures in first file to strucutres in second
if (strcmp("-firstonly", argv[1]) != 0)
{
cerr << "Usage: " << argv[0]
<< " [-firstonly] <reference structure(s)> <comparison structure(s)>\n";
exit(-1);
}
fileRef = argv[2];
fileTest = argv[3];
firstOnly = true;
}
//open mols
OBConversion refconv;
OBFormat *refFormat = refconv.FormatFromExt(fileRef);
if (!refFormat || !refconv.SetInFormat(refFormat)
|| !refconv.SetOutFormat("SMI"))
{
cerr << "Cannot read reference molecule format!" << endl;
exit(-1);
}
OBConversion testconv;
OBFormat *testFormat = testconv.FormatFromExt(fileTest);
if (!testFormat || !testconv.SetInAndOutFormats(testFormat, testFormat))
{
cerr << "Cannot read reference molecule format!" << endl;
exit(-1);
}
//read reference
ifstream ifsref;
OBMol molref;
ifsref.open(fileRef);
if (!ifsref)
{
cerr << "Cannot read fixed molecule file: " << fileRef << endl;
exit(-1);
}
//check comparison file
ifstream ifstest;
ifstest.open(fileTest);
if (!ifstest)
{
cerr << "Cannot read file: " << fileTest << endl;
exit(-1);
}
while (refconv.Read(&molref, &ifsref))
{
processMol(molref);
Matcher matcher(molref);// create the matcher
OBMol moltest;
while (testconv.Read(&moltest, &ifstest))
{
if (moltest.Empty())
break;
processMol(moltest);
double rmsd = matcher.computeRMSD(moltest);
cout << "RMSD " << moltest.GetTitle() << " " << rmsd << "\n";
if (!firstOnly)
{
break;
}
}
}
return (0);
}