Package rdkit :: Package VLib :: Package NodeLib :: Module SmilesSupply

[hide private]
[frames] | no frames]

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

     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
    11 -class SmilesSupplyNode(SupplyNode):
    12    """ Smiles supplier
    13
    14    Sample Usage:
    15      >>> fileN = os.path.join(RDConfig.RDCodeDir,'VLib','NodeLib',\
    16                               'test_data','pgp_20.txt')
    17      >>> suppl = SmilesSupplyNode(fileN,delim="\\t",smilesColumn=2,nameColumn=1,titleLine=1)
    18      >>> ms = [x for x in suppl]
    19      >>> len(ms)
    20      20
    21      >>> ms[0].GetProp("_Name")
    22      'ALDOSTERONE'
    23      >>> ms[0].GetProp("ID")
    24      'RD-PGP-0001'
    25      >>> ms[1].GetProp("_Name")
    26      'AMIODARONE'
    27      >>> ms[3].GetProp("ID")
    28      'RD-PGP-0004'
    29      >>> suppl.reset()
    30      >>> suppl.next().GetProp("_Name")
    31      'ALDOSTERONE'
    32      >>> suppl.next().GetProp("_Name")
    33      'AMIODARONE'
    34      >>> suppl.reset()
    35
    36    """
    37 -  def __init__(self,fileName,delim="\t",nameColumn=1,smilesColumn=0,titleLine=0,
    38                 **kwargs):
    39      SupplyNode.__init__(self,**kwargs)
    40      self._fileName = fileName
    41      self._supplier = Chem.SmilesMolSupplier(self._fileName,delimiter=delim,
    42                                              smilesColumn=smilesColumn,
    43                                              nameColumn=nameColumn,
    44                                              titleLine=titleLine)
    45
    46 -  def reset(self):
    47      SupplyNode.reset(self)
    48      self._supplier.reset()
    49 -  def next(self):
    50      """
    51
    52      """
    53      r = None
    54      while not r:
    55        r = self._supplier.next()
    56      return r
    57
    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