コード例 #1
0
    def _doDetailFile(self, inF, nFailsAllowed=1):
        done = 0
        verbose = 0
        nFails = 0
        while not done:
            if verbose: print '---------------'
            try:
                smi, refContribs = cPickle.load(inF)
            except EOFError:
                done = 1
            else:
                refContribs = [x[0] for x in refContribs]
                refOrder = numpy.argsort(refContribs)
                try:
                    mol = Chem.MolFromSmiles(smi)
                except:
                    import traceback
                    traceback.print_exc()
                    mol = None
                if mol:
                    mol = Chem.AddHs(mol, 1)
                    smi2 = Chem.MolToSmiles(mol)
                    contribs = Crippen._GetAtomContribs(mol)
                    contribs = [x[0] for x in contribs]
                    #
                    #  we're comparing to the old results using the oelib code.
                    #  Since we have some disagreements with them as to what is
                    #  aromatic and what isn't, we may have different numbers of
                    #  Hs. For the sake of comparison, just pop those off our
                    #  new results.
                    #
                    while len(contribs) > len(refContribs):
                        del contribs[-1]
                    order = numpy.argsort(contribs)

                    for i in range(len(refContribs)):
                        refL = refContribs[refOrder[i]]
                        l = contribs[order[i]]
                        if not feq(refL, l):
                            print '%s (%s): %d %6.5f != %6.5f' % (
                                smi, smi2, order[i], refL, l)
                            Crippen._GetAtomContribs(mol, force=1)
                            print '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'
                            nFails += 1
                            break
                    self.failUnless(nFails < nFailsAllowed)
                else:
                    print 'Problems with SMILES:', smi
コード例 #2
0
ファイル: MolSurf.py プロジェクト: abradle/rdkit
def pySlogP_VSA_(mol, bins=None, force=1):
  """ *Internal Use Only*
  """
  if not force:
    try:
      res = mol._slogpVSA
    except AttributeError:
      pass
    else:
      if res.all():
        return res

  if bins is None:
    bins = logpBins
  Crippen._Init()
  propContribs = Crippen._GetAtomContribs(mol, force=force)
  volContribs = _LabuteHelper(mol)

  ans = numpy.zeros(len(bins) + 1, 'd')
  for i in range(len(propContribs)):
    prop = propContribs[i]
    vol = volContribs[i + 1]
    if prop is not None:
      bin = bisect.bisect_right(bins, prop[0])
      ans[bin] += vol

  mol._slogpVSA = ans
  return ans
コード例 #3
0
def pySlogP_VSA_(mol,bins=None,force=1):
  """ *Internal Use Only*
  """
  if not force:
    try:
      res = mol._slogpVSA
    except AttributeError:
      pass
    else:
      if res.all():
        return res

  if bins is None: bins = logpBins
  Crippen._Init()
  propContribs = Crippen._GetAtomContribs(mol,force=force)
  volContribs = _LabuteHelper(mol)

  ans = numpy.zeros(len(bins)+1,'d')
  for i in range(len(propContribs)):
    prop = propContribs[i]
    vol = volContribs[i+1]
    if prop is not None:
      bin = bisect.bisect_right(bins,prop[0])
      ans[bin] += vol

  mol._slogpVSA=ans
  return ans    
コード例 #4
0
ファイル: UnitTestCrippen.py プロジェクト: BielitzLabs/rdkit
  def _doDetailFile(self,inF,nFailsAllowed=1):
    done = 0
    verbose=0
    nFails=0
    while not done:
      if verbose: print('---------------')
      try:
        smi,refContribs = cPickle.load(inF)
      except EOFError:
        done = 1
      else:
        refContribs = [x[0] for x in refContribs]
        refOrder= numpy.argsort(refContribs)
        try:
          mol = Chem.MolFromSmiles(smi)
        except:
          import traceback
          traceback.print_exc()
          mol = None
        if mol:
          mol=Chem.AddHs(mol,1)
          smi2 = Chem.MolToSmiles(mol)
          contribs = Crippen._GetAtomContribs(mol)
          contribs = [x[0] for x in contribs]
          #
          #  we're comparing to the old results using the oelib code.
          #  Since we have some disagreements with them as to what is
          #  aromatic and what isn't, we may have different numbers of
          #  Hs. For the sake of comparison, just pop those off our
          #  new results.
          #
          while len(contribs)>len(refContribs):
            del contribs[-1]
          order = numpy.argsort(contribs)

          for i in range(len(refContribs)):
            refL = refContribs[refOrder[i]]
            l = contribs[order[i]]
            if not feq(refL,l):
              print('%s (%s): %d %6.5f != %6.5f'%(smi,smi2,order[i],refL,l))
              Crippen._GetAtomContribs(mol,force=1)
              print('-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*')
              nFails +=1
              break;
        else:
          print('Problems with SMILES:',smi)
    self.assertTrue(nFails<nFailsAllowed)
コード例 #5
0
 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)
コード例 #6
0
ファイル: UnitTestCrippen.py プロジェクト: rdkit/rdkit
 def _writeDetailFile(self, inF, outF):
   while 1:
     try:
       smi, refContribs = pickle.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)
         pickle.dump((smi, contribs), outF)
       else:
         print('Problems with SMILES:', smi)
コード例 #7
0
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()
コード例 #8
0
ファイル: BuildCrippenTestSet.py プロジェクト: abradle/rdkit
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()
コード例 #9
0
ファイル: UnitTestCrippen.py プロジェクト: CKannas/rdkit
 def _writeDetailFile(self,inF,outF):
   while 1:
     try:
       smi,refContribs = cPickle.load(inF)
     except EOFError:
       break
     else:
       try:
         mol = Chem.MolFromSmiles(smi)
       except:
         import traceback
         traceback.print_exc()
         mol = None
       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
コード例 #10
0
ファイル: atom.py プロジェクト: yccai/scikit-chem
def crippen_molar_refractivity_contrib(a):
    """ Hacky way of getting molar refractivity contribution. """

    idx = a.GetIdx()
    m = a.GetOwningMol()
    return Crippen._GetAtomContribs(m)[idx][1]
コード例 #11
0
ファイル: atom.py プロジェクト: yccai/scikit-chem
def crippen_log_p_contrib(a):
    """ Hacky way of getting logP contribution. """

    idx = a.GetIdx()
    m = a.GetOwningMol()
    return Crippen._GetAtomContribs(m)[idx][0]