Package rdkit :: Package VLib :: Package NodeLib :: Module DbMolSupply

[hide private]
[frames] | no frames]

# Source Code for Module rdkit.VLib.NodeLib.DbMolSupply

     1  #  $Id$
     2  #
     3  #  Copyright (C) 2003 Rational Discovery LLC
     4  #     All Rights Reserved
     5  #
     6  import sys,os.path
     7  from rdkit import RDConfig
     8  from rdkit.VLib.Supply import SupplyNode
     9  from rdkit import Chem
    10  from rdkit.Chem.Suppliers import DbMolSupplier
    11
    12 -class DbMolSupplyNode(SupplyNode):
    13    """ Supplies molecules from a db result set:
    14
    15    Sample Usage:
    16      >>> from rdkit.Dbase.DbConnection import DbConnect
    17      >>> dbName = os.path.join(RDConfig.RDCodeDir,'Chem','Fingerprints',\
    18                               'test_data','data.gdb')
    19      >>> conn = DbConnect(dbName,'simple_mols')
    20      >>> dataset = conn.GetData()
    21      >>> suppl = DbMolSupplyNode(dataset)
    22      >>> ms = [x for x in suppl]
    23      >>> len(ms)
    24      12
    25      >>> ms[0].GetProp("ID")
    26      'ether-1'
    27      >>> ms[10].GetProp("ID")
    28      'acid-4'
    29      >>> suppl.reset()
    30      >>> suppl.next().GetProp("ID")
    31      'ether-1'
    32      >>> suppl.next().GetProp("ID")
    33      'acid-1'
    34      >>> suppl.reset()
    35
    36    """
    37 -  def __init__(self,dbResults,
    38                 **kwargs):
    39      SupplyNode.__init__(self,**kwargs)
    40      self._dbResults = dbResults
    41      self._supplier = DbMolSupplier.RandomAccessDbMolSupplier(self._dbResults,
    42                                                               **kwargs)
    43
    44
    45 -  def reset(self):
    46      SupplyNode.reset(self)
    47      self._supplier.Reset()
    48 -  def next(self):
    49      """
    50
    51      """
    52      return self._supplier.next()
    53
    54 -def GetNode(dbName,tableName):
    55    from rdkit.Dbase.DbConnection import DbConnect
    56    conn = DbConnect(dbName,tableName)
    57    return DbMolSupplyNode(conn.GetData())
    58
    59  #------------------------------------
    60  #
    61  #  doctest boilerplate
    62  #
    63 -def _test():
    64    import doctest,sys
    65    return doctest.testmod(sys.modules["__main__"])
    66
    67
    68  if __name__ == '__main__':
    69    import sys
    70    failed,tried = _test()
    71    sys.exit(failed)
    72