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  from rdkit import Chem
     7  from rdkit import six
     8  from rdkit.VLib.Supply import SupplyNode
     9
    10
    11 -class SmilesSupplyNode(SupplyNode):
    12    """ Smiles supplier
    13
    14    Sample Usage:
    15      >>> import os
    16      >>> from rdkit import RDConfig
    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
    40 -  def __init__(self, fileName, delim="\t", nameColumn=1, smilesColumn=0, titleLine=0, **kwargs):
    41      SupplyNode.__init__(self, **kwargs)
    42      self._fileName = fileName
    43      self._supplier = Chem.SmilesMolSupplier(self._fileName, delimiter=delim,
    44                                              smilesColumn=smilesColumn, nameColumn=nameColumn,
    45                                              titleLine=titleLine)
    46
    47 -  def reset(self):
    48      SupplyNode.reset(self)
    49      self._supplier.reset()
    50
    51 -  def next(self):
    52      """
    53
    54      """
    55      r = None
    56      while not r:
    57        r = next(self._supplier)
    58      return r
    59
    60
    61  if six.PY3:
    62    SmilesSupplyNode.__next__ = SmilesSupplyNode.next
    63
    64
    65  # ------------------------------------
    66  #
    67  #  doctest boilerplate
    68  #
    69 -def _runDoctests(verbose=None):  # pragma: nocover
    70    import doctest
    71    import sys
    72    failed, _ = doctest.testmod(optionflags=doctest.ELLIPSIS, verbose=verbose)
    73    sys.exit(failed)
    74
    75
    76  if __name__ == '__main__':  # pragma: nocover
    77    _runDoctests()
    78