本文整理汇总了C++中OBMol::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::Clear方法的具体用法?C++ OBMol::Clear怎么用?C++ OBMol::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckValidDipeptide
void CheckValidDipeptide(OBConversion &conv,
const string &test,
unsigned int testCount)
{
OBMol mol;
OBResidue *res;
ostringstream os;
mol.Clear();
conv.ReadString(&mol, test);
chainsparser.PerceiveChains(mol);
if (mol.NumResidues() != 2) {
os << "not ok " << testCount << " # expected 2 residues, but found "
<< mol.NumResidues() << '\n';
os << "# ";
FOR_RESIDUES_OF_MOL(res, mol)
os << res->GetName() << " ";
os << endl;
BOOST_CHECK_MESSAGE( 0, os.str().c_str() );
} else {
res = mol.GetResidue(0);
BOOST_CHECK_MESSAGE( res, "Get first AA from dipeptide" );
res = mol.GetResidue(1);
BOOST_CHECK_MESSAGE( res, "Get second AA from dipeptide" );
}
}
示例2: GenerateFormulaReference
void GenerateFormulaReference()
{
std::ifstream ifs;
if (!SafeOpen(ifs, smilestypes_file.c_str()))
return;
std::ofstream ofs;
if (!SafeOpen(ofs, results_file.c_str()))
return;
OBMol mol;
OBConversion conv(&ifs, &cout);
if(! conv.SetInAndOutFormats("SMI","SMI"))
{
cerr << "SMILES format is not loaded" << endl;
return;
}
for (;ifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
//write out formula, molecular weight and exact mass
ofs << mol.GetFormula() << " " << mol.GetMolWt() << " "
<< mol.GetExactMass() << endl;
}
cerr << " Molecular formula results written successfully" << endl;
return;
}
示例3: aromatic_test
void aromatic_test()
{
cout << endl << "# Testing aromaticity perception... " << endl;
string filename = "files/aromatics.smi";
ifstream ifs(filename.c_str());
BOOST_REQUIRE_MESSAGE( ifs, "Bail out! Cannot read input file!" );
OBConversion conv(&ifs, &cout);
OBFormat* pFormat;
pFormat = conv.FormatFromExt(filename.c_str());
BOOST_REQUIRE_MESSAGE( pFormat != NULL, "Bail out! Cannot read file format!" );
// Finally, we can do some work!
OBMol mol;
unsigned int testCount = 0;
BOOST_REQUIRE_MESSAGE( conv.SetInAndOutFormats(pFormat, pFormat), "Bail out! File format isn't loaded");
int molCount = 0;
char message[BUFF_SIZE];
while(ifs.peek() != EOF && ifs.good())
{
mol.Clear();
conv.Read(&mol);
molCount++;
FOR_ATOMS_OF_MOL(atom, mol)
{
if (atom->IsHydrogen())
continue;
testCount++;
snprintf(message, BUFF_SIZE, "not ok %d # atom isn't aromatic!\n"
"# atom idx %d in molecule %d %s",
testCount, atom->GetIdx(), molCount, mol.GetTitle());
BOOST_CHECK_MESSAGE( atom->IsAromatic(), message );
}
FOR_BONDS_OF_MOL(bond, mol)
{
if (!bond->IsInRing())
continue;
testCount++;
snprintf(message, BUFF_SIZE, "not ok %d # bond isn't aromatic!\n"
"# begin atom %d, end atom %d, bond order %d in molecule %d %s",
testCount, bond->GetBeginAtomIdx(), bond->GetEndAtomIdx(),
bond->GetBondOrder(), molCount, mol.GetTitle());
BOOST_CHECK_MESSAGE( bond->IsAromatic(), message );
}
} // while reading molecules
}
示例4: WriteAgents
static void WriteAgents(OBMol& mol, OBReactionFacade& rxnfacade, OBConversion* pconv, OBFormat* pformat)
{
for(unsigned int i=0; i<rxnfacade.NumComponents(AGENT); i++) {
mol.Clear();
rxnfacade.GetComponent(&mol, AGENT, i);
WriteMolFile(&mol, pconv, pformat);
}
}
示例5: 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(&cin, &cout);
OBFormat *inFormat = conv.FormatFromExt(FileIn);
if (!inFormat || !conv.SetInFormat(inFormat)) {
cerr << program_name << ": cannot read input format!" << endl;
exit (-1);
}
// If we can't also use this for an output format, use XYZ
if (!conv.SetOutFormat(inFormat))
conv.SetOutFormat(conv.FindFormat("xyz"));
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
pg.Setup(&mol);
cerr << "Point Group: " << pg.IdentifyPointGroup() << endl;
pg.Symmetrize(&mol);
conv.Write(&mol, &cout);
} // end for loop
return(1);
}
示例6: GenerateCharges
void GenerateCharges()
{
std::ifstream ifs;
if (!SafeOpen(ifs, molecules_file.c_str()))
return;
std::ofstream rofs;
if (!SafeOpen(rofs, results_file.c_str()))
return;
std::ofstream dofs;
if (!SafeOpen(dofs, dipole_file.c_str()))
return;
OBMol mol;
OBConversion conv(&ifs, &cout);
char buffer[BUFF_SIZE];
if(! conv.SetInAndOutFormats("SDF","SDF"))
{
cerr << "SDF format is not loaded" << endl;
return;
}
OBChargeModel *pCM = OBChargeModel::FindType("mmff94");
if (pCM == NULL) {
cerr << "Cannot load charge model!" << endl;
return;
}
std::vector<double> partialCharges;
vector3 dipoleMoment;
for (;ifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
if (pCM->ComputeCharges(mol)) {
partialCharges = pCM->GetPartialCharges();
}
// write out the dipole moment
dipoleMoment = pCM->GetDipoleMoment(mol);
sprintf(buffer, "%15.5f%15.5f%15.5f\n", dipoleMoment.x(), dipoleMoment.y(), dipoleMoment.z());
dofs << buffer;
// and write all the partial charges
FOR_ATOMS_OF_MOL(atom, mol) {
sprintf(buffer, "%15.5f\n", atom->GetPartialCharge());
rofs << buffer;
}
}
示例7: 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);
}
示例8: ReadPQS_geom
int ReadPQS_geom(istream &ifs, OBMol &mol, const char *title,
int input_style, double bohr_to_angstrom)
{
int atom_count=0;
double x, y, z;
char buffer[BUFF_SIZE];
string str;
OBAtom *atom;
vector<string> vs;
mol.Clear();
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE) && !card_found(buffer))
{
if (buffer[0]!='$')
{
tokenize(vs, buffer);
if (vs.size() < 1) return false; // timvdm 18/06/2008
atom=mol.NewAtom();
str=vs[0];
if (input_style==0)
{
if (vs.size() < 4) return false; // timvdm 18/06/2008
atom->SetAtomicNum(OBElements::GetAtomicNum(str.c_str()));
x=atof((char*) vs[1].c_str())*bohr_to_angstrom;
y=atof((char*) vs[2].c_str())*bohr_to_angstrom;
z=atof((char*) vs[3].c_str())*bohr_to_angstrom;
}
else
{
if (vs.size() < 5) return false; // timvdm 18/06/2008
str.replace (0,2,"");
atom->SetAtomicNum(OBElements::GetAtomicNum(str.c_str()));
x=atof((char*) vs[2].c_str())*bohr_to_angstrom;
y=atof((char*) vs[3].c_str())*bohr_to_angstrom;
z=atof((char*) vs[4].c_str())*bohr_to_angstrom;
}
atom->SetVector(x, y, z);
atom_count++;
}
}
mol.ConnectTheDots();
mol.PerceiveBondOrders();
mol.EndModify();
mol.SetTitle(title);
return atom_count;
}
示例9: GenerateEnergies
void GenerateEnergies()
{
std::ifstream ifs;
if (!SafeOpen(ifs, molecules_file.c_str()))
return;
std::ofstream ofs;
if (!SafeOpen(ofs, results_file.c_str()))
return;
OBMol mol;
OBConversion conv(&ifs, &cout);
char buffer[BUFF_SIZE];
if(! conv.SetInAndOutFormats("SDF","SDF"))
{
cerr << "SDF format is not loaded" << endl;
return;
}
OBForceField* pFF = OBForceField::FindForceField("Ghemical");
if (pFF == NULL) {
cerr << "Cannot load force field!" << endl;
return;
}
pFF->SetLogFile(&cout);
pFF->SetLogLevel(OBFF_LOGLVL_NONE);
for (;ifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
if (!pFF->Setup(mol)) {
cerr << "Could not setup force field on molecule: " << mol.GetTitle() << endl;
return;
}
// Don't compute gradients
sprintf(buffer, "%15.5f\n", pFF->Energy(false));
ofs << buffer;
}
cerr << " Ghemical force field energies written successfully" << endl;
return;
}
示例10: CheckInvalidResidue
void CheckInvalidResidue(OBConversion &conv,
const string &test,
unsigned int testCount)
{
OBMol mol;
mol.Clear();
conv.ReadString(&mol, test);
chainsparser.PerceiveChains(mol);
if (mol.NumResidues() != 0) {
OBResidue *res = mol.GetResidue(0);
if (res->GetName() == "LIG") { // ligand, not residue
cout << "ok " << testCount << " # found ligand, not residue "
<< test << '\n';
} else {
cout << "not ok " << testCount << " # expected 0 residues, found "
<< mol.NumResidues() << '\n';
cout << "# " << res->GetName() << endl;
}
} else
cout << "ok " << testCount << " # correctly rejected " << test << '\n';
}
示例11: CheckInvalidResidue
void CheckInvalidResidue(OBConversion &conv,
const string &test,
unsigned int testCount)
{
OBMol mol;
ostringstream os;
mol.Clear();
conv.ReadString(&mol, test);
chainsparser.PerceiveChains(mol);
if (mol.NumResidues() != 0) {
OBResidue *res = mol.GetResidue(0);
if (res->GetName() == "LIG") { // ligand, not residue
BOOST_CHECK( 1 );
} else {
os << "not ok " << testCount << " # expected 0 residues, found "
<< mol.NumResidues() << '\n';
os << "# " << res->GetName() << endl;
BOOST_CHECK_MESSAGE( 0, os.str().c_str() );
}
} else
BOOST_CHECK( 1 );
}
示例12: CheckValidDipeptide
void CheckValidDipeptide(OBConversion &conv,
const string &test,
unsigned int testCount)
{
OBMol mol;
mol.Clear();
conv.ReadString(&mol, test);
chainsparser.PerceiveChains(mol);
if (mol.NumResidues() != 2) {
cout << "not ok " << testCount << " # expected 2 residues, but found "
<< mol.NumResidues() << '\n';
cout << "# ";
FOR_RESIDUES_OF_MOL(res, mol)
cout << res->GetName() << " ";
cout << endl;
} else {
OBResidue *res;
res = mol.GetResidue(0);
cout << "ok " << testCount << " # " << res->GetName();
res = mol.GetResidue(1);
cout << " " << res->GetName() << '\n';
}
}
示例13: main
int main(int argc,char *argv[])
{
if (argc != 2)
{
cout << "Usage: obrotamer <file>" << endl;
cout << " Outputs the number of rotable bonds and generate a random"
<< " rotamer" << endl;
return(-1);
}
ifstream ifs(argv[1]);
if (!ifs)
{
cerr << "Error! Cannot read input file!" << endl;
return(-1);
}
OBConversion conv(&ifs, &cout);
OBFormat* pFormat;
pFormat = conv.FormatFromExt(argv[1]);
if ( pFormat == NULL )
{
cerr << "Error! Cannot read file format!" << endl;
return(-1);
}
// Finally, we can do some work!
OBMol mol;
if (! conv.SetInAndOutFormats(pFormat, pFormat))
{
cerr << "Error! File format isn't loaded" << endl;
return (-1);
}
OBRotorList rl;
OBRotamerList rotamers;
int *rotorKey = NULL;
OBRandom rand;
rand.TimeSeed();
while(ifs.peek() != EOF && ifs.good())
{
mol.Clear();
conv.Read(&mol);
rl.Setup(mol);
cerr << " Number of rotatable bonds: " << rl.Size() << endl;
// indexed from 1, rotorKey[0] = 0
std::vector<int> rotorKey(rl.Size() + 1, 0);
// each entry represents the configuration of a rotor
// e.g. indexes into OBRotor::GetResolution()
// (the different angles to sample from the OBRotorRules database)
OBRotorIterator ri;
OBRotor *rotor = rl.BeginRotor(ri);
for (int i = 1; i < rl.Size() + 1; ++i, rotor = rl.NextRotor(ri))
rotorKey[i] = rand.NextInt() % rotor->GetResolution().size();
rotamers.SetBaseCoordinateSets(mol);
rotamers.Setup(mol, rl);
rotamers.AddRotamer(rotorKey);
// This is more useful when you have added many rotamers
// rather than the one in this example
rotamers.ExpandConformerList(mol, mol.GetConformers());
// Change the molecule conformation -- from 0 .. rotamers.NumRotamers()
mol.SetConformer(0);
conv.Write(&mol);
} // while reading molecules
return(0);
}
示例14: GenerateSmartsReference
void GenerateSmartsReference()
{
std::ifstream ifs;
if (!SafeOpen(ifs,smarts_file.c_str()))
return;
char buffer[BUFF_SIZE];
vector<OBSmartsPattern*> vsp;
for (;ifs.getline(buffer,BUFF_SIZE);)
{
if (buffer[0] == '#') // skip comment line
continue;
OBSmartsPattern *sp = new OBSmartsPattern;
if (sp->Init(buffer))
vsp.push_back(sp);
else
delete sp;
}
std::ofstream ofs;
if (!SafeOpen(ofs, results_file.c_str()))
return;
ofs << vsp.size() << " patterns" << endl;
std::ifstream mifs;
if (!SafeOpen(mifs, smilestypes_file.c_str()))
return;
vector<int> vm;
vector<vector<int> > mlist;
vector<vector<int> >::iterator j;
vector<OBSmartsPattern*>::iterator i;
OBMol mol;
OBConversion conv(&mifs, &cout);
if(! conv.SetInAndOutFormats("SMI","SMI"))
{
cerr << "SMILES format is not loaded" << endl;
return;
}
for (;mifs;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
continue;
for (i = vsp.begin();i != vsp.end();i++)
{
(*i)->Match(mol);
mlist = (*i)->GetMapList();
for (j = mlist.begin();j != mlist.end();j++)
{
sprintf(buffer,"%3d",*(j->begin()));
ofs << buffer;
}
ofs << endl;
}
}
cerr << " SMARTS test results written successfully" << endl;
return;
}
示例15: WriteMolecule
bool RXNFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if (pmol == NULL || !pmol->IsReaction())
return false;
pConv->AddOption("no$$$$",OBConversion::OUTOPTIONS);
OBFormat* pMolFormat = pConv->FindFormat("MOL");
if(pMolFormat==NULL)
{
obErrorLog.ThrowError(__FUNCTION__, "MDL MOL format not available", obError);
return false;
}
OBReactionFacade rxnfacade(pmol);
HandleAgent handleagent = ReadAgentOption(pConv->IsOption("G"));
bool hasAgent = rxnfacade.NumComponents(AGENT) > 0;
bool agentInReactants, agentInProducts;
if (hasAgent && (handleagent==BOTH_REACT_AND_PROD || handleagent==AS_REACT))
agentInReactants = true;
else
agentInReactants = false;
if (hasAgent && (handleagent==BOTH_REACT_AND_PROD || handleagent==AS_PROD))
agentInProducts = true;
else
agentInProducts = false;
ostream &ofs = *pConv->GetOutStream();
ofs << "$RXN" << '\n';
ofs << pmol->GetTitle() << '\n';
ofs << " OpenBabel" << '\n';
//ofs << pReact->GetComment() << '\n';
ofs << "\n";
ofs << setw(3);
if (agentInReactants)
ofs << rxnfacade.NumComponents(REACTANT) + rxnfacade.NumComponents(AGENT);
else
ofs << rxnfacade.NumComponents(REACTANT);
ofs << setw(3);
if (agentInProducts)
ofs << rxnfacade.NumComponents(PRODUCT) + rxnfacade.NumComponents(AGENT);
else
ofs << rxnfacade.NumComponents(PRODUCT);
if (hasAgent && handleagent==AS_AGENT)
ofs << setw(3) << rxnfacade.NumComponents(AGENT);
ofs << '\n';
// Write reactants
OBMol mol;
for(unsigned int i=0; i<rxnfacade.NumComponents(REACTANT); i++) {
mol.Clear();
rxnfacade.GetComponent(&mol, REACTANT, i);
WriteMolFile(&mol, pConv, pMolFormat);
}
if (agentInReactants)
WriteAgents(mol, rxnfacade, pConv, pMolFormat);
// Write products
for(unsigned int i=0; i<rxnfacade.NumComponents(PRODUCT); i++) {
mol.Clear();
rxnfacade.GetComponent(&mol, PRODUCT, i);
WriteMolFile(&mol, pConv, pMolFormat);
}
if (agentInProducts)
WriteAgents(mol, rxnfacade, pConv, pMolFormat);
// Write agent out (if treating AS_AGENT)
if(hasAgent && handleagent==AS_AGENT)
WriteAgents(mol, rxnfacade, pConv, pMolFormat);
return true;
}