本文整理汇总了C++中OBConversion::ReadString方法的典型用法代码示例。如果您正苦于以下问题:C++ OBConversion::ReadString方法的具体用法?C++ OBConversion::ReadString怎么用?C++ OBConversion::ReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBConversion
的用法示例。
在下文中一共展示了OBConversion::ReadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testTetrahedralStereo1
void testTetrahedralStereo1()
{
cout << "testTetrahedralStereo1()" << endl;
// read a smiles string
OBMol mol;
OBConversion conv;
OB_REQUIRE( conv.SetInFormat("smi") );
cout << "smiles: C[[email protected]](O)N" << endl;
OB_REQUIRE( conv.ReadString(&mol, "C[[email protected]](O)N") );
// get the stereo data
OB_REQUIRE( mol.HasData(OBGenericDataType::StereoData) );
std::vector<OBGenericData *> stereoData = mol.GetAllData(OBGenericDataType::StereoData);
OB_REQUIRE( stereoData.size() == 1 );
// convert to tetrahedral data
OB_REQUIRE( ((OBStereoBase*)stereoData[0])->GetType() == OBStereo::Tetrahedral );
OBTetrahedralStereo *ts = dynamic_cast<OBTetrahedralStereo*>(stereoData[0]);
OB_REQUIRE( ts );
// print the configuration
cout << *ts << endl;
// construct a valid configuration here
//
// C[[email protected]](O)N
// 0 1 2 3 4 <- ids
//
OBTetrahedralStereo::Config cfg(1, 0, OBStereo::MakeRefs(4, 3, 2), OBStereo::Clockwise);
// compare stereochemistry
OB_REQUIRE( ts->GetConfig() == cfg );
cout << endl;
}
示例2: testIsomorphism1
void testIsomorphism1()
{
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.ReadString(&mol, "CC1CCC(C)CC1");
OBQuery *query = CompileMoleculeQuery(&mol);
OBIsomorphismMapper *mapper = OBIsomorphismMapper::GetInstance(query);
OBIsomorphismMapper::Mappings maps;
mapper->MapAll(&mol, maps);
OB_ASSERT( maps.size() == 4 );
delete query;
delete mapper;
query = CompileSmilesQuery("C1(C)CCC(C)CC1");
mapper = OBIsomorphismMapper::GetInstance(query);
OBIsomorphismMapper::Mapping map;
mapper->MapFirst(&mol, map);
OB_ASSERT( map.size() == 8 );
mapper->MapUnique(&mol, maps);
OB_ASSERT( maps.size() == 1 );
mapper->MapAll(&mol, maps);
OB_ASSERT( maps.size() == 4 );
delete query;
delete mapper;
}
示例3: 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" );
}
}
示例4: test_Issue178_DeleteHydrogens
// Delete hydrogens should not remove charged or isotopic hydrogens or [H][H] or [Cu][H][Cu]
// or hydrogens with assigned atom classes
void test_Issue178_DeleteHydrogens()
{
OBConversion conv;
conv.SetInFormat("smi");
OBMol mol;
// Test DeleteHydrogens() and DeleteNonPolarHydrogens()
static const char *smi[] = { "C[H]", "[H][H]", "C[1H]", "C[H]C", "C[H+]" };
int numHs[] = { 0, 2, 1, 1, 1 };
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 2; ++j) {
conv.ReadString(&mol, smi[i]);
if (j == 0)
mol.DeleteHydrogens();
else
mol.DeleteNonPolarHydrogens();
int myNumHs = 0;
FOR_ATOMS_OF_MOL(atom, mol)
if (atom->IsHydrogen())
myNumHs++;
OB_COMPARE(myNumHs, numHs[i]);
}
}
// Test DeletePolarHydrogens()
static const char *smiB[] = { "N[H]", "[H][H]", "N[1H]", "N[H]C", "N[H+]" };
int numHsB[] = { 0, 2, 1, 1, 1 };
for (int i = 0; i < 5; ++i) {
conv.ReadString(&mol, smiB[i]);
mol.DeletePolarHydrogens();
int myNumHs = 0;
FOR_ATOMS_OF_MOL(atom, mol)
if (atom->IsHydrogen())
myNumHs++;
OB_COMPARE(myNumHs, numHsB[i]);
}
// Test atom class
// Currently, the SMILES parser does not retain atom classes for hydrogens on reading so...
conv.ReadString(&mol, "C[H]");
OBAtomClassData *ac = new OBAtomClassData;
ac->Add(2, 99); // Assign the hydrogen (atom 2) a class of 99
mol.SetData(ac);
mol.DeleteHydrogens();
int myNumHs = 0;
FOR_ATOMS_OF_MOL(atom, mol)
if (atom->IsHydrogen())
myNumHs++;
OB_COMPARE(myNumHs, 1);
}
示例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: testAutomorphismPreMapping
void testAutomorphismPreMapping()
{
cout << "testAutomorphismPreMapping" << endl;
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.ReadString(&mol, "c1(C)c(C)c(C)c(C)c(C)c1");
Automorphisms aut;
FindAutomorphisms((OBMol*)&mol, aut);
cout << aut.size() << endl;
OB_ASSERT( aut.size() == 2 );
}
示例7: 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");
}
示例8: 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;
}
示例9: testIsomorphism4
void testIsomorphism4()
{
cout << "testIsomorphism4" << endl;
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.ReadString(&mol, "C12C(C2)C1");
OBQuery *query = CompileSmilesQuery("C1CC1");
OBIsomorphismMapper *mapper = OBIsomorphismMapper::GetInstance(query);
OBIsomorphismMapper::Mappings maps;
mapper->MapUnique(&mol, maps);
cout << maps.size() << endl;
OB_ASSERT( maps.size() == 2 );
delete query;
delete mapper;
}
示例10: main
int main()
{
// Create an OBConversion object.
OBConversion conv;
// Set the input format.
if (!conv.SetInFormat("smi")) {
// Handle error.
return 1;
}
// Create the OBMol object.
OBMol mol;
// Read the smiles string.
if (conv.ReadString(&mol, "CCCC")) {
// Handle error.
return 1;
}
// ...Use OBMol object...
}
示例11: 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';
}
示例12: readSmiString
bool OBReader::readSmiString(QString smiString)
{
using namespace OpenBabel;
OBConversion conv;
if (!conv.SetInFormat("smi"))
{
qDebug() << "Error in conv.SetInFormat().";
return false;
}
OBMol obMol;
if (!conv.ReadString(&obMol, smiString.toStdString()))
{
qDebug() << "Error occured while reading the smi string.";
return false;
}
if (!obMol.Has3D())
{
if (!buildGeometry(&obMol))
{
qDebug() << "Error in buildGeometry()";
return false;
}
}
if (!toMolecule(&obMol))
{
qDebug() << "Could not convert OBMol to Molecule.";
return false;
}
return true;
}
示例13: 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 );
}
示例14: 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';
}
}
示例15: Do
//.........这里部分代码省略.........
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
for(unsigned i=0;i<ExtraMols.size();++i)
queries.push_back(CompileMoleculeQuery(static_cast<OBMol*>(ExtraMols[i])));
ExtraMols.clear();
}
if(vec.size()>1 && vec[1]=="exact")
{
if(queries.empty())
{
//Convert SMARTS to SMILES to count number of atoms
OBConversion conv;
OBMol patmol;
if(!conv.SetInFormat("smi") || !conv.ReadString(&patmol, vec[0]))
{
obErrorLog.ThrowError(__FUNCTION__, "Cannot read the parameter of -s option, "
"which has to be valid SMILES when the exact option is used.", obError, onceOnly);
delete pmol;
if(pConv)
pConv->SetOneObjectOnly(); //stop conversion
return false;
}
nPatternAtoms = patmol.NumHvyAtoms();
}
}
else
nPatternAtoms = 0;
//disable old versions
if(pConv)
pConv->AddOption(GetID(), OBConversion::GENOPTIONS, "");
}
bool match = false;
//These are a vector of each mapping, each containing atom indxs.
vector<vector<int> > vecatomvec;
vector<vector<int> >* pMappedAtoms = NULL;
if(nPatternAtoms)
if(pmol->NumHvyAtoms() != nPatternAtoms)
return false;
unsigned int imol=0; //index of mol in pattern file
if(!queries.empty()) //filename supplied
{
//match is set true if any of the structures match - OR behaviour