当前位置: 首页>>代码示例>>C++>>正文


C++ OBSmartsPattern类代码示例

本文整理汇总了C++中OBSmartsPattern的典型用法代码示例。如果您正苦于以下问题:C++ OBSmartsPattern类的具体用法?C++ OBSmartsPattern怎么用?C++ OBSmartsPattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OBSmartsPattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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);
  
  cout << "# Testing SMARTS Parsing...  \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];
  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;
}
开发者ID:annulen,项目名称:openbabel,代码行数:35,代码来源:smartsparse.cpp

示例2: tokenize

  void OBAromaticTyper::ParseLine(const char *buffer)
  {
    OBSmartsPattern *sp;
    char temp_buffer[BUFF_SIZE];

    if (buffer[0] == '#' || !*buffer) //comment and empty lines
      return;
    vector<string> vs;
    tokenize(vs,buffer);
    if (vs.empty())
      return;

    if (vs.size() == 3)
      {
        strncpy(temp_buffer,vs[0].c_str(), BUFF_SIZE - 1);
        temp_buffer[BUFF_SIZE - 1] = '\0';
        sp = new OBSmartsPattern();
        if (sp->Init(temp_buffer))
          {
            _vsp.push_back(sp);
            _verange.push_back(pair<int,int>
                               (atoi((char*)vs[1].c_str()),
                                atoi((char*)vs[2].c_str())));
          }
        else
          {
            obErrorLog.ThrowError(__FUNCTION__, " Could not parse line in aromatic typer from aromatic.txt", obInfo);
            delete sp;
            sp = NULL;
            return;
          }
      }
    else
      obErrorLog.ThrowError(__FUNCTION__, " Could not parse line in aromatic typer from aromatic.txt", obInfo);
  }
开发者ID:annulen,项目名称:openbabel,代码行数:35,代码来源:typer.cpp

示例3: 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;
  }    
开发者ID:RitaDo,项目名称:pgchem,代码行数:31,代码来源:matchtest.cpp

示例4: tr

  // 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;
  }
开发者ID:ChrisWilliams,项目名称:avogadro,代码行数:36,代码来源:selectextension.cpp

示例5: strncpy

  void patty::assign_rules(std::vector<std::string> &rules)
  {
    vector<string> vs;
    char buffer[BUFF_SIZE];
    char tmp_str[BUFF_SIZE];
    unsigned int i;
    OBSmartsPattern *sp;

    for ( i = 0 ; i < rules.size() ; i++ )
      {
        strncpy(buffer, rules[i].c_str(), BUFF_SIZE - 1); // leave space for null termination
        if (buffer[0] != '#')
          {
            tokenize(vs,buffer," \t\n");
            if (vs.size() >= 2)
              {
                strncpy(tmp_str,vs[0].c_str(), sizeof(tmp_str) - 1);
                tmp_str[sizeof(tmp_str) - 1] = '\0';
                sp = new OBSmartsPattern;
                sp->Init(tmp_str);
                _sp.push_back(sp);
                smarts.push_back(vs[0]);
                typ.push_back(vs[1]);
              }
          }
      }
  }
开发者ID:Acpharis,项目名称:openbabel,代码行数:27,代码来源:patty.cpp

示例6: getenv

  void patty::read_rules(const string &infile)
  {
    ifstream ifs, ifs1, *ifsP;
    vector<string> vs;
    char buffer[BUFF_SIZE];
    char tmp_str[BUFF_SIZE];
    string patty_dir;
    OBSmartsPattern *sp;

    ifs.open(infile.c_str());
    ifsP= &ifs;
    if (!ifs)
      {
        if (getenv("BABEL_DATADIR") == NULL)
          {
            stringstream errorMsg;
            errorMsg << "The BABEL_DATADIR environment variable is not defined" << endl;
            errorMsg << "Please define it so the program can find " << infile << endl;
            obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obWarning);
            //            exit(0);
          }
        else
          patty_dir = getenv("BABEL_DATADIR");
        patty_dir += FILE_SEP_CHAR;
        patty_dir += infile;
        ifs1.open(patty_dir.c_str());
        ifsP= &ifs1;
        //     if (!ifs1)
        //    {
        //     cerr << "Could not open " << patty_dir << endl;
        //    exit(0);
        // }
      }

    if (!ifsP)
      {
        stringstream errorMsg;
        errorMsg << "Could not open " << patty_dir << endl;
        obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obWarning);
        //        exit(0);
      }
    while (ifsP->getline(buffer,BUFF_SIZE))
      {
        if (buffer[0] != '#')
          {
            tokenize(vs,buffer," \t\n");
            if (vs.size() >= 2)
              {
                strncpy(tmp_str,vs[0].c_str(), sizeof(tmp_str) - 1);
                tmp_str[sizeof(tmp_str) - 1] = '\0';
                sp = new OBSmartsPattern;
                sp->Init(tmp_str);
                _sp.push_back(sp);
                smarts.push_back(vs[0]);
                typ.push_back(vs[1]);
              }
          }
      }
  }
