• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python cPickle.dump函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rdkit.six.moves.cPickle.dump函数的典型用法代码示例。如果您正苦于以下问题:Python dump函数的具体用法?Python dump怎么用?Python dump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dump函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: Pickle

  def Pickle(self,fileName='foo.pkl'):
    """ Writes this forest off to a file so that it can be easily loaded later

     **Arguments**

       fileName is the name of the file to be written
       
    """
    pFile = open(fileName,'wb+')
    cPickle.dump(self,pFile,1)
    pFile.close()
开发者ID:ASKCOS,项目名称:rdkit,代码行数:11,代码来源:Forest.py


示例2: testPkl

 def testPkl(self):
   # Test pickling
   v1 = self.klass(10)
   v1[1] = 1
   v1[2] = 1
   v1[3] = 1
   pklName = 'foo.pkl'
   outF = open(pklName, 'wb+')
   cPickle.dump(v1, outF)
   outF.close()
   inF = open(pklName, 'rb')
   v2 = cPickle.load(inF)
   inF.close()
   os.unlink(pklName)
   assert tuple(v1.GetOnBits()) == tuple(v2.GetOnBits()), 'pkl failed'
开发者ID:connorcoley,项目名称:rdkit,代码行数:15,代码来源:UnitTestcBitVect.py


示例3: SaveState

  def SaveState(self, fileName):
    """ Writes this calculator off to a file so that it can be easily loaded later

     **Arguments**

       - fileName: the name of the file to be written

    """
    try:
      f = open(fileName, 'wb+')
    except Exception:
      logger.error('cannot open output file %s for writing' % (fileName))
      return
    cPickle.dump(self, f)
    f.close()
开发者ID:connorcoley,项目名称:rdkit,代码行数:15,代码来源:MoleculeDescriptors.py


示例4: _writeDetailFile

 def _writeDetailFile(self,inF,outF):
   while 1:
     try:
       smi,refContribs = cPickle.load(inF)
     except EOFError:
       break
     else:
       mol = Chem.MolFromSmiles(smi)
       if mol:
         mol=Chem.AddHs(mol,1)
         smi2 = Chem.MolToSmiles(mol)
         contribs = Crippen._GetAtomContribs(mol)
         cPickle.dump((smi,contribs),outF)
       else:
         print('Problems with SMILES:',smi)
开发者ID:ASKCOS,项目名称:rdkit,代码行数:15,代码来源:UnitTestCrippen.py


示例5: testPkl

 def testPkl(self):
     """ test pickling 
 """
     v1 = klass(10)
     v1[1] = 1
     v1[2] = 1
     v1[3] = 1
     pklName = "foo.pkl"
     outF = open(pklName, "wb+")
     cPickle.dump(v1, outF)
     outF.close()
     inF = open(pklName, "rb")
     v2 = cPickle.load(inF)
     inF.close()
     os.unlink(pklName)
     assert tuple(v1.GetOnBits()) == tuple(v2.GetOnBits()), "pkl failed"
开发者ID:steve-federowicz,项目名称:rdkit,代码行数:16,代码来源:UnitTestcBitVect2.py


示例6: SaveState

  def SaveState(self,fileName):
    """ Writes this calculator off to a file so that it can be easily loaded later

     **Arguments**

       - fileName: the name of the file to be written
       
    """
    from rdkit.six.moves import cPickle
    try:
      f = open(fileName,'wb+')
    except:
      print('cannot open output file %s for writing'%(fileName))
      return
    cPickle.dump(self,f)
    f.close()
开发者ID:Acpharis,项目名称:rdkit,代码行数:16,代码来源:Descriptors.py


示例7: Pickle

  def Pickle(self, fileName='foo.pkl', saveExamples=0):
    """ Writes this composite off to a file so that it can be easily loaded later

     **Arguments**

       - fileName: the name of the file to be written

       - saveExamples: if this is zero, the individual models will have
         their stored examples cleared.

    """
    if not saveExamples:
      self.ClearModelExamples()

    pFile = open(fileName, 'wb+')
    cPickle.dump(self, pFile, 1)
    pFile.close()
开发者ID:connorcoley,项目名称:rdkit,代码行数:17,代码来源:Composite.py


示例8: runIt

def runIt(inFileName, outFileName, smiCol=0, maxMols=-1, delim=','):
  inF = gzip.open(inFileName, 'r')
  outF = open(outFileName, 'wb+')
  mols = []
  nDone = 0
  for line in inF.readlines():
    if line[0] != '#':
      splitL = line.strip().split(delim)
      smi = splitL[smiCol].strip()
      print(smi)
      mol = Chem.MolFromSmiles(smi)
      if mol:
        contribs = Crippen._GetAtomContribs(mol)
        cPickle.dump((smi, contribs), outF)
      nDone += 1
      if maxMols > 0 and nDone >= maxMols:
        break
  outF.close()
