本文整理汇总了C++中OBSmartsPattern::Match方法的典型用法代码示例。如果您正苦于以下问题:C++ OBSmartsPattern::Match方法的具体用法?C++ OBSmartsPattern::Match怎么用?C++ OBSmartsPattern::Match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBSmartsPattern
的用法示例。
在下文中一共展示了OBSmartsPattern::Match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectSMARTS
// Helper function -- handle SMARTS selections
// Called by performAction()
void SelectExtension::selectSMARTS(GLWidget *widget)
{
bool ok;
QString pattern = QInputDialog::getText(qobject_cast<QWidget*>(parent()),
tr("SMARTS Selection"),
tr("SMARTS pattern to select"),
QLineEdit::Normal,
"", &ok);
if (ok && !pattern.isEmpty()) {
OBSmartsPattern smarts;
smarts.Init(pattern.toStdString());
OpenBabel::OBMol obmol = m_molecule->OBMol();
smarts.Match(obmol);
// if we have matches, select them
if(smarts.NumMatches() != 0) {
QList<Primitive *> matchedAtoms;
vector< vector <int> > mapList = smarts.GetUMapList();
vector< vector <int> >::iterator i; // a set of matching atoms
vector<int>::iterator j; // atom ids in each match
for (i = mapList.begin(); i != mapList.end(); ++i) {
for (j = i->begin(); j != i->end(); ++j) {
matchedAtoms.append(m_molecule->atom(obmol.GetAtom(*j)->GetIdx()-1));
}
}
widget->clearSelected();
widget->setSelected(matchedAtoms, true);
widget->update();
} // end matches
}
return;
}
示例2: main
int main() {
OBAtom a, b, c;
a.SetAtomicNum(8);
b.SetAtomicNum(6);
c.SetAtomicNum(8);
OBMol mol;
mol.AddAtom(a);
mol.AddAtom(b);
mol.AddAtom(c);
mol.AddBond(1,2,2);
mol.AddBond(2,3,2);
OBConversion conv;
conv.SetOutFormat("SMI");
cout << conv.WriteString(&mol,1) << endl;
OBSmartsPattern sp;
sp.Init ("C~*");
sp.Match (mol,false);
cout << sp.NumMatches() << endl;
cout << sp.GetUMapList().size() << endl;
return EXIT_SUCCESS;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
};
示例6: 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";
}
}
示例7: 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;
}
示例8: main
///////////////////////////////////////////////////////////////////////////////
//! \brief Find the molecule(s) with or without a given SMART pattern
int main(int argc,char **argv)
{
char c;
unsigned int ntimes=0; // number of times SMARTS matches in a molecule
unsigned int numMatching = 0; // number of matching molecules (for -c flag)
bool pattern_matched=false, ntimes_matched=true;
bool count=false, invert=false, full=false, name_only=false;
char *FileIn = NULL, *Pattern = NULL;
char *program_name = argv[0];
char *iext;
bool useInFile = true;
OBConversion conv(&cin,&cout);
OBFormat *pFormat = conv.FindFormat("smi"); // default format is SMILES
// Parse options
while ((c = getopt(argc, argv, "t:nvcfi:-")) != -1)
{
#ifdef _WIN32
char optopt = c;
#endif
switch (c)
{
case 't': // request ntimes unique matches
c = sscanf(optarg, "%d", &ntimes);
if (c != 1 )
{
cerr << program_name << ": unable to parse -t option" << endl;
exit (-1);
}
break;
case 'i':
iext = optarg;
//The ID provided by the OBFormat class is used as
// the identifying file extension. This is a slight
// reduction in flexibility (which is not currently used)
pFormat = conv.FindFormat(iext);
if(pFormat==NULL)
{
cerr << program_name << ": cannot read input format!" << endl;
exit(-1);
}
break;
case 'n': // print the molecule name only
name_only = true;
break;
case 'c': // count the number of match
count = true;
break;
case 'v': // match only the molecules without the pattern
invert = true;
break;
case 'f':
full = true;
break;
case '-':
useInFile = false;
break;
case '?':
if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
}
}
int index = optind;
if (argc-index != 2 && argc-index != 1)
{
string err = "Usage: ";
err += program_name;
err += " [options] \"PATTERN\" <filename>\n";
err += "If no filename is supplied, then obgrep will use stdin instead.\n";
err += "Options:\n";
err += " -v Invert the matching, print non-matching molecules\n";
err += " -c Print the number of matched molecules\n";
err += " -i <format> Specify the input and output format\n";
err += " -f Full match, print matching-molecules when the number\n";
err += " of heavy atoms is equal to the number of PATTERN atoms\n";
err += " -n Only print the name of the molecules\n";
err += " -t NUM Print a molecule only if the PATTERN occurs NUM times inside the molecule\n";
cerr << err << ends;
exit(-1);
}
else
{
Pattern = argv[index++];
//.........这里部分代码省略.........
示例9: main
//.........这里部分代码省略.........
{
// No incompleted jobs. Sleep for a while.
if (!sleeping) cout << local_time() << "Sleeping" << endl;
sleeping = true;
this_thread::sleep_for(chrono::seconds(10));
continue;
}
sleeping = false;
const auto job = value.Obj();
// Obtain job properties.
const auto _id = job["_id"].OID();
cout << local_time() << "Executing job " << _id.str() << endl;
const auto job_path = jobs_path / _id.str();
const auto format = job["format"].String();
const auto email = job["email"].String();
// Parse the user-supplied ligand.
OBMol obMol;
OBConversion obConversion;
obConversion.SetInFormat(format.c_str());
obConversion.ReadFile(&obMol, (job_path / ("ligand." + format)).string());
const auto num_atoms = obMol.NumAtoms();
// obMol.AddHydrogens(); // Adding hydrogens does not seem to affect SMARTS matching.
// Classify subset atoms.
array<vector<int>, num_subsets> subsets;
for (size_t k = 0; k < num_subsets; ++k)
{
auto& subset = subsets[k];
subset.reserve(num_atoms);
OBSmartsPattern smarts;
smarts.Init(SubsetSMARTS[k]);
smarts.Match(obMol);
for (const auto& map : smarts.GetMapList())
{
subset.push_back(map.front());
}
}
const auto& subset0 = subsets.front();
// Check user-provided ligand validity.
if (subset0.empty())
{
// Record job completion time stamp.
const auto millis_since_epoch = duration_cast<std::chrono::milliseconds>(system_clock::now().time_since_epoch()).count();
conn.update(collection, BSON("_id" << _id), BSON("$set" << BSON("done" << Date_t(millis_since_epoch))));
// Send error notification email.
cout << local_time() << "Sending an error notification email to " << email << endl;
MailMessage message;
message.setSender("usr <[email protected]>");
message.setSubject("Your usr job has failed");
message.setContent("Description: " + job["description"].String() + "\nSubmitted: " + to_simple_string(ptime(epoch, boost::posix_time::milliseconds(job["submitted"].Date().millis))) + " UTC\nFailed: " + to_simple_string(ptime(epoch, boost::posix_time::milliseconds(millis_since_epoch))) + " UTC\nReason: failed to parse the provided ligand.");
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, email));
SMTPClientSession session("137.189.91.190");
session.login();
session.sendMessage(message);
session.close();
continue;
}
// Calculate the four reference points.
const auto n = subset0.size();
const auto v = 1.0 / n;
array<vector3, num_references> references{};
示例10: main
///////////////////////////////////////////////////////////////////////////////
//! \brief Set a tortional bond to a given angle
int main(int argc,char **argv)
{
const char *Pattern=NULL;
unsigned int i, t, errflg = 0;
int c;
char flags[255];
string err;
bool graphOutput=false;
// parse the command line -- optional -a flag to change all matching torsions
if (argc < 3 || argc > 4) {
errflg++;
} else {
FileIn = argv[1];
Pattern = "[!$(*#*)&!D1][email protected][!$(*#*)&!D1]";
// Read the atom position
c = sscanf(argv[2], "%d", &angleSum);
angle = 360./angleSum;
if (argc == 4)
{
c = sscanf(argv[3], "%s", flags);
int flagid=1;
while (flags[flagid]!=0)
switch (flags[flagid++])
{
case 'g':
graphOutput=true;
case 'e':
forceField=OBForceField::FindForceField("MMFF94");
isEnergyCalcing=true;
break;
}
}
}
if (errflg) {
cerr << "Usage: rkrotate <filename> <angle> [options]" << endl;
exit(-1);
}
// create pattern
OBSmartsPattern sp;
sp.Init(Pattern);
OBFormat* format = conv.FormatFromExt(FileIn);
if(!(format && conv.SetInAndOutFormats(format, format))) { //in and out formats same
cerr << "obrotate: cannot read and/or write this file format!" << endl;
exit (-1);
} //...NF
//Open the molecule file
ifstream ifs;
// Read the file
ifs.open(FileIn);
if (!ifs) {
cerr << "obrotate: cannot read input file!" << endl;
exit (-1);
}
OBMol mol;
vector< vector <int> > maplist; // list of matched atoms
// vector< vector <int> >::iterator m; // and its iterators
// int tindex;
// Set the angles
for (;;) {
mol.Clear();
//NF ifs >> mol; // Read molecule
conv.Read(&mol,&ifs); //NF
if (mol.Empty())
break;
if (sp.Match(mol)) {
// if match perform rotation
maplist = sp.GetUMapList(); // get unique matches
if (maplist.size() > 1)
cerr << "obrotate: Found " << maplist.size() << " matches." << endl;
energySheet=new MultiVector<double>(degrees=maplist.size(),angleSum);
indexSheet=new int[maplist.size()];
for (int EXO=0;EXO<maplist.size();++EXO)
totalSum*=angleSum+EXO;
// look at all the mapping atom but save only the last one.
turnMol(mol,maplist,maplist.size()-1);
if (graphOutput)
{
ofstream ofs("energyGraph.mlog");
int ind[degrees];
for (int i=0;i<degrees;++i)
ind[i]=0;
do
{
for (int i=0;i<degrees;++i)
ofs<<ind[i]<<'\t';
ofs<<energySheet->getVectorValue(ind)<<endl;
//.........这里部分代码省略.........
示例11: Do
//.........这里部分代码省略.........
nPatternAtoms = patmol.NumHvyAtoms();
}
}
else
nPatternAtoms = 0;
//disable old versions
pConv->AddOption(GetID(), OBConversion::GENOPTIONS, "");
}
bool match;
//These are a vector of each mapping, each containing atom indxs.
vector<vector<int> > vecatomvec;
vector<vector<int> >* pMappedAtoms = NULL;
OBSmartsPattern sp;
if(nPatternAtoms)
if(pmol->NumHvyAtoms() != nPatternAtoms)
return false;
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
for(qiter=queries.begin();qiter!=queries.end();++qiter, ++imol)
{
OBIsomorphismMapper* mapper = OBIsomorphismMapper::GetInstance(*qiter);
OBIsomorphismMapper::Mappings mappings;
mapper->MapUnique(pmol, mappings);
if( (match = !mappings.empty()) ) // extra parens to indicate truth value
{
OBIsomorphismMapper::Mappings::iterator ita;
OBIsomorphismMapper::Mapping::iterator itb;
for(ita=mappings.begin(); ita!=mappings.end();++ita)//each mapping
{
vector<int> atomvec;
for(itb=ita->begin(); itb!=ita->end();++itb)//each atom index
atomvec.push_back(itb->second+1);
vecatomvec.push_back(atomvec);
atomvec.clear();
}
pMappedAtoms = &vecatomvec;
break;
}
}
}
else //SMARTS supplied
{
if(!sp.Init(vec[0]))
{
string msg = vec[0] + " 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;
}
if( (match = sp.Match(*pmol)) ) // extra parens to indicate truth value
pMappedAtoms = &sp.GetMapList();
}
if((!match && !inv) || (match && inv))
{
//delete a non-matching mol
delete pmol;
pmol = NULL;
return false;
}
if(!inv && vec.size()>=2 && !vec[1].empty() && !nPatternAtoms)
{
vector<vector<int> >::iterator iter;
if(vec[1]=="extract")
{
//Delete all unmatched atoms. Use only the first match
ExtractSubstruct(pmol, *pMappedAtoms->begin());
return true;
}
// color the substructure if there is a second parameter which is not "exact" or "extract"
// with multiple color parameters use the one corresponding to the query molecule, or the last
if(imol>vec.size()-2)
imol = vec.size()-2;
for(iter=pMappedAtoms->begin();iter!=pMappedAtoms->end();++iter)//each match
AddDataToSubstruct(pmol, *iter, "color", vec[imol+1]);
return true;
}
if(pConv && pConv->IsLast())
{
for(qiter=queries.begin();qiter!=queries.end();++qiter)
delete *qiter;
queries.clear();
}
return true;
}
示例12: 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;
}
}
示例13: 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
//.........这里部分代码省略.........
示例14: 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];
//.........这里部分代码省略.........
示例15: 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);
if (argc != 1)
{
cout << "Usage: smilesmatch\n";
cout << " Tests Open Babel SMILES/SMARTS pattern matching." << endl;
return 0;
}
cout << endl << "# Testing SMILES self-matching using SMARTS... \n";
std::ifstream mifs;
if (!SafeOpen(mifs, smilestypes_file.c_str()))
{
cout << "Bail out! Cannot read test data " << smilestypes_file << endl;
return -1; // test failed
}
OBConversion conv(&mifs, &cout);
if (! conv.SetInAndOutFormats("SMI","SMI"))
{
cout << "Bail out! SMILES format is not loaded" << endl;
return -1;
}
unsigned int currentMol = 0;
OBSmartsPattern smarts;
OBMol mol;
string buffer;
//read in molecules and see if their SMARTS matches themselves
while (getline(mifs, buffer))
{
mol.Clear();
conv.ReadString(&mol, buffer);
if (mol.Empty())
continue;
// trim off any title, etc.
string::size_type pos = buffer.find_first_of(" \t\n\r");
if (pos != string::npos)
buffer.erase(pos);
pos = buffer.find_first_of('.');
if (pos != string::npos)
continue;
smarts.Init(buffer);
if (smarts.Match(mol))
cout << "ok " << ++currentMol << " # SMARTS matched the"
<< " SMILES molecule\n";
else
cout << "not ok " << ++currentMol << " # SMARTS did not match"
<< " for molecule " << buffer << "\n";
}
// output the number of tests run
cout << "1.." << currentMol << endl;
// Passed Test
return 0;
}