.. include:: ../../toolkit-substitutions


.. oe:namespace:: OESiteHopper

.. attention::

      |TWOLANGUAGE|



.. _OESiteHopper_OESiteHopperDatabase:

.. oe:class:: OESiteHopperDatabase

   .. oe:api::


      class OESiteHopperDatabase : public OEShape::OESiteHopperDatabaseBase

  
   This class allows creation and searching of one or more OESiteHopper patches, built
   from OEDesignUnits. When adding data to the database, it can be opened in either
   Create or Append mode. For searching, open in Search (ReadOnly) mode for thread
   safety and to prevent accidentally changing the data.

   
   .. oe:method:: Constructors

      .. oe:language:: c++ java csharp

         .. oe:api::

            OESiteHopperDatabase()
            OESiteHopperDatabase(const OESiteHopperDatabase &)

      .. oe:language:: python

         .. oe:api:: python

            OESiteHopperDatabase() -> OESiteHopperDatabase
            OESiteHopperDatabase(arg2: OESiteHopperDatabase) -> OESiteHopperDatabase

      Default constructors.


   .. oe:method:: Open

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool Open(const std::string& dbfile, const unsigned int mode,
                      const OESiteHopperDatabaseOptions& opts = OESiteHopperDatabaseOptions())

      .. oe:language:: python

         .. oe:api:: python

            Open(dbfile: str, mode: int,
                 opts: OESiteHopperDatabaseOptions = OESiteHopperDatabaseOptions()) -> bool

      Open a file as an OESiteHopperDatabase. 
      
      To create a new database, use the mode
      :oe:const:`OESiteHopper::OESiteHopperDatabaseMode::CREATE`. If the file
      already exists, it will be overwritten. The options used to create the 
      database can be changed by passing an new version of :ref:`OESiteHopperDatabaseOptions <OESiteHopper_OESiteHopperDatabaseOptions>`.

      To append to an existing database, use the mode
      :oe:const:`OESiteHopper::OESiteHopperDatabaseMode::APPEND`. If the file
      does not yet exists, it will be created like the Create mode. 

      To read or search a file, open using the mode
      :oe:const:`OESiteHopper::OESiteHopperDatabaseMode::SEARCH`. This opens the
      database in read-only mode and will not allow adding new entries.  

      .. note::

         OESiteHopperDatabaseOptions are only used in `CREATE` mode. Otherwise, options already stored in
         the database will be used.


   .. oe:method:: operator bool

      .. oe:language:: c++ java csharp

         .. oe:api::

            operator bool() const

      .. oe:language:: python

         .. oe:api:: python

            IsValid() -> bool

   .. oe:method:: Add

      .. oe:language:: c++ java csharp

         .. oe:api::

            unsigned int Add(const std::string& filename)
            unsigned int Add(const OEBio::OEDesignUnit& du)

      .. oe:language:: python

         .. oe:api:: python

            Add(filename: str) -> int
            Add(du: OEDesignUnit) -> int

      Add a single OEDesignUnit file or object to an open database. This method will fail if the
      database is not open or if not opened in Create or Append mode.

      Returns the index of the newly added OEDesignUnit or `UINT_MAX` on failure.

   .. oe:method:: AddDirectory

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool AddDirectory(const std::string& path, unsigned int ncpu = 0,
                              OESystem::OETracerBase& tracer = OESystem::OENoTracer)

      .. oe:language:: python

         .. oe:api:: python

            AddDirectory(path: str, ncpu: int = 0,
                         tracer: OETracerBase = OENoTracer) -> bool

      Add a directory of OEDesignUnit files to the database. This call will recurse the
      entire directory tree, looking for all available `.oedu` files.

      By default, this call will use all available CPUs to process this set of OEDesignUnits. 
      Setting `ncpu` can be used to reduce the number of CPUs used.

      If you want to see a progress bar during the process, use an `OEConsoleProgressTracer`
      instead of the default `OENoTracer`.

   .. oe:method:: Close

      .. oe:language:: c++ java csharp

         .. oe:api::

            void Close()

      .. oe:language:: python

         .. oe:api:: python

            Close() -> None

      Close the database connection. Any operations (except another call to
      `Open`) after this will fail.

   .. oe:method:: GetDesignUnit

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool GetDesignUnit(OEBio::OEDesignUnit& du, unsigned int idx) const

      .. oe:language:: python

         .. oe:api:: python

            GetDesignUnit(du: OEDesignUnit, idx: int) -> bool

      Get a specific OEDesignUnit based on the database index.

   .. oe:method:: GetIDByTitle

      .. oe:language:: c++ java csharp

         .. oe:api::

            std::vector<unsigned int> GetIDByTitle(const std::string& title) const

      .. oe:language:: python

         .. oe:api:: python

            GetIDByTitle(title: str) -> OEUIntVector

      Get a vector of indices based on a substring match of the passed in title to
      OEDesignUnit titles in the database. 

   .. oe:method:: GetMaxMolIdx

      .. oe:language:: c++ java csharp

         .. oe:api::

            unsigned int GetMaxMolIdx() const

      .. oe:language:: python

         .. oe:api:: python

            GetMaxMolIdx() -> int

      Internal use: Get the maximum index in the database. Used by the GPU search.

   .. oe:method:: GetMolecule

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool GetMolecule(OEChem::OEMolBase& mol, unsigned int idx) const

      .. oe:language:: python

         .. oe:api:: python

            GetMolecule(mol: Union[OEGraphMol,OEMol,OEQMol], idx: int) -> bool

      Internal use: Get the patch molecule for the given index.

   .. oe:method:: GetOptions

      .. oe:language:: c++ java csharp

         .. oe:api::

            const OESiteHopperDatabaseOptions& GetOptions() const

      .. oe:language:: python

         .. oe:api:: python

            GetOptions() -> OESiteHopperDatabaseOptions

      Get the options used to create patches as they are added to the database.

   .. oe:method:: GetSequenceInfo

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool GetSequenceInfo(std::vector<std::vector<std::string>>& seq,
                                 unsigned int idx) const

      .. oe:language:: python

         .. oe:api:: python

            GetSequenceInfo(seq: OEStringVectorVector, idx: int) -> bool

      Internal use: Get the sequence info for the given database index.

   .. oe:method:: GetTitle

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool GetTitle(std::string& title, unsigned int idx) const

      .. oe:language:: python

         .. oe:api:: python

            GetTitle(idx: int) -> str

      Get the OEDesignUnit title for the given index.

