当前位置: 首页>>代码示例>>Python>>正文


Python cPickle.dump函数代码示例

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


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


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