本文整理汇总了C++中OBConversion::AddOption方法的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion::AddOption方法的具体用法?C++ OBConversion::AddOption怎么用?C++ OBConversion::AddOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBConversion
的用法示例。
在下文中一共展示了OBConversion::AddOption方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tmpStr
extern "C" char *
ob_mol_to_canonical_smiles (char *molfile, int omit_iso_and_chiral_markings)
{
OBMol mol;
OBConversion conv;
string tmpStr (molfile);
string outstring;
istringstream molstream (tmpStr);
ostringstream smilesstream;
char *tmpSmiles;
conv.SetInAndOutFormats ("MDL", "CAN");
conv.AddOption ("n", OBConversion::OUTOPTIONS);
//conv.AddOption ("c", OBConversion::OUTOPTIONS);
if (omit_iso_and_chiral_markings != 0)
{
conv.AddOption ("i", OBConversion::OUTOPTIONS);
}
conv.Read (&mol, &molstream);
if (mol.Empty ())
return NULL;
conv.Write (&mol, &smilesstream);
outstring = smilesstream.str ();
outstring = outstring.substr (0, outstring.length () - 1);
tmpSmiles = strdup (outstring.c_str ());
return (tmpSmiles);
}
示例2: 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);
}
}
示例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: 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: 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);
}
示例7: 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;
}
示例8: DoOption
void DoOption(const char* p, OBConversion& Conv,
OBConversion::Option_type typ, int& arg, int argc, char *argv[])
{
//Unlike babel, cannot have multiple concatenated single char options
//accepts: -sCCC -s CCC -s"CCC" -s CCC red -sCCC red
char ch[2]="?";
*ch = *p++;
std::string txt;
//Get the option text
if(*p)
txt = p; //use text immediately following the option letter, and keep looking
while(arg<argc-1 && *argv[arg+1]!='-')
{
//use text from subsequent args
if(!txt.empty())txt += ' '; //..space separated if more than one
txt += argv[++arg];
}
Conv.AddOption(ch, typ, txt.c_str());
}
示例9: main
//.........这里部分代码省略.........
}
else
help();
return 0;
case '-': //long option --name text
{
//Option's text is in the next and subsequent args, until one starts with -
char* nam = argv[arg]+2;
if(!strcasecmp(nam, "help")) //special case handled here
{
help();
return 0;
}
if(*nam != '\0') //Do nothing if name is empty
{
string txt;
while(arg<argc-1 && *argv[arg+1]!='-')
{
//use text from subsequent args
if(!txt.empty())txt += ' '; //..space separated if more than one
txt += argv[++arg];
}
// If a API directive, e.g.---errorlevel
// send to the pseudoformat "obapi" (without any leading -)
if(*nam=='-')
{
OBConversion apiConv;
OBFormat* pAPI= OBConversion::FindFormat("obapi");
if(pAPI)
{
apiConv.SetOutFormat(pAPI);
apiConv.AddOption(nam+1, OBConversion::GENOPTIONS, txt.c_str());
apiConv.Write(NULL, &std::cout);
}
}
else
// Is a normal long option name, e.g --addtotitle
Conv.AddOption(nam,OBConversion::GENOPTIONS,txt.c_str());
}
}
break;
case 'm': //multiple output files
SplitOrBatch=true;
break;
case 'a': //single character input option
p = argv[arg]+2;
DoOption(p,Conv,OBConversion::INOPTIONS,arg,argc,argv);
break;
case 'x': //single character output option
p = argv[arg]+2;
DoOption(p,Conv,OBConversion::OUTOPTIONS,arg,argc,argv);
break;
//Not essential, but allows these options to be before input filenames
//since we know they take one parameter, and are the most likely options to be misplaced
case 'f':
case 'l':
p = argv[arg] + 2;
if(!*p)
p = argv[++arg]; //space left after -f: use next argument
Conv.AddOption(opchar, OBConversion::GENOPTIONS, p);
示例10: 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
//.........这里部分代码省略.........
示例11: addHydrogensToPair
// This function will call the Babel library to add
// hydrogens to the residues
void PDB::addHydrogensToPair(AminoAcid& a, AminoAcid& b, int cd1, int cd2)
{
OBMol mol;
string addedH;
istringstream tempss;
bool ligand;
if(b.atom[0]->line.find("HETATM") != string::npos)
{
ligand = true;
}
else
{
ligand = false;
}
// This section is just to suppress all of the
// warning message that aren't important to us
{
OBConversion apiConv;
OBFormat* pAPI = OBConversion::FindFormat("obapi");
if(pAPI)
{
apiConv.SetOutFormat(pAPI);
apiConv.AddOption("errorlevel", OBConversion::GENOPTIONS, "0");
apiConv.Write(NULL, &std::cout);
}
}
// Now, let's pack up the information into a string
string packedFile="";
for(unsigned int i=0; i < a.altlocs[cd1].size(); i++)
{
if( !a.altlocs[cd1][i]->skip )
{
packedFile += a.altlocs[cd1][i]->line + "\n";
}
}
int cd2_al = cd2;
if(b.residue == "ASP" || b.residue == "GLU")
{
cd2_al = cd2%(b.altlocs.size());
}
for(unsigned int i=0; i < b.altlocs[cd2_al].size(); i++)
{
if( !b.altlocs[cd2_al][i]->skip )
{
packedFile += b.altlocs[cd2_al][i]->line + "\n";
}
}
packedFile += a.makeConect(cd1);
packedFile += b.makeConect(cd2_al);
// Now, let's set up some Babel information
// First, we get the PDB format to tell
// Babel how to read the information and
// how to output it
OBFormat* pdbformat = this->conv.FindFormat("pdb");
this->conv.SetInFormat(pdbformat);
this->conv.SetOutFormat(pdbformat);
// Here is where Babel reads everything
// and adds hydrogens to the pair
// TO ADD: option to set pH
this->conv.ReadString(&mol,packedFile);
mol.AddHydrogens(false,true,PH_LEVEL);
// Let's write the newly written hydrogens to
// a string and parse it
addedH = this->conv.WriteString(&mol);
tempss.str(addedH);
// This ensures that the ligand hydrogens are labeled as
// HETATM instead of ATOM just for the sake of STAAR.
// This may be wrong, but it should be fine since we are
// stripping out that information later when we write
// the GAMESS inp files
if( ligand )
{
string line;
string f = "";
while( getline(tempss,line) )
{
if( line.find(b.residue) != string::npos )
{
line.replace(0,6,"HETATM");
}
f += line + "\n";
}
tempss.seekg(ios_base::beg);
tempss.clear();
tempss.str(f);
}
this->failure = false;
this->parsePDB(tempss,99999.99);
//.........这里部分代码省略.........
示例12: main
//.........这里部分代码省略.........
else
{
OBPlugin::List("formats","verbose");
}
}
else
help();
return 0;
case '-': //long option --name text
{
//Do nothing if name is empty
//Option's text is the next arg provided it doesn't start with -
char* nam = argv[arg]+2;
if(*nam != '\0')
{
string txt;
int i;
for(i=0; i<Conv.GetOptionParams(nam, OBConversion::GENOPTIONS)
&& arg<argc-1 && argv[arg+1];++i) //removed && *argv[arg+1]!='-'
{
if(!txt.empty()) txt+=' ';
txt += argv[++arg];
}
if(*nam=='-')
{
// Is a API directive, e.g.---errorlevel
//Send to the pseudoformat "obapi" (without any leading -)
OBConversion apiConv;
OBFormat* pAPI= OBConversion::FindFormat("obapi");
if(pAPI)
{
apiConv.SetOutFormat(pAPI);
apiConv.AddOption(nam+1, OBConversion::GENOPTIONS, txt.c_str());
apiConv.Write(NULL, &std::cout);
}
}
else
// Is a long option name, e.g --addtotitle
Conv.AddOption(nam,OBConversion::GENOPTIONS,txt.c_str());
}
}
break;
case 'm': //multiple output files
SplitOrBatch=true;
break;
case 'a': //single character input option
p = argv[arg]+2;
DoOption(p,Conv,OBConversion::INOPTIONS,arg,argc,argv);
break;
case 'x': //single character output option
p = argv[arg]+2;
DoOption(p,Conv,OBConversion::OUTOPTIONS,arg,argc,argv);
break;
default: //single character general option
p = argv[arg]+1;
DoOption(p,Conv,OBConversion::GENOPTIONS,arg,argc,argv);
break;
}
}
else
{