11#ifndef RD_MOLSUPPLIER_H
12#define RD_MOLSUPPLIER_H
27#ifdef RDK_BUILD_THREADSAFE_SSS
31#ifdef RDK_BUILD_MAEPARSER_SUPPORT
32namespace schrodinger {
114 virtual std::unique_ptr<RWMol>
next() = 0;
146 std::ifstream *strm =
147 new std::ifstream(filename.c_str(), std::ios_base::binary);
148 if ((!(*strm)) || strm->bad()) {
149 std::ostringstream errout;
150 errout <<
"Bad input file " << filename;
155 if (strm->bad() || strm->eof()) {
156 std::ostringstream errout;
157 errout <<
"Invalid input file " << filename;
161 return static_cast<std::istream *
>(strm);
167#if !defined(__clang__) && defined(__GNUC__)
168#pragma GCC diagnostic push
169#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
173template <
typename Supplier>
220#if !defined(__clang__) && defined(__GNUC__)
221#pragma GCC diagnostic pop
236 std::istream *inStream,
bool takeOwnership =
true,
243 std::unique_ptr<RWMol>
next()
override;
245 return std::shared_ptr<RWMol>(this->
next());
257 "Cannot create an iterator for a ForwardSDMolSupplier that has already "
276 std::ranges::input_range<ForwardSDMolSupplier>
281template <
typename Supplier>
350 return this->supplier == other.
supplier &&
382 const std::string &fileName,
386 std::istream *inStream,
bool takeOwnership =
true,
392 std::unique_ptr<RWMol>
next()
override;
430 void checkForEnd()
override;
431 void peekCheckForEnd(
char *bufPtr,
char *bufEnd, std::streampos molStartPos);
432 void buildIndexTo(
unsigned int targetIdx);
435 std::vector<std::streampos> d_molpos;
436 bool d_cacheMolecules =
false;
437 std::vector<std::optional<std::shared_ptr<RWMol>>> d_molCache;
438#ifdef RDK_BUILD_THREADSAFE_SSS
439 std::mutex d_readMutex;
440 std::mutex d_cacheMutex;
445 std::ranges::random_access_range<SDMolSupplier>
488 const std::string &fileName,
492 std::istream *inStream,
bool takeOwnership =
true,
500 std::unique_ptr<RWMol>
next()
override;
521 std::unique_ptr<RWMol> processLine(std::string inLine);
522 void processTitleLine();
523 std::string nextLine();
524 long int skipComments();
532 std::vector<std::streampos>
534 std::vector<int> d_lineNums;
536 bool d_cacheMolecules =
false;
537 std::vector<std::optional<std::shared_ptr<RWMol>>> d_molCache;
538#ifdef RDK_BUILD_THREADSAFE_SSS
539 std::mutex d_readMutex;
540 std::mutex d_cacheMutex;
583 const std::string &fileName,
586 std::istream *inStream,
bool takeOwnership =
true,
594 std::unique_ptr<RWMol>
next()
override;
616 bool advanceToNextRecord();
618 std::unique_ptr<RWMol> parseMol(std::string inLine);
624 std::vector<std::streampos>
627 bool d_cacheMolecules =
false;
628 std::vector<std::optional<std::shared_ptr<RWMol>>> d_molCache;
629#ifdef RDK_BUILD_THREADSAFE_SSS
630 std::mutex d_readMutex;
631 std::mutex d_cacheMutex;
635#ifdef RDK_BUILD_MAEPARSER_SUPPORT
636struct MaeMolSupplierParams {
637 bool sanitize =
true;
638 bool removeHs =
true;
651 explicit MaeMolSupplier(
652 std::shared_ptr<std::istream> inStream,
653 const MaeMolSupplierParams ¶ms = MaeMolSupplierParams());
655 explicit MaeMolSupplier(
656 std::istream *inStream,
bool takeOwnership =
true,
657 const MaeMolSupplierParams ¶ms = MaeMolSupplierParams());
659 explicit MaeMolSupplier(
660 const std::string &fname,
661 const MaeMolSupplierParams ¶ms = MaeMolSupplierParams());
663 ~MaeMolSupplier()
override {}
665 void init()
override;
666 void reset()
override;
667 std::unique_ptr<RWMol> next()
override;
668 bool atEnd()
override;
669 void moveTo(
unsigned int idx);
670 std::unique_ptr<RWMol> operator[](
unsigned int idx);
672 unsigned int length();
674 void close()
override { dp_sInStream.reset(); }
676 void setData(
const std::string &text,
677 const MaeMolSupplierParams ¶ms = MaeMolSupplierParams());
680 void moveToNextBlock();
683 MaeMolSupplierParams d_params;
684 std::shared_ptr<schrodinger::mae::Reader> d_reader;
685 std::shared_ptr<schrodinger::mae::Block> d_next_struct;
686 std::shared_ptr<std::istream> dp_sInStream;
687 std::string d_stored_exc;
Defines the primary molecule class ROMol as well as associated typedefs.
used by various file parsing classes to indicate a bad file
ForwardSDMolSupplier(std::istream *inStream, bool takeOwnership=true, const MolFileParserParams ¶ms=MolFileParserParams())
bool getProcessPropertyLists() const
void setProcessPropertyLists(bool val)
~ForwardSDMolSupplier() override
bool df_processPropertyLists
std::unique_ptr< RWMol > _next()
MolFileParserParams d_params
std::shared_ptr< RWMol > nextShared()
virtual void checkForEnd()
ForwardSupplierIter< ForwardSDMolSupplier > iterator
bool getEOFHitOnRead() const
virtual void readMolProps(ROMol &)
std::unique_ptr< RWMol > next() override
std::istream * openAndCheckStream(const std::string &filename)
virtual std::unique_ptr< RWMol > next()=0
std::istream * dp_inStream
void moveTo(unsigned int idx)
void setStreamIndices(const std::vector< std::streampos > &locs)
~SDMolSupplier() override
void setData(const std::string &text)
reverse_iterator rbegin()
std::reverse_iterator< iterator > reverse_iterator
std::unique_ptr< RWMol > next() override
SDMolSupplier(std::istream *inStream, bool takeOwnership=true, const MolFileParserParams ¶ms=MolFileParserParams())
RandomAccessSupplierIter< SDMolSupplier > iterator
std::string getItemText(unsigned int idx)
returns the text block for a particular item
std::shared_ptr< RWMol > getShared(unsigned int idx)
!
void setData(const std::string &text, const MolFileParserParams ¶ms)
SDMolSupplier(const std::string &fileName, const MolFileParserParams ¶ms=MolFileParserParams())
std::unique_ptr< RWMol > operator[](unsigned int idx)
void setCaching(bool val)
~SmilesMolSupplier() override
void setCaching(bool val)
std::string getItemText(unsigned int idx)
returns the text block for a particular item
std::shared_ptr< RWMol > getShared(unsigned int idx)
std::unique_ptr< RWMol > next() override
SmilesMolSupplier(std::istream *inStream, bool takeOwnership=true, const SmilesMolSupplierParams ¶ms=SmilesMolSupplierParams())
std::unique_ptr< RWMol > operator[](unsigned int idx)
SmilesMolSupplier(const std::string &fileName, const SmilesMolSupplierParams ¶ms=SmilesMolSupplierParams())
reverse_iterator rbegin()
void moveTo(unsigned int idx)
RandomAccessSupplierIter< SmilesMolSupplier > iterator
std::reverse_iterator< iterator > reverse_iterator
void setData(const std::string &text, const SmilesMolSupplierParams ¶ms=SmilesMolSupplierParams())
std::unique_ptr< RWMol > operator[](unsigned int idx)
~TDTMolSupplier() override
void setData(const std::string &text, const TDTMolSupplierParams ¶ms=TDTMolSupplierParams())
void setCaching(bool val)
TDTMolSupplier(const std::string &fileName, const TDTMolSupplierParams ¶ms=TDTMolSupplierParams())
std::reverse_iterator< iterator > reverse_iterator
RandomAccessSupplierIter< TDTMolSupplier > iterator
std::string getItemText(unsigned int idx)
returns the text block for a particular item
TDTMolSupplier(std::istream *inStream, bool takeOwnership=true, const TDTMolSupplierParams ¶ms=TDTMolSupplierParams())
std::shared_ptr< RWMol > getShared(unsigned int idx)
reverse_iterator rbegin()
void moveTo(unsigned int idx)
std::unique_ptr< RWMol > next() override
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
#define RDKIT_FILEPARSERS_EXPORT
RDKIT_FILEPARSERS_EXPORT std::string strip(const std::string &orig)
std::vector< std::string > STR_VECT
const std::shared_ptr< RWMol > const_value_type
ForwardSupplierIter & operator++()
std::optional< value_type > current
std::input_iterator_tag iterator_category
ForwardSupplierIter()=default
ForwardSDMolSupplier * supplier
ForwardSupplierIter(const ForwardSupplierIter &)=default
bool operator==(const ForwardSupplierIter &other) const
std::shared_ptr< RWMol > value_type
std::ptrdiff_t difference_type
ForwardSupplierIter(Supplier *supplier)
ForwardSupplierIter(ForwardSupplierIter &&)=default
const_value_type operator*() const
ForwardSupplierIter & operator=(const ForwardSupplierIter &)=default
ForwardSupplierIter & operator=(ForwardSupplierIter &&)=default
ForwardSupplierIter operator++(int)
RandomAccessSupplierIter(const RandomAccessSupplierIter &)=default
RandomAccessSupplierIter(Supplier *supplier)
std::random_access_iterator_tag iterator_category
RandomAccessSupplierIter & operator++()
RandomAccessSupplierIter operator-(difference_type n) const
const std::shared_ptr< RWMol > const_value_type
std::shared_ptr< RWMol > value_type
const_value_type operator[](size_t idx) const
const_value_type operator*() const
RandomAccessSupplierIter operator+(difference_type n) const
std::ptrdiff_t difference_type
RandomAccessSupplierIter & operator=(RandomAccessSupplierIter &&)=default
bool operator==(const RandomAccessSupplierIter &other) const
RandomAccessSupplierIter(Supplier *supplier, size_t idx)
RandomAccessSupplierIter(RandomAccessSupplierIter &&)=default
friend RandomAccessSupplierIter operator+(difference_type n, const RandomAccessSupplierIter &it)
auto operator<=>(const RandomAccessSupplierIter &other) const
RandomAccessSupplierIter()=default
RandomAccessSupplierIter & operator=(const RandomAccessSupplierIter &)=default
RandomAccessSupplierIter operator--(int)
RandomAccessSupplierIter & operator+=(difference_type n)
RandomAccessSupplierIter & operator--()
difference_type operator-(const RandomAccessSupplierIter &other) const
RandomAccessSupplierIter operator++(int)
RandomAccessSupplierIter & operator-=(difference_type n)
v2::SmilesParse::SmilesParserParams parseParameters
v2::SmilesParse::SmilesParserParams parseParameters