本文整理汇总了C++中OBSmartsPattern::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ OBSmartsPattern::Init方法的具体用法?C++ OBSmartsPattern::Init怎么用?C++ OBSmartsPattern::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBSmartsPattern
的用法示例。
在下文中一共展示了OBSmartsPattern::Init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Predict
double Predict(OBBase* pOb, string* param=NULL)
{
OBMol* pmol = dynamic_cast<OBMol*> (pOb);
if(!pmol)
return 0;
OBSmartsPattern sp;
if (sp.Init(_smarts) && sp.Match(*pmol))
return sp.GetUMapList().size();
else
return 0.0;
}
示例2: Compare
/** The descriptor name can be s or smarts and is case independent
The operator to return true for a match can be:
one or more spaces, =, ==, or nothing if the SMARTS string
starts with a letter.
To return true for a mismatch the operator is !=
A space or tab should follow the SMARTS string.
**/
bool SmartsFilter::Compare(OBBase* pOb, istream& optionText, bool noEval)
{
OBMol* pmol = dynamic_cast<OBMol*> (pOb);
if(!pmol)
return false;
string smarts;
bool matchornegate = ReadStringFromFilter(optionText, smarts);
if(noEval)
return false;
OBSmartsPattern sp;
sp.Init(smarts);
bool ret = sp.Match(*pmol,true);//single match
if(!matchornegate)
ret = !ret;
return ret;
}
示例3: GetFingerprint
bool GetFingerprint(OBBase* pOb, vector<unsigned int>&fp, int nbits)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
unsigned int o=0;
unsigned int m=0;
unsigned int i=0;
unsigned int n=0;
if(!pmol)
return false;
//Read patterns file if it has not been done already
if(smartsStrings.empty())
ReadPatternFile(_patternsfile, smartsStrings);
//Make fp size the smallest power of two to contain the patterns
//unsigned int n=Getbitsperint();
//while(n<smartsStrings.size())n*=2;
//fp.resize(n/Getbitsperint());
fp.resize(16);
for(n=0;n<smartsStrings.size();++n)
{
OBSmartsPattern sp;
sp.Init(smartsStrings[n]);
if(sp.Match(*pmol)) {
m=sp.GetUMapList().size();
//m=sp.NumMatches();
o=n*8;
for(i=0;i<8;++i) {
if(i<m) {SetBit(fp, o+i);
//cout << "1";
}
//cout << endl;
}
}
}
if(nbits)
Fold(fp, nbits);
return true;
};
示例4: checkSmarts
void CheckSmarts::checkSmarts() {
OBSmartsPattern smartsPattern;
for (unsigned int i = 0; i < data->num_smarts(); i++) {
cout << *data->get_smarts(i) << "\t[ ";
for (unsigned int j = 0; j < data->num_smiles(); j++) {
smartsPattern.Init(*data->get_smarts(i));
if (smartsPattern.Match(*data->get_mol(j), true))
cout << data->get_id(j) << " ";
}
cout << "]\n";
}
}
示例5: smartsparse
int smartsparse(int argc, char* argv[])
{
int defaultchoice = 1;
int choice = defaultchoice;
if (argc > 1) {
if(sscanf(argv[1], "%d", &choice) != 1) {
printf("Couldn't parse that input as a number\n");
return -1;
}
}
cout << "# Testing SMARTS Parsing... \n";
std::ifstream ifs;
if (!SafeOpen(ifs, nsmarts_file.c_str()))
{
cout << "Bail out! Cannot read " << nsmarts_file << endl;
return -1; // test failed
}
//read in the SMARTS test patterns
char buffer[BUFF_SIZE];
OBSmartsPattern sp;
unsigned int patterns = 0;
for (;ifs.getline(buffer,BUFF_SIZE);)
{
if (buffer[0] == '#') // skip comment line
continue;
if (sp.Init(buffer))
cout << "ok " << ++patterns << endl;
else
cout << "not ok " << ++patterns << " failed on " << buffer << endl;
}
ifs.close();
// output the number of tests run
cout << "1.." << patterns << endl;
// Passed Test
return 0;
}
示例6: Compare
/** The descriptor name can be s or smarts and is case independent
The operator to return true for a match can be:
one or more spaces, =, ==, or nothing if the SMARTS string
starts with a letter.
To return true for a mismatch the operator is !=
A space or tab should follow the SMARTS string.
**/
bool SmartsFilter::Compare(OBBase *pOb, istream &optionText, bool noEval,
std::string *) {
OBMol *pmol = dynamic_cast<OBMol *>(pOb);
if (!pmol)
return false;
string smarts;
bool matchornegate = ReadStringFromFilter(optionText, smarts);
if (noEval)
return false;
OBSmartsPattern sp;
if (!sp.Init(smarts))
return false; // can't initialize the SMARTS, so fail gracefully
bool ret = sp.Match(*pmol, true); // single match
if (!matchornegate)
ret = !ret;
return ret;
}
示例7: ParseFile
bool OBGroupContrib::ParseFile(const char *filename)
{
OBSmartsPattern *sp;
// open data file
ifstream ifs;
if (OpenDatafile(ifs, filename).length() == 0) {
obErrorLog.ThrowError(__FUNCTION__, " Could not find contribution data file.", obError);
return false;
}
vector<string> vs;
bool heavy = false;
char buffer[80];
while (ifs.getline(buffer, 80)) {
if (EQn(buffer, "#", 1)) continue;
if (EQn(buffer, ";heavy", 6))
heavy = true;
else if (EQn(buffer, ";", 1)) continue;
tokenize(vs, buffer);
if (vs.size() < 2)
continue;
sp = new OBSmartsPattern;
if (sp->Init(vs[0])) {
if (heavy)
_contribsHeavy.push_back(pair<OBSmartsPattern*, double> (sp, atof(vs[1].c_str())));
else
_contribsHydrogen.push_back(pair<OBSmartsPattern*, double> (sp, atof(vs[1].c_str())));
} else {
delete sp;
sp = NULL;
obErrorLog.ThrowError(__FUNCTION__, " Could not parse SMARTS from contribution data file", obInfo);
return false;
}
}
return true;
}
示例8: ParseLine
void OBBondTyper::ParseLine(const char *buffer)
{
vector<string> vs;
vector<int> bovector;
OBSmartsPattern *sp;
if (buffer[0] != '#')
{
tokenize(vs,buffer);
// Make sure we actually have a SMARTS pattern plus at least one triple
// and make sure we have the correct number of integers
if (vs.empty() || vs.size() < 4)
return; // just ignore empty (or short lines)
else if (!vs.empty() && vs.size() >= 4 && (vs.size() % 3 != 1))
{
stringstream errorMsg;
errorMsg << " Error in OBBondTyper. Pattern is incorrect, found "
<< vs.size() << " tokens." << endl;
errorMsg << " Buffer is: " << buffer << endl;
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obInfo);
return;
}
sp = new OBSmartsPattern;
if (sp->Init(vs[0]))
{
for (unsigned int i = 1; i < vs.size() ; ++i)
{
bovector.push_back( atoi((char *)vs[i].c_str()) );
}
_fgbonds.push_back(pair<OBSmartsPattern*,vector<int> >
(sp, bovector));
}
else
{
delete sp;
sp = NULL;
}
}
}
示例9: ParseLine
void OBRingTyper::ParseLine(const char *buffer)
{
vector<string> vs;
OBSmartsPattern *sp;
if (EQn(buffer,"RINGTYP",7)) {
tokenize(vs,buffer);
if (vs.empty() || vs.size() < 3) {
obErrorLog.ThrowError(__FUNCTION__, " Could not parse RING line in ring type table from ringtyp.txt", obInfo);
return;
}
sp = new OBSmartsPattern;
if (sp->Init(vs[2]))
_ringtyp.push_back(pair<OBSmartsPattern*,string> (sp,vs[1]));
else {
delete sp;
sp = NULL;
obErrorLog.ThrowError(__FUNCTION__, " Could not parse RING line in ring type table from ringtyp.txt", obInfo);
return;
}
}
}
示例10: 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);
// Define location of file formats for testing
#ifdef FORMATDIR
char env[BUFF_SIZE];
snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
putenv(env);
#endif
if (argc != 1)
{
if (strncmp(argv[1], "-g", 2))
{
cout << "Usage: smartstest\n";
cout << " Tests Open Babel SMILES/SMARTS pattern matching." << endl;
return 0;
}
else
{
GenerateSmartsReference();
return 0;
}
}
cout << endl << "# Testing SMARTS... \n";
std::ifstream ifs;
if (!SafeOpen(ifs, smarts_file.c_str()))
{
cout << "Bail out! Cannot read " << smarts_file << endl;
return -1; // test failed
}
//read in the SMARTS test patterns
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;
}
ifs.close();
std::ifstream rifs;
if (!SafeOpen(rifs, results_file.c_str()))
{
cout << "Bail out! Cannot read in results file " << results_file << endl;
return -1; // test failed
}
unsigned int npats;
rifs.getline(buffer,BUFF_SIZE);
sscanf(buffer,"%d %*s",&npats);
//make sure the number of SMARTS patterns is the same as in the
//reference data
if (npats != vsp.size())
{
cout << "Bail out! Correct number of patterns not read in" <<
"Read in " << vsp.size() << " expected " << npats << endl;
return -1; // test failed
}
std::ifstream mifs;
if (!SafeOpen(mifs, smilestypes_file.c_str()))
{
cout << "Bail out! Cannot read atom types " << smilestypes_file << endl;
return -1; // test failed
}
unsigned int k;
unsigned int res_line = 0;
OBMol mol;
vector<string> vs;
vector<OBSmartsPattern*>::iterator i;
vector<vector<int> > mlist;
unsigned int currentMol = 0; // each molecule is a separate test
bool molPassed = true;
OBConversion conv(&mifs, &cout);
if (! conv.SetInAndOutFormats("SMI","SMI"))
{
cout << "Bail out! SMILES format is not loaded" << endl;
return -1;
}
//read in molecules, match SMARTS, and compare results to reference data
for (;mifs;)
{
mol.Clear();
conv.Read(&mol);
//.........这里部分代码省略.........
示例11: 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;
}
示例12: main
int main(int argc, char* argv[])
{
const array<string, 5> SmartsPatterns =
{
"[!#1]", // heavy
"[#6+0!$(*~[#7,#8,F]),SH0+0v2,s+0,S^3,Cl+0,Br+0,I+0]", // hydrophobic
"[a]", // aromatic
"[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N&v3;H1,H2]-[!$(*=[O,N,P,S])]),$([N;v3;H0]),$([n,o,s;+0]),F]", // acceptor
"[N!H0v3,N!H0+v4,OH+0,SH+0,nH+0]", // donor
};
OBConversion obConversion;
obConversion.SetInFormat("pdbqt");
while (true)
{
vector<array<double, 3>> atoms;
atoms.reserve(80);
stringstream ss;
for (string line; getline(cin, line);)
{
ss << line << endl;
const auto record = line.substr(0, 6);
if (record == "TORSDO") break;
if (record != "ATOM " && record != "HETATM") continue;
atoms.push_back({ stod(line.substr(30, 8)), stod(line.substr(38, 8)), stod(line.substr(46, 8)) });
}
if (atoms.empty()) break;
OBMol obMol;
obConversion.Read(&obMol, &ss);
array<vector<int>, 5> subsets;
for (size_t k = 0; k < 5; ++k)
{
auto& subset = subsets[k];
subset.reserve(atoms.size());
OBSmartsPattern smarts;
smarts.Init(SmartsPatterns[k]);
smarts.Match(obMol);
for (const auto& map : smarts.GetMapList())
{
subset.push_back(map.front() - 1);
}
}
const auto& subset0 = subsets.front();
const auto n = subset0.size();
const auto v = 1.0 / n;
array<double, 3> ctd{};
array<double, 3> cst{};
array<double, 3> fct{};
array<double, 3> ftf{};
for (size_t k = 0; k < 3; ++k)
{
for (const auto i : subset0)
{
const auto& a = atoms[i];
ctd[k] += a[k];
}
ctd[k] *= v;
}
double cst_dist = numeric_limits<double>::max();
double fct_dist = numeric_limits<double>::lowest();
double ftf_dist = numeric_limits<double>::lowest();
for (const auto i : subset0)
{
const auto& a = atoms[i];
const auto this_dist = dist2(a, ctd);
if (this_dist < cst_dist)
{
cst = a;
cst_dist = this_dist;
}
if (this_dist > fct_dist)
{
fct = a;
fct_dist = this_dist;
}
}
for (const auto i : subset0)
{
const auto& a = atoms[i];
const auto this_dist = dist2(a, fct);
if (this_dist > ftf_dist)
{
ftf = a;
ftf_dist = this_dist;
}
}
for (const auto& subset : subsets)
{
const auto n = subset.size();
const auto v = 1.0 / n;
for (const auto& rpt : { ctd, cst, fct, ftf })
{
vector<double> dists(n);
for (size_t i = 0; i < n; ++i)
{
dists[i] = sqrt(dist2(atoms[subset[i]], rpt));
}
array<double, 3> m{};
for (size_t i = 0; i < n; ++i)
{
const auto d = dists[i];
//.........这里部分代码省略.........
示例13: main
//.........这里部分代码省略.........
ifstream ifs;
if (useInFile && FileIn != NULL)
{
// Read the file
ifs.open(FileIn);
if (!ifs)
{
cerr << program_name << ": cannot read input file!" << endl;
exit (-1);
}
conv.SetInStream(&ifs);
// Find Input filetype
if (pFormat == NULL) {
pFormat = conv.FormatFromExt(FileIn);
if (pFormat == NULL)
{
cerr << program_name << ": cannot read input format!" << endl;
return (-1);
}
}
}
if (! conv.SetInAndOutFormats(pFormat, pFormat))
{
cerr << program_name << ": cannot read or write to this file format" << endl;
return (-1);
}
// Match the SMART
OBSmartsPattern sp;
vector< vector <int> > maplist; // list of matched atoms
sp.Init(Pattern);
OBMol mol;
bool impossible_match;
// Search for pattern
for (c=0;;)
{
mol.Clear();
conv.Read(&mol);
if (mol.Empty())
break;
////////////////////////////////////////////////////////////////
// Do not loose time trying to match the pattern if the matching
// is impossible.
// It is impossible to make a full match if the number of atoms is
// different
if (full )
impossible_match = (sp.NumAtoms() == mol.NumHvyAtoms()) ? false : true;
else
impossible_match = false;
if (impossible_match)
{ // -> avoid useless SMART matching attempt
if (invert)
{
if (!count)
{
if ( name_only )
cout << mol.GetTitle() << endl;
示例14: DoTransformations
//.........这里部分代码省略.........
{
string attr(txt.substr(0,pos)), val(txt.substr(pos+1));
//Update value if it already exists
OBPairData* dp = dynamic_cast<OBPairData*>(GetData(attr));
if(dp) {
dp->SetValue(val);
dp->SetOrigin(userInput);
}
else {
// Pair did not exist; make new one
dp = new OBPairData;
dp->SetAttribute(attr);
dp->SetValue(val);
dp->SetOrigin(userInput);
SetData(dp);
}
}
}
itr = pOptions->find("add"); //adds new properties from descriptors in list
if(itr!=pOptions->end())
OBDescriptor::AddProperties(this, itr->second);
itr = pOptions->find("delete"); //deletes the specified properties
if(itr!=pOptions->end())
OBDescriptor::DeleteProperties(this, itr->second);
itr = pOptions->find("append"); //Appends values of descriptors or properties to title
if(itr!=pOptions->end())
{
string title(GetTitle());
title += OBDescriptor::GetValues(this, itr->second);
if(ispunct(title[0]))
title[0]=' ';//a leading punct char is used only as a separator, not at start
SetTitle(Trim(title).c_str());
}
//Filter using OBDescriptor comparison and (older) SMARTS tests
//Continue only if previous test was true.
bool fmatch = true;
itr = pOptions->find("filter");
if(itr!=pOptions->end())
{
std::istringstream optionText(itr->second);
fmatch = OBDescriptor::FilterCompare(this, optionText, false);
}
if(fmatch)
{
itr = pOptions->find("v");
if(itr!=pOptions->end() && !itr->second.empty())
{
//inverse match quoted SMARTS string which follows
OBSmartsPattern sp;
sp.Init(itr->second);
fmatch = !sp.Match(*this); //(*pmol) ;
}
}
if(fmatch)
{
itr = pOptions->find("s");
if(itr!=pOptions->end() && !itr->second.empty())
{
//SMARTS filter
//If exactmatch option set (probably in fastsearchformat) the
//number of atoms in the pattern (passed as a string in the option text)
//has to be the same as in the molecule.
itr2 = pOptions->find("exactmatch");
if(itr2!=pOptions->end() && NumHvyAtoms()!=atoi(itr2->second.c_str()))
fmatch=false;
else
{
//match quoted SMARTS string which follows
OBSmartsPattern sp;
sp.Init(itr->second.c_str());
fmatch = sp.Match(*this);
}
}
}
if(!fmatch)
{
//filter failed: delete OBMol and return NULL
delete this;
return NULL;
}
else
{
if(ret==false)
{
obErrorLog.ThrowError(__FUNCTION__, "Error executing an option", obError);
delete this; //added 9March2006
return NULL;
}
else
return this;
}
}
示例15: AssignFunctionalGroupBonds
void OBBondTyper::AssignFunctionalGroupBonds(OBMol &mol)
{
if (!_init)
Init();
OBSmartsPattern *currentPattern;
OBBond *b1, *b2;
OBAtom *a1,*a2, *a3;
double angle, dist1, dist2;
vector<int> assignments;
vector<vector<int> > mlist;
vector<vector<int> >::iterator matches, l;
vector<pair<OBSmartsPattern*, vector<int> > >::iterator i;
unsigned int j;
// Loop through for all the functional groups and assign bond orders
for (i = _fgbonds.begin();i != _fgbonds.end();++i)
{
currentPattern = i->first;
assignments = i->second;
if (currentPattern && currentPattern->Match(mol))
{
mlist = currentPattern->GetUMapList();
for (matches = mlist.begin(); matches != mlist.end(); ++matches)
{
// Now loop through the bonds to assign from _fgbonds
for (j = 0; j < assignments.size(); j += 3)
{
// along the assignments vector: atomID1 atomID2 bondOrder
a1 = mol.GetAtom((*matches)[ assignments[j] ]);
a2 = mol.GetAtom((*matches)[ assignments[j+1 ] ]);
if (!a1 || !a2) continue;
b1 = a1->GetBond(a2);
if (!b1) continue;
b1->SetBO(assignments[j+2]);
} // bond order assignments
} // each match
} // current pattern matches
} // for(functional groups)
// FG with distance and/or bond criteria
// Carbonyl oxygen C=O
OBSmartsPattern carbo; carbo.Init("[#8D1][#6](*)(*)");
if (carbo.Match(mol))
{
mlist = carbo.GetUMapList();
for (l = mlist.begin(); l != mlist.end(); ++l)
{
a1 = mol.GetAtom((*l)[0]);
a2 = mol.GetAtom((*l)[1]);
angle = a2->AverageBondAngle();
dist1 = a1->GetDistance(a2);
// carbonyl geometries ?
if (angle > 115 && angle < 150 && dist1 < 1.28) {
if ( !a1->HasDoubleBond() ) {// no double bond already assigned
b1 = a1->GetBond(a2);
if (!b1 ) continue;
b1->SetBO(2);
}
}
}
} // Carbonyl oxygen
// thione C=S
OBSmartsPattern thione; thione.Init("[#16D1][#6](*)(*)");
if (thione.Match(mol))
{
mlist = thione.GetUMapList();
for (l = mlist.begin(); l != mlist.end(); ++l)
{
a1 = mol.GetAtom((*l)[0]);
a2 = mol.GetAtom((*l)[1]);
angle = a2->AverageBondAngle();
dist1 = a1->GetDistance(a2);
// thione geometries ?
if (angle > 115 && angle < 150 && dist1 < 1.72) {
if ( !a1->HasDoubleBond() ) {// no double bond already assigned
b1 = a1->GetBond(a2);
if (!b1 ) continue;
b1->SetBO(2);
}
}
}
} // thione
// Isocyanate N=C=O or Isothiocyanate
//.........这里部分代码省略.........