Here are some of the ways one can interact with MolSuppliers:
1) Lazy (works with forward and random access suppliers): while(!supplier.atEnd()){ auto mol = supplier.next(); // mol is a std::unique_ptr<RWMol> if(mol){ do something; } }
2) Range based for loops (works with forward and random access suppliers): for(auto mol : supplier){ if(mol) { do something; // mol is a shared_ptr<RWMol> } }
3) Random Access: for(int i=0;i<supplier.length();i++){ auto mol = supplier[i]; // mol is a std::unique_ptr<RWMol> if(mol){ do something; } }
4) Random access supplier also support caching: supplier.setCaching(true); for(auto mol : supplier){ if(mol) { do something; // mol is a shared_ptr<RWMol> } } Subsequent iterations will be much faster as the molecules are cached after the first read.
It's also possible to access the cached molecules directly using the getShared method: supplier.setCaching(true); for(int i=0;i<supplier.length();i++){ auto mol = supplier.getShared(i); // mol is a std::shared_ptr<RWMol>; if(mol){ do something; } }
5) Random access suppliers can also be used with parallel algorithms: supplier.setCaching(true); std::for_each(std::execution::par, supplier.begin(), supplier.end(), [](auto mol) { if (mol) { do something; } });
Caching is not required here, but if you are planning on working with the molecules multiple times, it can speed things up significantly.
Definition at line 106 of file MolSupplier.h.