本文整理汇总了C++中OBConversion::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion::Write方法的具体用法?C++ OBConversion::Write怎么用?C++ OBConversion::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBConversion
的用法示例。
在下文中一共展示了OBConversion::Write方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tmpStr
extern "C" char *
ob_V3000_to_mol (char *V3000)
{
OBMol mol;
OBConversion conv;
string tmpStr (V3000);
string outstring;
istringstream V3000stream (tmpStr);
ostringstream molstream;
char *tmpMolfile;
conv.SetInAndOutFormats ("MDL", "MDL");
conv.AddOption ("3", OBConversion::INOPTIONS);
conv.AddOption ("2", OBConversion::OUTOPTIONS);
conv.Read (&mol, &V3000stream);
conv.Write (&mol, &molstream);
outstring = molstream.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);
}
示例2: turnMol
void turnMol(OBMol& mol,vector< vector <int> >& maplist,int k)
{
if (k<0)
return;
if (k>=maplist.size())
return;
OBAtom *a1, *a2, *a3, *a4;
double energy;
string fileName;
ostringstream oss(fileName);
for (int i=0;i<angleSum;++i) {
fileName = "";
a2 = mol.GetAtom(maplist[k][0]);
a3 = mol.GetAtom(maplist[k][1]);
std::vector<OBEdgeBase*>::iterator temp = a2->BeginBonds();
a1 = a2->BeginNbrAtom(temp);
if (a1==a3)
a1 = a2->NextNbrAtom(temp);
temp = a3->BeginBonds();
a4 = a3->BeginNbrAtom(temp);
if (a4==a2)
a4 = a3->NextNbrAtom(temp);
if ( !a2->IsConnected(a3) ) {
cerr << "obrotate: The atoms of the rotating bond must be bonded." << endl;
exit(-1);
}
mol.SetTorsion(a1, a2, a3, a4, i * angle * DEG_TO_RAD);
if (isEnergyCalcing)
{
indexSheet[k]=i;
forceField->Setup(mol);
energy = forceField->Energy(false);
energySheet->getVectorValue(indexSheet)=energy;
}
else
{
oss.str("");
pthread_mutex_lock(&sum_lock);
oss << sum++ << "," << FileIn ;
pthread_mutex_unlock(&sum_lock);
ofstream ofs(oss.str().c_str());
cerr << "Outputing file no." << sum << "/" << totalSum << endl;
conv.Write(&mol,&ofs); //NF
}
turnMol(mol,maplist,k-1);
}
}
示例3: 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);
}
}
示例4: outputMol
void outputMol(vector<int*>& mols,OBMol& mol,vector< vector <int> >& maplist,int k)
{
if (k<0)
return;
if (k>=maplist.size())
return;
OBAtom *a1, *a2, *a3, *a4;
double energy;
string fileName;
ostringstream oss(fileName);
for (int i=0;i<angleSum;++i) {
fileName = "";
a2 = mol.GetAtom(maplist[k][0]);
a3 = mol.GetAtom(maplist[k][1]);
std::vector<OBEdgeBase*>::iterator temp = a2->BeginBonds();
a1 = a2->BeginNbrAtom(temp);
if (a1==a3)
a1 = a2->NextNbrAtom(temp);
temp = a3->BeginBonds();
a4 = a3->BeginNbrAtom(temp);
if (a4==a2)
a4 = a3->NextNbrAtom(temp);
mol.SetTorsion(a1, a2, a3, a4, i * angle * DEG_TO_RAD);
indexSheet[k]=i;
if (isContained(mols,indexSheet))
{
oss.str("");
pthread_mutex_lock(&sum_lock);
oss << sum++ << "," << FileIn;
pthread_mutex_unlock(&sum_lock);
ofstream ofs(oss.str().c_str());
cerr << "Outputing low energy file no." << sum << "/" << totalSum << endl;
conv.Write(&mol,&ofs); //NF
}
outputMol(mols,mol,maplist,k-1);
}
}
示例5: main
//.........这里部分代码省略.........
// param is a subtype, like babel -L ops gen3D
// or first arg is a plugin ID, like babel -L cml
OBPlugin* plugin;
if(OBPlugin::GetPlugin("plugins", argv[arg+1])
&& (plugin = OBPlugin::GetPlugin(argv[arg+1], param))
|| (plugin = OBPlugin::GetPlugin(NULL, argv[arg+1])))
{
//Output details of subtype
string txt;
plugin->Display(txt, "verbose", argv[arg+1]);
cout << "One of the " << plugin->TypeID() << '\n' << txt << endl;
return 0;
}
//...otherwise assume it is a plugin type, like babel -L forcefields
//Output list of subtypes
OBPlugin::List(argv[arg+1], param);
return 0;
}
case '?':
case 'H':
if(isalnum(argv[arg][2]) || arg==argc-2)
{
if(strncasecmp(argv[arg]+2,"all",3))
{
OBFormat* pFormat
= (arg==argc-2) ? Conv.FindFormat(argv[arg+1]) : Conv.FindFormat(argv[arg]+2);
if(pFormat)
{
cout << argv[arg]+2 << " " << pFormat->Description() << endl;
if(pFormat->Flags() & NOTWRITABLE)
cout << " This format is Read-only" << endl;
if(pFormat->Flags() & NOTREADABLE)
cout << " This format is Write-only" << endl;
if(strlen(pFormat->SpecificationURL()))
cout << "Specification at: " << pFormat->SpecificationURL() << endl;
}
else
cout << "Format type: " << argv[arg]+2 << " was not recognized" <<endl;
}
else
{
OBPlugin::List("formats","verbose");
}
}
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
示例6: main
//.........这里部分代码省略.........
list<string>::iterator optffarg = optff;
++optffarg;
if (optffarg != argl.end()) {
ff = *optffarg;
argl.erase(optff,++optffarg);
} else {
argl.erase(optff);
}
}
if (argl.empty()) {
cout << "Usage: obgen <filename> [options]" << endl;
cout << endl;
cout << "options: description:" << endl;
cout << endl;
cout << " -ff select a forcefield" << endl;
cout << endl;
OBPlugin::List("forcefields", "verbose");
exit(-1);
}
basename = filename = *argl.begin();
size_t extPos = filename.rfind('.');
if (extPos!= string::npos) {
basename = filename.substr(0, extPos);
}
// Find Input filetype
OBConversion conv;
OBFormat *format_in = conv.FormatFromExt(filename.c_str());
OBFormat *format_out = conv.FindFormat("sdf");
if (!format_in || !format_out || !conv.SetInAndOutFormats(format_in, format_out)) {
cerr << program_name << ": cannot read input/output format!" << endl;
exit (-1);
}
ifstream ifs;
ofstream ofs;
// Read the file
ifs.open(filename.c_str());
if (!ifs) {
cerr << program_name << ": cannot read input file!" << endl;
exit (-1);
}
OBMol mol;
for (c=1;;c++) {
mol.Clear();
if (!conv.Read(&mol, &ifs))
break;
if (mol.Empty())
break;
OBForceField* pFF = OBForceField::FindForceField(ff);
if (!pFF) {
cerr << program_name << ": could not find forcefield '" << ff << "'." <<endl;
exit (-1);
}
//mol.AddHydrogens(false, true); // hydrogens must be added before Setup(mol) is called
pFF->SetLogFile(&cerr);
pFF->SetLogLevel(OBFF_LOGLVL_LOW);
//pFF->GenerateCoordinates();
OBBuilder builder;
builder.Build(mol);
mol.AddHydrogens(false, true); // hydrogens must be added before Setup(mol) is called
if (!pFF->Setup(mol)) {
cerr << program_name << ": could not setup force field." << endl;
exit (-1);
}
pFF->SteepestDescent(500, 1.0e-4);
pFF->WeightedRotorSearch(250, 50);
pFF->SteepestDescent(500, 1.0e-6);
pFF->UpdateCoordinates(mol);
//pFF->ValidateGradients();
//pFF->SetLogLevel(OBFF_LOGLVL_HIGH);
//pFF->Energy();
//char FileOut[32];
//sprintf(FileOut, "%s_obgen.pdb", basename.c_str());
//ofs.open(FileOut);
//conv.Write(&mol, &ofs);
//ofs.close();
conv.Write(&mol, &cout);
} // end for loop
return(0);
}
示例7: WriteMolecule
bool ReactionInChIFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if (pmol == NULL || !pmol->IsReaction())
return false;
ostream &ofs = *pConv->GetOutStream();
OBFormat* pInChIFormat = OBConversion::FindFormat("inchi");
if (!pInChIFormat)
return false;
bool isEquilibrium = pConv->IsOption("e");
OBConversion inchiconv;
inchiconv.SetOutFormat(pInChIFormat);
stringstream ss;
inchiconv.SetOutStream(&ss);
#define M_REACTANTS 0
#define M_PRODUCTS 1
#define M_AGENTS 2
OBReactionFacade facade(pmol);
std::vector<std::vector<std::string> > inchis(3);
unsigned int nonInchi[3] = { 0, 0, 0 };
bool hasNonInchi = false;
OBMol mol;
for (int part = 0; part <= 2; ++part) {
unsigned int N;
switch (part) {
case M_REACTANTS: N = facade.NumComponents(REACTANT); break;
case M_PRODUCTS: N = facade.NumComponents(PRODUCT); break;
case M_AGENTS: N = facade.NumComponents(AGENT); break;
}
for (unsigned int i = 0; i < N; ++i) {
mol.Clear();
switch (part) {
case M_REACTANTS: facade.GetComponent(&mol, REACTANT, i); break;
case M_PRODUCTS: facade.GetComponent(&mol, PRODUCT, i); break;
case M_AGENTS: facade.GetComponent(&mol, AGENT, i); break;
}
if (mol.NumAtoms() == 1 && mol.GetFirstAtom()->GetAtomicNum() == 0) {
// This represents an unknown component
nonInchi[part]++;
hasNonInchi = true;
}
else {
bool ok = inchiconv.Write(&mol);
if (!ok) {
nonInchi[part]++;
hasNonInchi = true;
}
else {
string inchi = ss.str();
if (strncmp(inchi.c_str(), "InChI=1S/", 9) != 0)
return false;
inchis[part].push_back(TrimInChI(inchi.c_str()));
}
ss.str("");
}
}
}
std::sort(inchis[M_REACTANTS].begin(), inchis[M_REACTANTS].end());
std::sort(inchis[M_PRODUCTS].begin(), inchis[M_PRODUCTS].end());
std::sort(inchis[M_AGENTS].begin(), inchis[M_AGENTS].end());
std::string reactants_string = "";
const int rsize = inchis[M_REACTANTS].size();
for (int i = 0; i < rsize; ++i) {
if (i > 0)
reactants_string += '!';
reactants_string += inchis[M_REACTANTS][i];
}
std::string products_string = "";
const int psize = inchis[M_PRODUCTS].size();
for (int i = 0; i < psize; ++i) {
if (i > 0)
products_string += '!';
products_string += inchis[M_PRODUCTS][i];
}
bool reactants_first = reactants_string <= products_string;
ofs << RINCHI_VERSION_STRING;
if (rsize > 0 || psize > 0 || !inchis[M_AGENTS].empty()) {
ofs << (reactants_first ? reactants_string : products_string);
ofs << "<>";
ofs << (reactants_first ? products_string : reactants_string);
if (!inchis[M_AGENTS].empty()) {
ofs << "<>";
for (std::vector<std::string>::const_iterator vit = inchis[M_AGENTS].begin(); vit != inchis[M_AGENTS].end(); ++vit) {
if (vit != inchis[M_AGENTS].begin())
ofs << '!';
ofs << *vit;
}
}
}
ofs << "/d";
//.........这里部分代码省略.........
示例8: 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);
//.........这里部分代码省略.........
示例9: main
//.........这里部分代码省略.........
if ((option == "-ff") && (argc > (i+1))) {
ff = argv[i+1];
ifile += 2;
}
}
basename = filename = argv[ifile];
size_t extPos = filename.rfind('.');
if (extPos!= string::npos) {
basename = filename.substr(0, extPos);
}
}
// Find Input filetype
OBFormat *format_in = conv.FormatFromExt(filename.c_str());
if (!format_in || !format_out || !conv.SetInAndOutFormats(format_in, format_out)) {
cerr << program_name << ": cannot read input/output format!" << endl;
exit (-1);
}
ifstream ifs;
ofstream ofs;
// Read the file
ifs.open(filename.c_str());
if (!ifs) {
cerr << program_name << ": cannot read input file!" << endl;
exit (-1);
}
OBForceField* pFF = OBForceField::FindForceField(ff);
if (!pFF) {
cerr << program_name << ": could not find forcefield '" << ff << "'." <<endl;
exit (-1);
}
// set some force field variables
pFF->SetLogFile(&cerr);
pFF->SetLogLevel(OBFF_LOGLVL_LOW);
pFF->SetVDWCutOff(rvdw);
pFF->SetElectrostaticCutOff(rele);
pFF->SetUpdateFrequency(freq);
pFF->EnableCutOff(cut);
if (newton)
pFF->SetLineSearchType(LineSearchType::Newton2Num);
OBMol mol;
for (c=1;;c++) {
mol.Clear();
if (!conv.Read(&mol, &ifs))
break;
if (mol.Empty())
break;
if (hydrogens)
mol.AddHydrogens();
if (!pFF->Setup(mol)) {
cerr << program_name << ": could not setup force field." << endl;
exit (-1);
}
bool done = true;
OBStopwatch timer;
timer.Start();
if (sd) {
pFF->SteepestDescentInitialize(steps, crit);
} else {
pFF->ConjugateGradientsInitialize(steps, crit);
}
unsigned int totalSteps = 1;
while (done) {
if (sd)
done = pFF->SteepestDescentTakeNSteps(1);
else
done = pFF->ConjugateGradientsTakeNSteps(1);
totalSteps++;
if (pFF->DetectExplosion()) {
cerr << "explosion has occured!" << endl;
conv.Write(&mol, &cout);
return(1);
} else
pFF->GetCoordinates(mol);
}
double timeElapsed = timer.Elapsed();
pFF->GetCoordinates(mol);
conv.Write(&mol, &cout);
cerr << "Time: " << timeElapsed << "seconds. Iterations per second: " << double(totalSteps) / timeElapsed << endl;
} // end for loop
return(0);
}
示例10: main
//.........这里部分代码省略.........
}
ifs.open(vs[1].c_str());
if (!ifs) {
cout << "could not open '" << vs[1] << "'." <<endl;
continue;
}
mol.Clear();
if (!conv.Read(&mol, &ifs)) {
cout << "could not read a molecule from '" << vs[1] << "'." <<endl;
continue;
}
if (mol.Empty()) {
cout << "this molecule is empty." <<endl;
continue;
}
if (!pFF->Setup(mol)) {
cout << "error while initializing the force field for this molecule." <<endl;
continue;
}
cout << "molecule succesfully loaded." << endl;
cout << " " << mol.NumAtoms() << " atoms" << endl;
cout << " " << mol.NumBonds() << " bonds" << endl;
ifs.close();
continue;
}
// save <filename>
if (EQn(commandline, "save", 4)) {
if (vs.size() < 2) {
cout << "no <filename> specified." << endl;
continue;
}
ofstream ofs;
OBConversion conv;
OBFormat *format_out = conv.FormatFromExt(vs[1].c_str());
if (!format_out || !conv.SetOutFormat(format_out)) {
cout << "could not detect format." << endl;
continue;
}
ofs.open(vs[1].c_str());
if (!ofs) {
cout << "could not open '" << vs[1] << "'." <<endl;
continue;
}
if (!conv.Write(&mol, &ofs)) {
cout << "could not read a molecule from '" << vs[1] << "'." <<endl;
continue;
}
cout << "molecule succesfully saved." << endl;
cout << " " << mol.NumAtoms() << " atoms" << endl;
cout << " " << mol.NumBonds() << " bonds" << endl;
ofs.close();
continue;
}
// steepest descent
if (EQn(commandline, "sd", 2)) {
if (vs.size() < 2) {
cout << "no <n> steps specified." << endl;
continue;
}
pFF->SteepestDescent(atoi(vs[1].c_str()), OBFF_ANALYTICAL_GRADIENT);
pFF->UpdateCoordinates(mol);
continue;
}
// conjugate gradients
if (EQn(commandline, "cg", 2)) {
if (vs.size() < 2) {
cout << "no <n> steps specified." << endl;
continue;
}
pFF->ConjugateGradients(atoi(vs[1].c_str()), OBFF_ANALYTICAL_GRADIENT);
pFF->UpdateCoordinates(mol);
continue;
}
cout << "invalid command." << endl;
}
return(1);
}
示例11: main
//.........这里部分代码省略.........
// First assume first arg is a plugin type and
// param is a subtype, like babel -L ops gen3D
// or first arg is a plugin ID, like babel -L cml
OBPlugin* plugin;
if ((OBPlugin::GetPlugin("plugins", argv[arg+1]) &&
(plugin = OBPlugin::GetPlugin(argv[arg+1], param))) ||
(plugin = OBPlugin::GetPlugin(NULL, argv[arg+1])))
{
//Output details of subtype
string txt;
plugin->Display(txt, "verbose", argv[arg+1]);
cout << "One of the " << plugin->TypeID() << '\n' << txt << endl;
return 0;
}
//...otherwise assume it is a plugin type, like babel -L forcefields
//Output list of subtypes
OBPlugin::List(argv[arg+1], param);
return 0;
}
case '?':
case 'H':
if(isalnum(argv[arg][2]) || arg==argc-2)
{
if(strncasecmp(argv[arg]+2,"all",3))
{
const char* pID= (arg==argc-2) ? argv[arg+1] : argv[arg]+2;
OBFormat* pFormat = Conv.FindFormat(pID);
if(pFormat)
{
cout << pID << " " << pFormat->Description() << endl;
if(pFormat->Flags() & NOTWRITABLE)
cout << " This format is Read-only" << endl;
if(pFormat->Flags() & NOTREADABLE)
cout << " This format is Write-only" << endl;
if(strlen(pFormat->SpecificationURL()))
cout << "Specification at: " << pFormat->SpecificationURL() << endl;
}
else
cout << "Format type: " << pID << " was not recognized" <<endl;
}
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=='-')