开发者ID:abradle,项目名称:rdkit,代码行数:18,代码来源:BuildCrippenTestSet.py


示例9: testPkl

 def testPkl(self):
   " testing molecule pickle "
   import tempfile
   f, self.fName = tempfile.mkstemp('.pkl')
   f = None
   self.m = Chem.MolFromSmiles('CC(=O)CC')
   outF = open(self.fName, 'wb+')
   cPickle.dump(self.m, outF)
   outF.close()
   inF = open(self.fName, 'rb')
   m2 = cPickle.load(inF)
   inF.close()
   try:
     os.unlink(self.fName)
   except Exception:
     pass
   oldSmi = Chem.MolToSmiles(self.m)
   newSmi = Chem.MolToSmiles(m2)
   assert oldSmi == newSmi, 'string compare failed'
开发者ID:abradle,项目名称:rdkit,代码行数:19,代码来源:UnitTestChem.py


示例10: testPkl

    def testPkl(self):
        " testing molecule pickle "
        import tempfile

        f, self.fName = tempfile.mkstemp(".pkl")
        f = None
        self.m = Chem.MolFromSmiles("CC(=O)CC")
        outF = open(self.fName, "wb+")
        cPickle.dump(self.m, outF)
        outF.close()
        inF = open(self.fName, "rb")
        m2 = cPickle.load(inF)
        inF.close()
        try:
            os.unlink(self.fName)
        except:
            pass
        oldSmi = Chem.MolToSmiles(self.m)
        newSmi = Chem.MolToSmiles(m2)
        assert oldSmi == newSmi, "string compare failed"
开发者ID:steve-federowicz,项目名称:rdkit,代码行数:20,代码来源:UnitTestChem.py


示例11: ClusterFromDetails

def ClusterFromDetails(details):
  """ Returns the cluster tree

  """
  data = MolSimilarity.GetFingerprints(details)
  if details.maxMols > 0:
    data = data[:details.maxMols]
  if details.outFileName:
    try:
      outF = open(details.outFileName, 'wb+')
    except IOError:
      error("Error: could not open output file %s for writing\n" % (details.outFileName))
      return None
  else:
    outF = None

  if not data:
    return None

  clustTree = ClusterPoints(data, details.metric, details.clusterAlgo, haveLabels=0, haveActs=1)
  if outF:
    cPickle.dump(clustTree, outF)
  return clustTree
开发者ID:abradle,项目名称:rdkit,代码行数:23,代码来源:ClusterMols.py


示例12: WritePickledData

def WritePickledData(outName,data):
  """ writes either a .qdat.pkl or a .dat.pkl file

    **Arguments**

      - outName: the name of the file to be used

      - data: either an _MLData.MLDataSet_ or an _MLData.MLQuantDataSet_

  """
  varNames = data.GetVarNames()
  qBounds = data.GetQuantBounds()
  ptNames = data.GetPtNames()
  examples = data.GetAllData()
  with open(outName,'wb+') as outFile:
    cPickle.dump(varNames,outFile)
    cPickle.dump(qBounds,outFile)  
    cPickle.dump(ptNames,outFile)  
    cPickle.dump(examples,outFile)
开发者ID:ASKCOS,项目名称:rdkit,代码行数:19,代码来源:DataUtils.py


示例13: MolViewer

    cmpd = Chem.MolFromSmiles('C1=CC=C1C#CC1=CC=C1')
    cmpd = Chem.AddHs(cmpd)
    AllChem.EmbedMolecule(cmpd)
    AllChem.UFFOptimizeMolecule(cmpd)
    AllChem.CanonicalizeMol(cmpd)
    print >>file('testmol.mol','w+'),Chem.MolToMolBlock(cmpd)
  else:
    cmpd = Chem.MolFromMolFile('testmol.mol')
  builder=SubshapeBuilder()
  if 1:
    shape=builder.GenerateSubshapeShape(cmpd)
  v = MolViewer()
  if 1:
    import tempfile
    tmpFile = tempfile.mktemp('.grd')
    v.server.deleteAll()
    Geometry.WriteGridToFile(shape.grid,tmpFile)
    time.sleep(1)
    v.ShowMol(cmpd,name='testMol',showOnly=True)
    v.server.loadSurface(tmpFile,'testGrid','',2.5)
  v.server.resetCGO('*')

  cPickle.dump(shape,file('subshape.pkl','w+'))
  for i,pt in enumerate(shape.skelPts):
    v.server.sphere(tuple(pt.location),.5,(1,0,1),'Pt-%d'%i)
    if not hasattr(pt,'shapeDirs'): continue
    momBeg = pt.location-pt.shapeDirs[0]
    momEnd = pt.location+pt.shapeDirs[0]
    v.server.cylinder(tuple(momBeg),tuple(momEnd),.1,(1,0,1),'v-%d'%i)

