本文整理汇总了C++中OBConversion::WriteString方法的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion::WriteString方法的具体用法?C++ OBConversion::WriteString怎么用?C++ OBConversion::WriteString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBConversion
的用法示例。
在下文中一共展示了OBConversion::WriteString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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");
}
示例4: 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);
}
示例5: 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);
}
示例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: 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);
}
示例8: 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");
}
示例9: 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);
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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)
{
cout << "Usage: conversion" << endl;
cout << " Unit tests for OBConversion " << endl;
return(-1);
}
cout << "# Unit tests for OBConversion \n";
// the number of tests for "prove"
cout << "1..9\n";
cout << "ok 1\n"; // for loading tests
OBMol obMol;
OBConversion obConversion;
obConversion.SetInAndOutFormats("smi", "mdl");
cout << "ok 2\n";
obConversion.ReadString(&obMol, "C1=CC=CS1");
cout << "ok 3\n";
if (obMol.NumAtoms() == 5) {
cout << "ok 4\n";
} else {
cout << "not ok 4\n";
}
obMol.AddHydrogens();
if (obMol.NumAtoms() == 9) {
cout << "ok 5\n";
} else {
cout << "not ok 5\n";
}
if ( (obConversion.WriteString(&obMol)).length() > 0)
cout << "ok 6\n";
else
cout << "not ok 6\n";
// PR#1474265
obConversion.WriteFile(&obMol, "test.mdl");
ifstream ifs("test.mdl");
if (ifs.good())
cout << "ok 7\n";
else
cout << "not ok 7\n";
// PR#143577
obConversion.SetInFormat("mdl");
obConversion.ReadFile(&obMol, "test.mdl");
if ( remove("test.mdl") != -1)
cout << "ok 8\n";
else
cout << "not ok 8\n";
// gzip input
// gzip output
// multi-molecule reading
// PR#1465586
// aromatics.smi
// attype.00.smi
//ReadFile()
//Read()
//WriteString()
// GetOutputIndex()
// IsLast
//ReadString()
//IsFirstInput
//Read()
// splitting
// splitting using gzip-input
// PR#1357705
// size 0 input
// PR#1250900
// RegisterFormat
// FindFormat
// FormatFromExt
// FormatFromMIME
// GetNextFormat
// GetDefaultFormat
// BatchFileName
// IncrementedFileName
// option handling
// AddOption
// IsOption
//.........这里部分代码省略.........
示例14: Do
bool OpNewS::Do(OBBase* pOb, const char* OptionText, OpMap* pmap, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if(!pmol)
return false;
// The SMARTS and any other parameters are extracted on the first molecule
// and stored in the member variables. The parameter is cleared so that
// the original -s option in transform.cpp is inactive
//string txt(pmap->find(GetID())->second); // ID can be "s" or "v"
vector<OBQuery*>::iterator qiter;
if(OptionText && *OptionText)//(!pConv || pConv->IsFirstInput())
{
//Set up on first call
queries.clear();
query=NULL;
nPatternAtoms=0;
inv=false;
tokenize(vec, OptionText);
inv = GetID()[0]=='v';
if(vec[0][0]=='~')
{
inv = true;
vec[0].erase(0,1);
}
//Do not filter out any molecules if there is a parameter "showall";
//allows -s option to be used for highlighting substructures (--highlight also does this)
vector<string>::iterator it = std::remove(vec.begin(), vec.end(),"showall");
showAll = it != vec.end();
if(showAll)
vec.erase(it);
//Store the number of matches required, if as a number in the second parameter, else 0.
nmatches = 0;
comparechar = '\0';
if(vec.size()>1)
{
comparechar = vec[1][0];
if(comparechar=='>' || comparechar=='<')
vec[1].erase(0,1);
else
comparechar = '\0';
nmatches = atoi(vec[1].c_str());
if(nmatches) //remove this parameter to still allow coloring
vec.erase(vec.begin()+1);
}
//Interpret as a filename if possible
MakeQueriesFromMolInFile(queries, vec[0], &nPatternAtoms, strstr(OptionText,"noH"));
vec.erase(remove(vec.begin(),vec.end(),"noH"),vec.end());//to prevent "noH2" being seen as a color
if(queries.empty())
{
//SMARTS supplied
// Explicit H in SMARTS requires explicit H in the molecule.
// Calling AddHydrogens() on a copy of the molecule is done in parsmart.cpp
// only when SMARTS contains [H]. Doing more has complications with atom typing,
// so AddHydrogens here on the molecule (not a copy) when #1 detected.
addHydrogens = (vec[0].find("#1]")!=string::npos);
// If extra target mols have been supplied, make a composite SMARTS
// to test for any of the targets.
if(ExtraMols.size()>0)
{
for(unsigned i=0;i<ExtraMols.size();++i)
{
OBConversion extraConv;
extraConv.AddOption("h");
if(!extraConv.SetOutFormat("smi"))
return false;
// Add option which avoids implicit H being added to the SMARTS.
// The parameter must be present but can be anything.
extraConv.AddOption("h",OBConversion::OUTOPTIONS, "X");
xsmarts += ",$(" + extraConv.WriteString(ExtraMols[i], true) + ")";
}
}
string ysmarts = xsmarts.empty() ? vec[0] : "[$(" + vec[0] + ")" + xsmarts +"]";
xsmarts.clear();
if(!sp.Init(ysmarts))
{
string msg = ysmarts + " cannot be interpreted as either valid SMARTS "
"or the name of a file with an extension known to OpenBabel "
"that contains one or more pattern molecules.";
obErrorLog.ThrowError(__FUNCTION__, msg, obError, onceOnly);
delete pmol;
pmol = NULL;
pConv->SetOneObjectOnly(); //stop conversion
return false;
}
}
else
{
// Target is in a file. Add extra targets if any supplied
//.........这里部分代码省略.........
示例15: 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);
OBConversion conv;
OBFormat *inFormat, *canFormat;
OBMol mol;
ifstream ifs;
vector<OBMol> fragments;
unsigned int fragmentCount = 0; // track how many in library -- give a running count
map<string, int> index; // index of cansmi
string currentCAN;
unsigned int size;
OBAtom *atom;
OBBond *bond;
bool nonRingAtoms, nonRingBonds;
char buffer[BUFF_SIZE];
canFormat = conv.FindFormat("can");
conv.SetOutFormat(canFormat);
if (argc < 2)
{
cout << "Usage: obfragment <file>" << endl;
return(-1);
}
for (int i = 1; i < argc; i++) {
cerr << " Reading file " << argv[i] << endl;
inFormat = conv.FormatFromExt(argv[i]);
if(inFormat==NULL || !conv.SetInFormat(inFormat))
{
cerr << " Cannot read file format for " << argv[i] << endl;
continue; // try next file
}
ifs.open(argv[i]);
if (!ifs)
{
cerr << "Cannot read input file: " << argv[i] << endl;
continue;
}
while(ifs.peek() != EOF && ifs.good())
{
conv.Read(&mol, &ifs);
if (!mol.Has3D()) continue; // invalid coordinates!
mol.DeleteHydrogens(); // remove these before we do anything else
do {
nonRingAtoms = false;
size = mol.NumAtoms();
for (unsigned int i = 1; i <= size; ++i)
{
atom = mol.GetAtom(i);
if (!atom->IsInRing()) {
mol.DeleteAtom(atom);
nonRingAtoms = true;
break; // don't know how many atoms there are
}
// Previously, we changed atoms to carbon here.
// Now we perform this alchemy in terms of string-rewriting
// once the canonical SMILES is generated
}
} while (nonRingAtoms);
if (mol.NumAtoms() < 3)
continue;
if (mol.NumBonds() == 0)
continue;
do {
nonRingBonds = false;
size = mol.NumBonds();
for (unsigned int i = 0; i < size; ++i)
{
bond = mol.GetBond(i);
if (!bond->IsInRing()) {
mol.DeleteBond(bond);
nonRingBonds = true;
break; // don't know how many bonds there are
}
}
} while (nonRingBonds);
fragments = mol.Separate();
for (unsigned int i = 0; i < fragments.size(); ++i)
{
if (fragments[i].NumAtoms() < 3) // too small to care
continue;
currentCAN = conv.WriteString(&fragments[i], true);
currentCAN = RewriteSMILES(currentCAN); // change elements to "a/A" for compression
if (index.find(currentCAN) != index.end()) { // already got this
index[currentCAN] += 1; // add to the count for bookkeeping
//.........这里部分代码省略.........