开发者ID:Acpharis,项目名称:openbabel,代码行数:59,代码来源:patty.cpp

示例7: tokenize

  void OBPhModel::ParseLine(const char *buffer)
  {
    vector<string> vs;
    OBSmartsPattern *sp;

    if (buffer[0] == '#')
      return;

    if (EQn(buffer,"TRANSFORM",7))
      {
        tokenize(vs,buffer);
        if (vs.size() < 5)
          {
            obErrorLog.ThrowError(__FUNCTION__, " Could not parse line in phmodel table from phmodel.txt", obInfo);
            return;
          }

        OBChemTsfm *tsfm = new OBChemTsfm;
        if (!tsfm->Init(vs[1],vs[3]))
          {
            delete tsfm;
            tsfm = NULL;
            obErrorLog.ThrowError(__FUNCTION__, " Could not parse line in phmodel table from phmodel.txt", obInfo);
            return;
          }

        _vtsfm.push_back(tsfm);
        _vpKa.push_back(atof(vs[4].c_str()));
      }
    else if (EQn(buffer,"SEEDCHARGE",10))
      {
        tokenize(vs,buffer);
        if (vs.size() < 2)
          {
            obErrorLog.ThrowError(__FUNCTION__, " Could not parse line in phmodel table from phmodel.txt", obInfo);
            return;
          }

        sp = new OBSmartsPattern;
        if (!sp->Init(vs[1]) || (vs.size()-2) != sp->NumAtoms())
          {
            delete sp;
            sp = NULL;
            obErrorLog.ThrowError(__FUNCTION__, " Could not parse line in phmodel table from phmodel.txt", obInfo);
            return;
          }

        vector<double> vf;
        vector<string>::iterator i;
        for (i = vs.begin()+2;i != vs.end();++i)
          vf.push_back(atof((char*)i->c_str()));

        _vschrg.push_back(pair<OBSmartsPattern*,vector<double> > (sp,vf));
      }
  }
开发者ID:nextmovesoftware,项目名称:openbabel,代码行数:55,代码来源:phmodel.cpp

示例8: 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;
    }
开发者ID:Clyde-fare,项目名称:openbabel,代码行数:12,代码来源:smartsdescriptors.cpp

示例9: ReadStringFromFilter

/** 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;
}
开发者ID:annulen,项目名称:openbabel,代码行数:24,代码来源:filters.cpp

示例10: 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;
  };
开发者ID:RitaDo,项目名称:pgchem,代码行数:45,代码来源:fingerpc8.cpp

示例11: while

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;
}
开发者ID:candycode,项目名称:openbabel,代码行数:43,代码来源:groupcontrib.cpp

示例12: 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";
	}
}
开发者ID:mguetlein,项目名称:OBDistance,代码行数:19,代码来源:CheckSmarts.cpp

示例13: ReadStringFromFilter

/** 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;
}
开发者ID:Reinis,项目名称:openbabel,代码行数:26,代码来源:filters.cpp

示例14: 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;
}
开发者ID:Reinis,项目名称:openbabel,代码行数:43,代码来源:smartsparse.cpp

示例15: tokenize

  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;
          }
      }
  }
开发者ID:baoilleach,项目名称:openbabel-svn-mirror,代码行数:40,代码来源:bondtyper.cpp


注:本文中的OBSmartsPattern类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。