开发者ID:baoilleach,项目名称:rdkit,代码行数:29,代码来源:SubshapeBuilder.py


示例14: print

from rdkit.Chem.PyMol import MolViewer
from rdkit.Chem.Subshape import SubshapeBuilder, SubshapeObjects, SubshapeAligner
from rdkit.six.moves import cPickle
import copy

m1 = Chem.MolFromMolFile('test_data/square1.mol')
m2 = Chem.MolFromMolFile('test_data/square2.mol')

b = SubshapeBuilder.SubshapeBuilder()
b.gridDims = (10., 10., 5)
b.gridSpacing = 0.4
b.winRad = 2.0
if 1:
  print('m1:')
  s1 = b.GenerateSubshapeShape(m1)
  cPickle.dump(s1, open('test_data/square1.shp.pkl', 'wb+'))
  print('m2:')
  s2 = b.GenerateSubshapeShape(m2)
  cPickle.dump(s2, open('test_data/square2.shp.pkl', 'wb+'))
  ns1 = b.CombineSubshapes(s1, s2)
  b.GenerateSubshapeSkeleton(ns1)
  cPickle.dump(ns1, open('test_data/combined.shp.pkl', 'wb+'))
else:
  s1 = cPickle.load(open('test_data/square1.shp.pkl', 'rb'))
  s2 = cPickle.load(open('test_data/square2.shp.pkl', 'rb'))
  #ns1 = cPickle.load(file('test_data/combined.shp.pkl','rb'))
  ns1 = cPickle.load(open('test_data/combined.shp.pkl', 'rb'))

v = MolViewer()
SubshapeObjects.DisplaySubshape(v, s1, 'shape1')
SubshapeObjects.DisplaySubshape(v, ns1, 'ns1')
开发者ID:abradle,项目名称:rdkit,代码行数:31,代码来源:testCombined.py


示例15: RunOnData

def RunOnData(details, data, progressCallback=None, saveIt=1, setDescNames=0):
  if details.lockRandom:
    seed = details.randomSeed
  else:
    import random
    seed = (random.randint(0, 1e6), random.randint(0, 1e6))
  DataUtils.InitRandomNumbers(seed)
  testExamples = []
  if details.shuffleActivities == 1:
    DataUtils.RandomizeActivities(data, shuffle=1, runDetails=details)
  elif details.randomActivities == 1:
    DataUtils.RandomizeActivities(data, shuffle=0, runDetails=details)

  namedExamples = data.GetNamedData()
  if details.splitRun == 1:
    trainIdx, testIdx = SplitData.SplitIndices(
      len(namedExamples), details.splitFrac, silent=not _verbose)

    trainExamples = [namedExamples[x] for x in trainIdx]
    testExamples = [namedExamples[x] for x in testIdx]
  else:
    testExamples = []
    testIdx = []
    trainIdx = list(range(len(namedExamples)))
    trainExamples = namedExamples

  if details.filterFrac != 0.0:
    # if we're doing quantization on the fly, we need to handle that here:
    if hasattr(details, 'activityBounds') and details.activityBounds:
      tExamples = []
      bounds = details.activityBounds
      for pt in trainExamples:
        pt = pt[:]
        act = pt[-1]
        placed = 0
        bound = 0
        while not placed and bound < len(bounds):
          if act < bounds[bound]:
            pt[-1] = bound
            placed = 1
          else:
            bound += 1
        if not placed:
          pt[-1] = bound
        tExamples.append(pt)
    else:
      bounds = None
      tExamples = trainExamples
    trainIdx, temp = DataUtils.FilterData(tExamples, details.filterVal, details.filterFrac, -1,
                                          indicesOnly=1)
    tmp = [trainExamples[x] for x in trainIdx]
    testExamples += [trainExamples[x] for x in temp]
    trainExamples = tmp

    counts = DataUtils.CountResults(trainExamples, bounds=bounds)
    ks = counts.keys()
    ks.sort()
    message('Result Counts in training set:')
    for k in ks:
      message(str((k, counts[k])))
    counts = DataUtils.CountResults(testExamples, bounds=bounds)
    ks = counts.keys()
    ks.sort()
    message('Result Counts in test set:')
    for k in ks:
      message(str((k, counts[k])))
  nExamples = len(trainExamples)
  message('Training with %d examples' % (nExamples))

  nVars = data.GetNVars()
  attrs = list(range(1, nVars + 1))
  nPossibleVals = data.GetNPossibleVals()
  for i in range(1, len(nPossibleVals)):
    if nPossibleVals[i - 1] == -1:
      attrs.remove(i)

  if details.pickleDataFileName != '':
    pickleDataFile = open(details.pickleDataFileName, 'wb+')
    cPickle.dump(trainExamples, pickleDataFile)
    cPickle.dump(testExamples, pickleDataFile)
    pickleDataFile.close()

  if details.bayesModel:
    composite = BayesComposite.BayesComposite()
  else:
    composite = Composite.Composite()

  composite._randomSeed = seed
  composite._splitFrac = details.splitFrac
  composite._shuffleActivities = details.shuffleActivities
  composite._randomizeActivities = details.randomActivities

  if hasattr(details, 'filterFrac'):
    composite._filterFrac = details.filterFrac
  if hasattr(details, 'filterVal'):
    composite._filterVal = details.filterVal

  composite.SetModelFilterData(details.modelFilterFrac, details.modelFilterVal)

  composite.SetActivityQuantBounds(details.activityBounds)
