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


C++ OBConversion::Read方法代码示例

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


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

示例1: tmpStr

extern "C" char *
ob_strip_salts (char *smiles, int neutralize_residue)
{
  OBAtom atom;
  OBMol mol, largestFragment;
  OBConversion conv;
  string tmpStr (smiles);
  string outstring;
  istringstream molstream1 (tmpStr);
  ostringstream molstream2;
  vector<OBMol> fragments;
  vector <OBMol>::const_iterator i;
  char *tmpMolfile;
  int max = 0;

  conv.SetInAndOutFormats ("SMI", "SMI");

  conv.Read (&mol, &molstream1);

  fragments = mol.Separate();
  
  for( i = fragments.begin(); i != fragments.end(); i++ ) {
    if (i->NumAtoms() > max) {
      max=i->NumAtoms();
      largestFragment = *i;
    }
  }       
 
  if(neutralize_residue != 0) {
    largestFragment.ConvertDativeBonds();
    FOR_ATOMS_OF_MOL(atom, largestFragment) {
      atom->SetFormalCharge(0);
    }
开发者ID:RitaDo,项目名称:pgchem,代码行数:33,代码来源:obwrapper.cpp

示例2: readOutputFile

  void InputFileExtension::readOutputFile(const QString filename)
  {
    QApplication::setOverrideCursor(Qt::WaitCursor);
    OBConversion conv;
    OBFormat     *inFormat = conv.FormatFromExt( filename.toAscii() );
    if ( !inFormat || !conv.SetInFormat( inFormat ) ) {
      QApplication::restoreOverrideCursor();
      QMessageBox::warning(m_widget, tr("Avogadro"),
        tr("Cannot read file format of file %1.").arg(filename));
      return;
    }

    // TODO: Switch to MoleculeFile
    ifstream ifs;
    ifs.open(QFile::encodeName(filename));
    if (!ifs) { // shouldn't happen, already checked file above
      QApplication::restoreOverrideCursor();
      QMessageBox::warning(m_widget, tr("Avogadro"),
        tr("Cannot read file %1.").arg( filename ) );
      return;
    }

    OBMol *obmol = new OBMol;
    if (conv.Read(obmol, &ifs)) {
      Molecule *mol = new Molecule;
      mol->setOBMol(obmol);
      mol->setFileName(filename);
      emit moleculeChanged(mol, Extension::DeleteOld);
      m_molecule = mol;
    }

    QApplication::restoreOverrideCursor();
  }
开发者ID:annulen,项目名称:avogadro,代码行数:33,代码来源:inputfileextension.cpp

示例3: MakeQueriesFromMolInFile

bool MakeQueriesFromMolInFile(vector<OBQuery*>& queries, const std::string& filename, int* pnAtoms, bool noH)
{
    OBMol patternMol;
    patternMol.SetIsPatternStructure();
    OBConversion patternConv;
    OBFormat* pFormat;
    //Need to distinguish between filename and SMARTS. Not infallable...
    if( filename.empty() ||
        filename.find('.')==string::npos ||
        !(pFormat = patternConv.FormatFromExt(filename.c_str())) ||
        !patternConv.SetInFormat(pFormat) ||
        !patternConv.ReadFile(&patternMol, filename) ||
        patternMol.NumAtoms()==0)
      return false;

    if(noH)
      patternMol.DeleteHydrogens();

    do
    {
      *pnAtoms = patternMol.NumHvyAtoms();
      queries.push_back(CompileMoleculeQuery(&patternMol));
    }while(patternConv.Read(&patternMol));
    return true;
}
开发者ID:CooperLiu,项目名称:openbabel,代码行数:25,代码来源:opisomorph.cpp

示例4: ifs

// Helper function to read molecule from file
shared_ptr<OBMol> GetMol(const std::string &filename)
{
  // Create the OBMol object.
  shared_ptr<OBMol> mol(new OBMol);

  // Create the OBConversion object.
  OBConversion conv;
  OBFormat *format = conv.FormatFromExt(filename.c_str());
  if (!format || !conv.SetInFormat(format)) {
    std::cout << "Could not find input format for file " << filename << std::endl;
    return mol;
  }

  // Open the file.
  std::ifstream ifs(filename.c_str());
  if (!ifs) {
    std::cout << "Could not open " << filename << " for reading." << std::endl;
    return mol;
  }
  // Read the molecule.
  if (!conv.Read(mol.get(), &ifs)) {
    std::cout << "Could not read molecule from file " << filename << std::endl;
    return mol;
  }

  return mol;
}
开发者ID:Acpharis,项目名称:openbabel,代码行数:28,代码来源:obconformersearch_default.cpp

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

示例6: testAutomorphismMask

void testAutomorphismMask() {
  // read file: 3 6-rings
  //
  //     /\ /\ /\
  //    |  |  |  |
  //     \/ \/ \/
  //
  cout <<  "testAutomorphismMask" << endl;
  OBMol mol;
  OBConversion conv;
  conv.SetInFormat("cml");
  std::ifstream ifs(OBTestUtil::GetFilename("isomorphism1.cml").c_str());
  OB_REQUIRE( ifs );
  conv.Read(&mol, &ifs);

  OBIsomorphismMapper::Mappings maps;

  // First of all, how many automorphisms are there without any mask?
  // This takes about 20 seconds, so you may want to comment this out while debugging
  FindAutomorphisms(&mol, maps);
  cout << maps.size() << endl;
  OB_ASSERT( maps.size() == 4 );

  // Now, let's remove the bridge (atomId 6) of the central ring.
  //
  //     /\ /\ /\
  //    |  |  |  |
  //     \/    \/
  // both rings can be flipped around exocyclic bond, the whole molecule can be mirrored
  // horizontally, this results in 2 x 2 x 2 = 8 automorphisms
  OBBitVec mask;
  mask.SetRangeOn(1, mol.NumAtoms());
  mask.SetBitOff(6+1);
  FindAutomorphisms(&mol, maps, mask);
  cout << maps.size() << endl;
  for (unsigned int i = 0; i < maps.size(); ++i) {
    OBIsomorphismMapper::Mapping::const_iterator j;
    for (j = maps[i].begin(); j != maps[i].end(); ++j)
      cout << j->second << " ";
    cout << endl;
  }
  OB_ASSERT( maps.size() == 8 );

  // Verify that atom Id 6 does not occur anywhere in the mappings
  OBIsomorphismMapper::Mappings::const_iterator a;
  OBIsomorphismMapper::Mapping::const_iterator b;
  for (a = maps.begin(); a != maps.end(); ++a)
    for (b = a->begin(); b!= a->end(); ++b) {
      OB_ASSERT( b->first != 6 );
      OB_ASSERT( b->second != 6 );
    }
}
开发者ID:Acpharis,项目名称:openbabel,代码行数:52,代码来源:isomorphismtest.cpp

示例7: main

int main(int argc, char **argv)
{
  OBFunctionFactory *factory = OBFunctionFactory::GetFactory("MMFF94");
  OBFunction *function = factory->NewInstance();
  if (!function) {
    cout << "ERROR: could not find MMFF94 function" << endl;
    return -1;
  }

  if (argc < 2) {
    cout << "Usage: " << argv[0] << " <filename>" << endl;
    return -1;    
  }

  OBMol mol;
  OBConversion conv;
  OBFormat *format = conv.FormatFromExt(argv[1]);
  if (!format || !conv.SetInFormat(format)) {
    cout << "ERROR: could not find format for file " << argv[1] << endl;
    return -1;
  }

  std::ifstream ifs;
  ifs.open(argv[1]);
  conv.Read(&mol, &ifs);
  ifs.close();

  cout << "# atoms = " << mol.NumAtoms() << endl;
  function->GetLogFile()->SetOutputStream(&std::cout);
  function->GetLogFile()->SetLogLevel(OBLogFile::Low);

  // read options file
  if (argc == 3) {
    std::ifstream cifs;
    cifs.open(argv[2]);
    std::stringstream options;
    std::string line;
    while (std::getline(cifs, line))
      options << line << std::endl;

    function->SetOptions(options.str());
  }


  function->Setup(mol);

  OBMinimize minimize(function);

  minimize.SteepestDescent(50);


}
开发者ID:eajfpeters,项目名称:OBForceField,代码行数:52,代码来源:minimize.cpp

示例8: testIsomorphismMask

void testIsomorphismMask()
{
  // read file: 3 6-rings
  //
  //     /\ /\ /\
  //    |  |  |  |
  //     \/ \/ \/
  //
  OBMol mol;
  OBConversion conv;
  conv.SetInFormat("cml");
  std::ifstream ifs(OBTestUtil::GetFilename("isomorphism1.cml").c_str());
  OB_REQUIRE( ifs );
  conv.Read(&mol, &ifs);

  OBQuery *query = CompileSmilesQuery("C1CCCCC1");
  OBIsomorphismMapper *mapper = OBIsomorphismMapper::GetInstance(query);

  // no mask
  OBIsomorphismMapper::Mappings maps;
  mapper->MapUnique(&mol, maps);
  cout << maps.size() << endl;
  OB_ASSERT( maps.size() == 3 );

  // mask first ring
  OBBitVec mask;
  for (int i = 0; i < 6; ++i)
    mask.SetBitOn(i+1);
  mapper->MapUnique(&mol, maps, mask);
  cout << maps.size() << endl;
  OB_ASSERT( maps.size() == 1 );

  // mask second ring also
  for (int i = 6; i < 10; ++i)
    mask.SetBitOn(i+1);
  mapper->MapUnique(&mol, maps, mask);
  cout << maps.size() << endl;
  OB_ASSERT( maps.size() == 2 );

  // just mask last ring (atomIds 7-8, 10-13)
  mask.Clear();
  for (int i = 10; i < 14; ++i)
    mask.SetBitOn(i+1);
  mask.SetBitOn(7 + 1); mask.SetBitOn(8 + 1);
  mapper->MapUnique(&mol, maps, mask);
  cout << maps.size() << endl;
  OB_ASSERT( maps.size() == 1 ); // Should be same result as masking just the first ring

  delete query;
  delete mapper;
}
开发者ID:Acpharis,项目名称:openbabel,代码行数:51,代码来源:isomorphismtest.cpp

示例9: instring

char *serializeMolecule(const char *molecule) {
    string instring(molecule);
    string outstring;
    istringstream inStream(instring);

    LibHandler ob_lib;

    if (!ob_lib.isLoaded()) {
        return NULL;
    }

    OBMol mol;
    OBConversion conv;
    conv.SetInFormat(MOLECULE_TYPE);
    conv.Read(&mol,&inStream);

    return serializeOBMol(mol);
}
开发者ID:studur,项目名称:mychem-code,代码行数:18,代码来源:conversion_wrapper.cpp

示例10: main

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: " << argv[0] << " filename" << std::endl;
    return -1;
  }

  // read a molecule
  OBConversion conv;
  OBFormat *format = conv.FormatFromExt(argv[1]);
  conv.SetInFormat(format);

  std::string filename(argv[1]);
  std::ifstream ifs;
  ifs.open(filename.c_str());
  if (!ifs) {
    std::cerr << "Could not open " << filename << std::endl;
    return -1;
  }

  CairoPainter *painter = new CairoPainter;
  OBDepict depictor(painter);
 
  string::size_type pos = filename.find_last_of(".");
  if (pos != string::npos)
    filename = filename.substr(0, pos);

  OBMol mol;
  unsigned int count = 1;
  while (conv.Read(&mol, &ifs)) {
    // depict the molecule
    depictor.DrawMolecule(&mol);
    depictor.AddAtomLabels(OBDepict::AtomSymmetryClass);
    
    std::stringstream ss;
    ss << filename << count << ".png";
    painter->WriteImage(ss.str());

    count++;
  }

  return 0;
}
开发者ID:timvdm,项目名称:OBDepict,代码行数:43,代码来源:cairodepict.cpp

