rdkit.VLib.NodeLib.SmilesSupply

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  from rdkit import six
    11
    12
    13 -class SmilesSupplyNode(SupplyNode):
    14    """ Smiles supplier
    15
    16    Sample Usage:
    17      >>> fileN = os.path.join(RDConfig.RDCodeDir,'VLib','NodeLib',\
    18                               'test_data','pgp_20.txt')
    19      >>> suppl = SmilesSupplyNode(fileN,delim="\\t",smilesColumn=2,nameColumn=1,titleLine=1)
    20      >>> ms = [x for x in suppl]
    21      >>> len(ms)
    22      20
    23      >>> ms[0].GetProp("_Name")
    24      'ALDOSTERONE'
    25      >>> ms[0].GetProp("ID")
    26      'RD-PGP-0001'
    27      >>> ms[1].GetProp("_Name")
    28      'AMIODARONE'
    29      >>> ms[3].GetProp("ID")
    30      'RD-PGP-0004'
    31      >>> suppl.reset()
    32      >>> suppl.next().GetProp("_Name")
    33      'ALDOSTERONE'
    34      >>> suppl.next().GetProp("_Name")
    35      'AMIODARONE'
    36      >>> suppl.reset()
    37
    38    """
    39 -  def __init__(self,fileName,delim="\t",nameColumn=1,smilesColumn=0,titleLine=0,
    40                 **kwargs):
    41      SupplyNode.__init__(self,**kwargs)
    42      self._fileName = fileName
    43      self._supplier = Chem.SmilesMolSupplier(self._fileName,delimiter=delim,
    44                                              smilesColumn=smilesColumn,
    45                                              nameColumn=nameColumn,
    46                                              titleLine=titleLine)
    47
    48 -  def reset(self):
    49      SupplyNode.reset(self)
    50      self._supplier.reset()
    51 -  def next(self):
    52      """
    53
    54      """
    55      r = None
    56      while not r:
    57        r = next(self._supplier)
    58      return r
    59
    60  if six.PY3:
    61      SmilesSupplyNode.__next__ = SmilesSupplyNode.next
    62
    63  #------------------------------------
    64  #
    65  #  doctest boilerplate
    66  #
    67 -def _test():
    68    import doctest,sys
    69    return doctest.testmod(sys.modules["__main__"])
    70
    71
    72  if __name__ == '__main__':
    73    import sys
    74    failed,tried = _test()
    75    sys.exit(failed)
    76