#.........这里部分代码省略.........
开发者ID:connorcoley,项目名称:rdkit,代码行数:101,代码来源:BuildComposite.py


示例16: message

  cat = None
  obls = None
  if details.doBuild:
    if not suppl:
      message("We require inData to generate a catalog\n")
      sys.exit(-2)
    message("Building catalog\n")
    t1 = time.time()
    cat = BuildCatalog(suppl, maxPts=details.numMols, minPath=details.minPath,
                       maxPath=details.maxPath)
    t2 = time.time()
    message("\tThat took %.2f seconds.\n" % (t2 - t1))
    if details.catalogName:
      message("Dumping catalog data\n")
      cPickle.dump(cat, open(details.catalogName, 'wb+'))
  elif details.catalogName:
    message("Loading catalog\n")
    cat = cPickle.load(open(details.catalogName, 'rb'))
    if details.onBitsName:
      try:
        obls = cPickle.load(open(details.onBitsName, 'rb'))
      except Exception:
        obls = None
      else:
        if len(obls) < (inD.count('\n') - 1):
          obls = None
  scores = None
  if details.doScore:
    if not suppl:
      message("We require inData to score molecules\n")
开发者ID:connorcoley,项目名称:rdkit,代码行数:30,代码来源:BuildFragmentCatalog.py


示例17: Pickle

  def Pickle(self, fileName='foo.pkl'):
    """ Pickles the tree and writes it to disk

    """
    with open(fileName, 'wb+') as pFile:
      cPickle.dump(self, pFile)
开发者ID:connorcoley,项目名称:rdkit,代码行数:6,代码来源:Tree.py


示例18: clear

# create a logged canvas and draw on it
sz = (300,300)
c1 = Logger.Logger(pidSVG.SVGCanvas,sz,'foo.svg',loggerFlushCommand='clear')
c1.drawPolygon([(100,100),(100,200),(200,200),(200,100)],fillColor=pid.Color(0,0,1))
c1.drawLines([(100,100,200,200),(100,200,200,100)],color=pid.Color(0,1,0),width=2)

# because the log has been instantiated with clear() as the loggerFlushCommand, 
# this will blow out the log as well as the contents of the canvas.
c1.clear()

# draw some more stuff
c1.drawPolygon([(100,100),(100,200),(200,200),(200,100)],fillColor=pid.Color(1,0,0))
c1.drawLines([(100,100,200,200),(100,200,200,100)],color=pid.Color(0,0,0),width=2)
# and write the resulting file.
c1.save()

# save the log by pickling it.
from rdkit.six.moves import cPickle
cPickle.dump(c1._LoggerGetLog(),open('foo.pkl','wb+'))

# create a new canvas
c2 = pidPIL.PILCanvas(sz,'foo.png')
# read the pickled log back in 
t = cPickle.load(open('foo.pkl','rb'))
# and play the log on the new canvas
Logger.replay(t,c2)
# there should now be a file 'foo.png' with the image


开发者ID:Acpharis,项目名称:rdkit,代码行数:27,代码来源:SpingDemo.py


示例19: FingerprintsFromDetails

