| Trees | Indices | Help |
|
|---|
|
|
1 # $Id: FastSDMolSupplier.py 391 2007-10-20 06:26:50Z glandrum $ 2 # 3 # Copyright (C) 2007 Greg Landrum 4 # @@ All Rights Reserved @@ 5 # 6 import sys 7 import Chem 810 """ A wrapper around an SDMolSupplier that precomputes and stores 11 molecular indices (via text processing) to allow quick length 12 calculations and random access. 13 14 NOTE that this class needs to have the entire SD data in memory, 15 so it's probably not particularly useful with large files. 16 """ 17 suppl=None 18 data=None 19 sanitize=True7721 if fileN: 22 data = open(fileN,'r').read() 23 self.sanitize=sanitize 24 self.removeHs=removeHs 25 if data: 26 data = data.replace('\r\n','\n') 27 self.init(data)2830 if not data: 31 raise ValueError,'no data' 32 # FIX: it'd be nice to not be caching data locally like this, but it's the easiest 33 # way to handle pickle support. 34 self.data=data 35 self.suppl = Chem.SDMolSupplier() 36 self.suppl.SetData(data,sanitize=self.sanitize,removeHs=self.removeHs) 37 38 self._pos = [0] 39 p = 0 40 while 1: 41 try: 42 p = data.index(recogTxt,p+1) 43 p+=len(recogTxt) 44 except: 45 break 46 else: 47 self._pos.append(p) 48 self._pos.pop(-1) 49 self.suppl._SetStreamIndices(self._pos) 50 self._idx=05153 startOfItem = self._pos[idx] 54 if idx+1<len(self._pos): 55 endOfItem = self._pos[idx+1] 56 else: 57 endOfItem = -1 58 return self.data[startOfItem:endOfItem]59 63 64 # ---------------------------------------------------------------- 65 # support random access and an iterator interface: 7274 return len(self.suppl)76 return self.suppl[idx]
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Sat May 24 08:37:20 2008 | http://epydoc.sourceforge.net |