Chem.Pharm3D.Pharmacophore

Package Chem :: Package Pharm3D :: Module Pharmacophore |
[hide private]
[frames] | no frames]

# Source Code for Module Chem.Pharm3D.Pharmacophore

      1  # $Id: Pharmacophore.py 2 2006-05-06 22:54:39Z glandrum $

      2  #

      3  # Copyright (C) 2004-2006 Rational Discovery LLC

      4  #

      5  #   @@ All Rights Reserved  @@

      6  #

      7  import Geometry
      8  from Numeric import *
      9  import Chem
     10  from Chem import ChemicalFeatures
     11

     12 -class Pharmacophore:
     13 -  def __init__(self, feats,initMats=True):
     14      self._initializeFeats(feats)
     15      nf = len(feats)
     16      self._boundsMat = zeros((nf, nf), Float)
     17      self._boundsMat2D = zeros((nf, nf), Int)
     18      if initMats:
     19        self._initializeMatrices()
     20

     21 -  def _initializeFeats(self,feats):
     22      self._feats = []
     23      for feat in feats:
     24        if isinstance(feat,ChemicalFeatures.MolChemicalFeature):
     25          pos = feat.GetPos()
     26          newFeat = ChemicalFeatures.FreeChemicalFeature(feat.GetFamily(),feat.GetType(),

     27                                             Geometry.Point3D(pos[0],pos[1],pos[2]))
     28          self._feats.append(newFeat)
     29        else:
     30          self._feats.append(feat)
     31

     32 -  def _initializeMatrices(self):
     33      # initialize the bounds matrix with distances to start with

     34      nf = len(self._feats)
     35      for i in range(1, nf):
     36        loci = self._feats[i].GetPos()
     37        for j in range(i):
     38          locj = self._feats[j].GetPos()
     39          dist = loci.Distance(locj)
     40          self._boundsMat[i,j] = dist
     41          self._boundsMat[j,i] = dist
     42      for i in range(nf):
     43        for j in range(i+1,nf):
     44          self._boundsMat2D[i,j] = 1000
     45

     46

     47 -  def getFeatures(self):
     48      return self._feats
     49

     50 -  def getFeature(self, i):
     51      return self._feats[i]
     52

     53 -  def getUpperBound(self, i, j):
     54      if (i > j):
     55        j,i = i,j
     56      return self._boundsMat[i, j]
     57

     58 -  def getLowerBound(self, i, j):
     59      if (j > i):
     60        j,i = i,j
     61      return self._boundsMat[i,j]
     62

     63 -  def _checkBounds(self,i,j):
     64      " raises ValueError on failure "
     65      nf = len(self._feats)
     66      if (i < 0) or (i >= nf):
     67        raise ValueError, "Index out of bound"
     68      if (j < 0) or (j >= nf):
     69        raise ValueError, "Index out of bound"
     70      return True
     71

     72 -  def setUpperBound(self, i, j, val, checkBounds=False):
     73      if (checkBounds): self._checkBounds(i,j)
     74      if (i > j):
     75        j,i = i,j
     76      self._boundsMat[i,j] = val
     77

     78 -  def setLowerBound(self, i, j, val, checkBounds=False):
     79      if (checkBounds): self._checkBounds(i,j)
     80      if (j > i):
     81        j,i = i,j
     82      self._boundsMat[i,j] = val
     83

     84 -  def getUpperBound2D(self, i, j):
     85      if (i > j):
     86        j,i = i,j
     87      return self._boundsMat2D[i, j]
     88

     89 -  def getLowerBound2D(self, i, j):
     90      if (j > i):
     91        j,i = i,j
     92      return self._boundsMat2D[i,j]
     93

     94

     95 -  def setUpperBound2D(self, i, j, val, checkBounds=False):
     96      if (checkBounds): self._checkBounds(i,j)
     97      if (i > j):
     98        j,i = i,j
     99      self._boundsMat2D[i,j] = val
    100

    101 -  def setLowerBound2D(self, i, j, val, checkBounds=False):
    102      if (checkBounds): self._checkBounds(i,j)
    103      if (j > i):
    104        j,i = i,j
    105      self._boundsMat2D[i,j] = val
    106

    107 -  def __str__(self):
    108      res = ' '*13
    109      for i,iFeat in enumerate(self._feats):
    110        res += '% 12s '%iFeat.GetFamily()
    111      res += '\n'
    112      for i,iFeat in enumerate(self._feats):
    113        res += '% 12s '%iFeat.GetFamily()
    114        for j,jFeat in enumerate(self._feats):
    115          if j<i:
    116            res += '% 12.3f '%self.getLowerBound(i,j)
    117          elif j>i:
    118            res += '% 12.3f '%self.getUpperBound(i,j)
    119          else:
    120            res += '% 12.3f '%0.0
    121        res += '\n'
    122      return res
    123