示例11: testAutomorphismMask2

void testAutomorphismMask2()
{
  // The test molecule is progesterone, a steroid (four fused non-planar rings)
  cout <<  "testAutomorphismMask2" << endl;
  OBMol mol;
  OBConversion conv;

  conv.SetInFormat("sdf");
  std::ifstream ifs(OBTestUtil::GetFilename("progesterone.sdf").c_str());
  OB_REQUIRE( ifs );
  OB_REQUIRE( conv.Read(&mol, &ifs) );

  Automorphisms _aut;
  OBBitVec _frag_atoms;
  FOR_ATOMS_OF_MOL(a, mol) {
    if(!(a->IsHydrogen()))
      _frag_atoms.SetBitOn(a->GetIdx());
  }
  FindAutomorphisms((OBMol*)&mol, _aut, _frag_atoms);
  OB_ASSERT( _aut.size() == 1 );

}
开发者ID:Acpharis,项目名称:openbabel,代码行数:22,代码来源:isomorphismtest.cpp

示例12: verifyLSSR

bool verifyLSSR(const std::string &filename, const LSSR &ref)
{
  cout << "Verify LSSR: " << filename << endl;
  std::string file = OBTestUtil::GetFilename(filename);
  // read a smiles string
  OBMol mol;
  OBConversion conv;
  OBFormat *format = conv.FormatFromExt(file.c_str());
  OB_REQUIRE( format );
  OB_REQUIRE( conv.SetInFormat(format) );

  std::ifstream ifs;
  ifs.open(file.c_str());
  OB_REQUIRE( ifs );
  OB_REQUIRE( conv.Read(&mol, &ifs) );

  std::vector<int> ringSizeCount(20, 0); 
  std::vector<OBRing*> lssr = mol.GetLSSR();

  for (unsigned int i = 0; i < lssr.size(); ++i) {
    ringSizeCount[lssr[i]->_path.size()]++;
  }

  /*
  cout << "ringSize: ringCount" << endl;
  cout << "3: " << ringSizeCount[3] << endl;
  cout << "4: " << ringSizeCount[4] << endl;
  cout << "5: " << ringSizeCount[5] << endl;
  cout << "6: " << ringSizeCount[6] << endl;
  */

  bool fail = false;
  for (unsigned int i = 0; i < ref.size_count.size(); ++i) {
    const LSSR::Size_Count &size_count = ref.size_count[i];
    OB_ASSERT( ringSizeCount[size_count.ringSize] == size_count.ringCount );
  }

  return true;
}
开发者ID:Reinis,项目名称:openbabel,代码行数:39,代码来源:lssrtest.cpp

示例13: doShuffleTestMultiFile

bool doShuffleTestMultiFile(const std::string &filename)
{
  cout << "Shuffling: " << filename << endl;
  std::string file = OBTestUtil::GetFilename(filename);
  // read a smiles string
  OBMol mol;
  OBConversion conv;
  OBFormat *format = conv.FormatFromExt(file.c_str());
  OB_REQUIRE( format );
  OB_REQUIRE( conv.SetInFormat(format) );

  std::ifstream ifs;
  ifs.open(file.c_str());
  OB_REQUIRE( ifs );
 
  bool result = true;
  while (conv.Read(&mol, &ifs)) {
    bool res = doShuffleTestMolecule(mol);
    if (!res)
      result = res;
  }

  return result;
}
开发者ID:Reinis,项目名称:openbabel,代码行数:24,代码来源:lssrtest.cpp

示例14: main

int main(int argc, char **argv)
{
  if (argc < 3) {
    std::cerr << "Usage: " << argv[0] << " <molecule_file> <output_score_file>" << std::endl;
    return 1;
  }

  unsigned long numAtoms = 0;
  unsigned long numAromaticAtoms = 0;
  unsigned long numCyclicAtoms = 0;
  std::map<int, unsigned long> mass;
  std::map<int, unsigned long> elem;
  std::map<int, unsigned long> aromelem;
  std::map<int, unsigned long> aliphelem;
  std::map<int, unsigned long> hcount;
  std::map<int, unsigned long> charge;
  std::map<int, unsigned long> connect;
  std::map<int, unsigned long> degree;
  std::map<int, unsigned long> implicit;
  std::map<int, unsigned long> rings;
  std::map<int, unsigned long> size;
  std::map<int, unsigned long> valence;
  std::map<int, unsigned long> chiral;
  std::map<int, unsigned long> hyb;
  std::map<int, unsigned long> ringconnect;

  unsigned long numBonds = 0;
  unsigned long numSingleBonds = 0;
  unsigned long numDoubleBonds = 0;
  unsigned long numTripleBonds = 0;
  unsigned long numAromaticBonds = 0;
  unsigned long numRingBonds = 0;

  OBConversion conv;
  conv.SetInFormat(conv.FormatFromExt(argv[1]));
  std::ifstream ifs(argv[1]);
  conv.SetInStream(&ifs);

  OBMol mol;
  unsigned long molecule = 0;
  while (conv.Read(&mol)) {
    ++molecule;
    //if ((molecule % 1000) == 0)
    //  std::cout << molecule << std::endl;

    FOR_ATOMS_OF_MOL (atom, mol) {
      numAtoms++;
      if (atom->IsAromatic()) {
        numAromaticAtoms++;
        aromelem[atom->GetAtomicNum()]++;
      } else
        aliphelem[atom->GetAtomicNum()]++;
      if (atom->IsInRing())
        numCyclicAtoms++;
      mass[atom->GetIsotope()]++;
      elem[atom->GetAtomicNum()]++;
      hcount[atom->ExplicitHydrogenCount() + atom->ImplicitHydrogenCount()]++;
      charge[atom->GetFormalCharge()]++;
      connect[atom->GetImplicitValence()]++;
      degree[atom->GetValence()]++;
      implicit[atom->ImplicitHydrogenCount()]++;
      rings[atom->MemberOfRingCount()]++;
      for (int i = 3; i < 25; ++i)
        if (atom->IsInRingSize(i))
          size[i]++;
      valence[atom->KBOSum() - (atom->GetSpinMultiplicity() ? atom->GetSpinMultiplicity() - 1 : 0)]++;
      hyb[atom->GetHyb()]++;
      ringconnect[atom->CountRingBonds()]++;    
    }

    FOR_BONDS_OF_MOL (bond, mol) {
      numBonds++;
      if (bond->IsSingle())
        numSingleBonds++;
      else if (bond->IsDouble())
        numDoubleBonds++;
      else if (bond->IsTriple())
        numTripleBonds++;
      if (bond->IsAromatic())
        numAromaticBonds++;
      if (bond->IsInRing())
        numRingBonds++;;
    }
开发者ID:timvdm,项目名称:SmartsCompiler,代码行数:83,代码来源:smartsscores.cpp

示例15: main

///////////////////////////////////////////////////////////////////////////////
//! \brief  Generate rough 3D coordinates for SMILES (or other 0D files).
//
int main(int argc,char **argv)
{
  char *program_name= argv[0];
  int c;
  string basename, filename = "", option, option2, ff = "MMFF94";

  list<string> argl(argv+1, argv+argc);

  list<string>::iterator optff = find(argl.begin(), argl.end(), "-ff");
  if (optff != argl.end()) {
    list<string>::iterator optffarg = optff;
    ++optffarg;

    if (optffarg != argl.end()) {
      ff = *optffarg;

      argl.erase(optff,++optffarg);
    } else {
      argl.erase(optff);
    }
  }

  if (argl.empty()) {
    cout << "Usage: obgen <filename> [options]" << endl;
    cout << endl;
    cout << "options:      description:" << endl;
    cout << endl;
    cout << "  -ff         select a forcefield" << endl;
    cout << endl;
    OBPlugin::List("forcefields", "verbose");
    exit(-1);
  }

  basename = filename = *argl.begin();
  size_t extPos = filename.rfind('.');

  if (extPos!= string::npos) {
    basename = filename.substr(0, extPos);
  }

  // Find Input filetype
  OBConversion conv;
  OBFormat *format_in = conv.FormatFromExt(filename.c_str());
  OBFormat *format_out = conv.FindFormat("sdf");

  if (!format_in || !format_out || !conv.SetInAndOutFormats(format_in, format_out)) {
    cerr << program_name << ": cannot read input/output format!" << endl;
    exit (-1);
  }

  ifstream ifs;
  ofstream ofs;

  // Read the file
  ifs.open(filename.c_str());
  if (!ifs) {
    cerr << program_name << ": cannot read input file!" << endl;
    exit (-1);
  }

  OBMol mol;

  for (c=1;;c++) {
      mol.Clear();
      if (!conv.Read(&mol, &ifs))
        break;
      if (mol.Empty())
        break;

      OBForceField* pFF = OBForceField::FindForceField(ff);
      if (!pFF) {
        cerr << program_name << ": could not find forcefield '" << ff << "'." <<endl;
        exit (-1);
      }

      //mol.AddHydrogens(false, true); // hydrogens must be added before Setup(mol) is called

      pFF->SetLogFile(&cerr);
      pFF->SetLogLevel(OBFF_LOGLVL_LOW);

      //pFF->GenerateCoordinates();
      OBBuilder builder;
      builder.Build(mol);

      mol.AddHydrogens(false, true); // hydrogens must be added before Setup(mol) is called
      if (!pFF->Setup(mol)) {
        cerr << program_name << ": could not setup force field." << endl;
        exit (-1);
      }

      pFF->SteepestDescent(500, 1.0e-4);
      pFF->WeightedRotorSearch(250, 50);
      pFF->SteepestDescent(500, 1.0e-6);

      pFF->UpdateCoordinates(mol);
      //pFF->ValidateGradients();
      //pFF->SetLogLevel(OBFF_LOGLVL_HIGH);
//.........这里部分代码省略.........
开发者ID:Reinis,项目名称:openbabel,代码行数:101,代码来源:obgen.cpp


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