Hi Jarod,

that is correct. Applying a reaction to a molecule may produce more than one 
product (depending on the reaction and reactants), so the method will return a 
vector of products for every reactant (i.e. a vector of vectors of molecules).
Consider adding a nested loop within your loop:

// ...

for (auto& productVector : prods) {
  for (auto& mol : productVector) {
    std::cout << RDKit::MolToSmiles(*mol) << std::endl;
  }
}

// ...

Best,
Chris
________________________________________
From: Jarod Younker <jarod_youn...@hotmail.com>
Sent: Tuesday, December 6, 2022 1:13:11 PM
To: java.jo...@gmail.com
Cc: rdkit-discuss@lists.sourceforge.net
Subject: Re: [Rdkit-discuss] std::vector<boost::shared_ptr<RDKit::ROMol> > 
object (RxnSmarts)

Thank you Garth. Implement the dereference, still getting a compilation error:

test.cpp:37:37: error: no match for ‘operator*’ (operand type is 
‘std::vector<boost::shared_ptr<RDKit::ROMol> >’)
   37 |     std::cout << RDKit::MolToSmiles(*mol) << std::endl;

It looks as if “mol” is still a “vector,” not an element of the range based 
loop.

Sent from my iPhone

On Dec 5, 2022, at 9:16 AM, java.jo...@gmail.com wrote:


I think that you need to deference the pointer (replace mol by *mol):

  for( auto & mol: prods ) {
    std::cout << RDKit::MolToSmiles(*mol) << std::endl;
  }

As indicated by this message:

opt/rdkit-Release_2022_09_2/Code/GraphMol/SmilesParse/SmilesWrite.h:116:45: 
note:   no known conversion for argument 1 from ‘std::vector<boost::shared_pt
r<RDKit::ROMol> >’ to ‘const RDKit::ROMol&’

Cheers,
Gareth

From: Jarod Younker <jarod_youn...@hotmail.com>
Sent: Monday, December 5, 2022 7:32 AM
To: rdkit-discuss@lists.sourceforge.net
Subject: [Rdkit-discuss] std::vector<boost::shared_ptr<RDKit::ROMol> > object 
(RxnSmarts)

 I’m new to C++ RDKit.  How do I perform functions on elements of 
std::vector<boost::shared_ptr<RDKit::ROMol> > object?  I’m struggle to unpack 
it (see highlighted sections below).

P.S. This is simply cut and pasted from the documentation with on addition: 
MolToSmiles()

Thank you, Jarod

 std::string smi="[O:1]>>[N:1]";
  RDKit::ChemicalReaction *rxn = RDKit::RxnSmartsToChemicalReaction(smi);
  rxn->initReactantMatchers();
  RDKit::MOL_SPTR_VECT reacts;
  reacts.clear();
  smi = "OCO";
  RDKit::ROMol *mol = RDKit::SmilesToMol(smi);
  reacts.push_back(RDKit::ROMOL_SPTR(mol));
  std::vector<RDKit::MOL_SPTR_VECT> prods;
  prods = rxn->runReactants(reacts);
  // here prods has two entries, because there are two Os in the
  // reactant.
  for( auto & mol: prods ) {
    std::cout << RDKit::MolToSmiles(mol) << std::endl;
  }

  reacts[0]->getAtomWithIdx(0)->setProp(RDKit::common_properties::_protected,1);
  prods = rxn->runReactants(reacts);
  // here prods only has one entry, the reaction at atom 0
  // has been blocked by the _protected property

test.cpp: In function ‘int main()’:
test.cpp:37:36: error: no matching function for call to 
‘MolToSmiles(std::vector<boost::shared_ptr<RDKit::ROMol> >&)’
   37 |     std::cout << RDKit::MolToSmiles(mol) << std::endl;
      |                  ~~~~~~~~~~~~~~~~~~^~~~~
In file included from test.cpp:5:
/opt/rdkit-Release_2022_09_2/Code/GraphMol/SmilesParse/SmilesWrite.h:96:38: 
note: candidate: ‘std::string RDKit::MolToSmiles(const ROMol&, const SmilesWri
teParams&)’
   96 | RDKIT_SMILESPARSE_EXPORT std::string MolToSmiles(
      |                                      ^~~~~~~~~~~
/opt/rdkit-Release_2022_09_2/Code/GraphMol/SmilesParse/SmilesWrite.h:96:38: 
note:   candidate expects 2 arguments, 1 provided
/opt/rdkit-Release_2022_09_2/Code/GraphMol/SmilesParse/SmilesWrite.h:116:20: 
note: candidate: ‘std::string RDKit::MolToSmiles(const ROMol&, bool, bool, in
t, bool, bool, bool, bool)’
  116 | inline std::string MolToSmiles(const ROMol &mol, bool doIsomericSmiles 
= true,
      |                    ^~~~~~~~~~~
/opt/rdkit-Release_2022_09_2/Code/GraphMol/SmilesParse/SmilesWrite.h:116:45: 
note:   no known conversion for argument 1 from ‘std::vector<boost::shared_pt
r<RDKit::ROMol> >’ to ‘const RDKit::ROMol&’
  116 | inline std::string MolToSmiles(const ROMol &mol, bool doIsomericSmiles 
= true,

Sent from my iPhone

_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to