def FingerprintsFromDetails(details, reportFreq=10):
  data = None
  if details.dbName and details.tableName:
    from rdkit.Dbase.DbConnection import DbConnect
    from rdkit.Dbase import DbInfo
    from rdkit.ML.Data import DataUtils
    try:
      conn = DbConnect(details.dbName, details.tableName)
    except Exception:
      import traceback
      error('Problems establishing connection to database: %s|%s\n' % (details.dbName,
                                                                       details.tableName))
      traceback.print_exc()
    if not details.idName:
      details.idName = DbInfo.GetColumnNames(details.dbName, details.tableName)[0]
    dataSet = DataUtils.DBToData(details.dbName, details.tableName,
                                 what='%s,%s' % (details.idName, details.smilesName))
    idCol = 0
    smiCol = 1
  elif details.inFileName and details.useSmiles:
    from rdkit.ML.Data import DataUtils
    conn = None
    if not details.idName:
      details.idName = 'ID'
    try:
      dataSet = DataUtils.TextFileToData(details.inFileName,
                                         onlyCols=[details.idName, details.smilesName])
    except IOError:
      import traceback
      error('Problems reading from file %s\n' % (details.inFileName))
      traceback.print_exc()

    idCol = 0
    smiCol = 1
  elif details.inFileName and details.useSD:
    conn = None
    dataset = None
    if not details.idName:
      details.idName = 'ID'
    dataSet = []
    try:
      s = Chem.SDMolSupplier(details.inFileName)
    except Exception:
      import traceback
      error('Problems reading from file %s\n' % (details.inFileName))
      traceback.print_exc()
    else:
      while 1:
        try:
          m = s.next()
        except StopIteration:
          break
        if m:
          dataSet.append(m)
          if reportFreq > 0 and not len(dataSet) % reportFreq:
            message('Read %d molecules\n' % (len(dataSet)))
            if details.maxMols > 0 and len(dataSet) >= details.maxMols:
              break

    for i, mol in enumerate(dataSet):
      if mol.HasProp(details.idName):
        nm = mol.GetProp(details.idName)
      else:
        nm = mol.GetProp('_Name')
      dataSet[i] = (nm, mol)
  else:
    dataSet = None

  fps = None
  if dataSet and not details.useSD:
    data = dataSet.GetNamedData()
    if not details.molPklName:
      fps = apply(FingerprintsFromSmiles, (data, idCol, smiCol), details.__dict__)
    else:
      fps = apply(FingerprintsFromPickles, (data, idCol, smiCol), details.__dict__)
  elif dataSet and details.useSD:
    fps = apply(FingerprintsFromMols, (dataSet, ), details.__dict__)

  if fps:
    if details.outFileName:
      outF = open(details.outFileName, 'wb+')
      for i in range(len(fps)):
        cPickle.dump(fps[i], outF)
      outF.close()
    dbName = details.outDbName or details.dbName
    if details.outTableName and dbName:
      from rdkit.Dbase.DbConnection import DbConnect
      from rdkit.Dbase import DbUtils, DbModule
      conn = DbConnect(dbName)
      #
      #  We don't have a db open already, so we'll need to figure out
      #    the types of our columns...
      #
      colTypes = DbUtils.TypeFinder(data, len(data), len(data[0]))
      typeStrs = DbUtils.GetTypeStrings([details.idName, details.smilesName], colTypes,
                                        keyCol=details.idName)
      cols = '%s, %s %s' % (typeStrs[0], details.fpColName, DbModule.binaryTypeName)

      # FIX: we should really check to see if the table
      #  is already there and, if so, add the appropriate
#.........这里部分代码省略.........
开发者ID:connorcoley,项目名称:rdkit,代码行数:101,代码来源:FingerprintMols.py


示例20: print

        for example in examples:
            res = net.ClassifyExample(example[:-1])
            print("%f -> %f" % (example[-1], res))

        return net

    def runProfile(command):
        import random

        random.seed(23)
        import profile, pstats

        datFile = "%s.prof.dat" % (command)
        profile.run("%s()" % command, datFile)
        stats = pstats.Stats(datFile)
        stats.strip_dirs()
        stats.sort_stats("time").print_stats()

    if 0:
        net = testXor()
        print("Xor:", net)
        from rdkit.six.moves import cPickle

        outF = open("xornet.pkl", "wb+")
        cPickle.dump(net, outF)
        outF.close()
    else:
        # runProfile('testLinear')
        net = testLinear()
        # net = testOr()
开发者ID:maxpillong,项目名称:rdkit,代码行数:30,代码来源:Trainers.py



注:本文中的rdkit.six.moves.cPickle.dump函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cPickle.dumps函数代码示例发布时间:2022-05-26
下一篇:
Python moves.xrange函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap