Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.PDB.Vector.Vector Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def __neg__
def __add__
def __sub__
def __mul__
def __div__
def __pow__
def __getitem__
def __setitem__
def __contains__
def norm
def normsq
def normalize
def normalized
def angle
def get_array
def left_multiply
def right_multiply
def copy

Private Attributes

 _ar

Detailed Description

Definition at line 198 of file Vector.py.


Constructor & Destructor Documentation

def Bio.PDB.Vector.Vector.__init__ (   self,
  x,
  y = None,
  z = None 
)

Definition at line 201 of file Vector.py.

00201 
00202     def __init__(self, x, y=None, z=None):
00203         if y is None and z is None:
00204             # Array, list, tuple...
00205             if len(x)!=3:
00206                 raise ValueError("Vector: x is not a "
00207                                  "list/tuple/array of 3 numbers")
00208             self._ar=numpy.array(x, 'd')
00209         else:
00210             # Three numbers
00211             self._ar=numpy.array((x, y, z), 'd')


Member Function Documentation

def Bio.PDB.Vector.Vector.__add__ (   self,
  other 
)

Definition at line 221 of file Vector.py.

00221 
00222     def __add__(self, other):
00223         "Return Vector+other Vector or scalar"
00224         if isinstance(other, Vector):
00225             a=self._ar+other._ar
00226         else:
00227             a=self._ar+numpy.array(other)
00228         return Vector(a)

def Bio.PDB.Vector.Vector.__contains__ (   self,
  i 
)

Definition at line 265 of file Vector.py.

00265 
00266     def __contains__(self, i):
00267         return (i in self._ar)

def Bio.PDB.Vector.Vector.__div__ (   self,
  x 
)

Definition at line 241 of file Vector.py.

00241 
00242     def __div__(self, x):
00243         "Return Vector(coords/a)"
00244         a=self._ar/numpy.array(x)
00245         return Vector(a)

def Bio.PDB.Vector.Vector.__getitem__ (   self,
  i 
)

Definition at line 259 of file Vector.py.

00259 
00260     def __getitem__(self, i):
00261         return self._ar[i]

Here is the caller graph for this function:

def Bio.PDB.Vector.Vector.__mul__ (   self,
  other 
)

Definition at line 237 of file Vector.py.

00237 
00238     def __mul__(self, other):
00239         "Return Vector.Vector (dot product)"
00240         return sum(self._ar*other._ar)

Definition at line 216 of file Vector.py.

00216 
00217     def __neg__(self):
00218         "Return Vector(-x, -y, -z)"
00219         a=-self._ar
00220         return Vector(a)

def Bio.PDB.Vector.Vector.__pow__ (   self,
  other 
)

Definition at line 246 of file Vector.py.

00246 
00247     def __pow__(self, other):
00248         "Return VectorxVector (cross product) or Vectorxscalar"
00249         if isinstance(other, Vector):
00250             a,b,c=self._ar
00251             d,e,f=other._ar
00252             c1=numpy.linalg.det(numpy.array(((b,c), (e,f))))
00253             c2=-numpy.linalg.det(numpy.array(((a,c), (d,f))))
00254             c3=numpy.linalg.det(numpy.array(((a,b), (d,e))))
00255             return Vector(c1,c2,c3)
00256         else:
00257             a=self._ar*numpy.array(other)
00258             return Vector(a)

Definition at line 212 of file Vector.py.

00212 
00213     def __repr__(self):
00214         x,y,z=self._ar
00215         return "<Vector %.2f, %.2f, %.2f>" % (x,y,z)

def Bio.PDB.Vector.Vector.__setitem__ (   self,
  i,
  value 
)

Definition at line 262 of file Vector.py.

00262 
00263     def __setitem__(self, i, value):
00264         self._ar[i]=value

def Bio.PDB.Vector.Vector.__sub__ (   self,
  other 
)

Definition at line 229 of file Vector.py.

00229 
00230     def __sub__(self, other):
00231         "Return Vector-other Vector or scalar"
00232         if isinstance(other, Vector):
00233             a=self._ar-other._ar
00234         else:
00235             a=self._ar-numpy.array(other)
00236         return Vector(a)

def Bio.PDB.Vector.Vector.angle (   self,
  other 
)

Definition at line 286 of file Vector.py.

00286 
00287     def angle(self, other):
00288         "Return angle between two vectors"
00289         n1=self.norm()
00290         n2=other.norm()
00291         c=(self*other)/(n1*n2)
00292         # Take care of roundoff errors
00293         c=min(c,1)
00294         c=max(-1,c)
00295         return numpy.arccos(c)

Here is the call graph for this function:

Definition at line 310 of file Vector.py.

00310 
00311     def copy(self):
00312         "Return a deep copy of the Vector"
00313         return Vector(self._ar)

Here is the caller graph for this function:

Definition at line 296 of file Vector.py.

00296 
00297     def get_array(self):
00298         "Return (a copy of) the array of coordinates"
00299         return numpy.array(self._ar)

def Bio.PDB.Vector.Vector.left_multiply (   self,
  matrix 
)

Definition at line 300 of file Vector.py.

00300 
00301     def left_multiply(self, matrix):
00302         "Return Vector=Matrix x Vector"
00303         a=numpy.dot(matrix, self._ar)
00304         return Vector(a)

Definition at line 268 of file Vector.py.

00268 
00269     def norm(self):
00270         "Return vector norm"
00271         return numpy.sqrt(sum(self._ar*self._ar))

Here is the caller graph for this function:

Definition at line 276 of file Vector.py.

00276 
00277     def normalize(self):
00278         "Normalize the Vector"
00279         self._ar=self._ar/self.norm()

Here is the call graph for this function:

Definition at line 280 of file Vector.py.

00280 
00281     def normalized(self):
00282         "Return a normalized copy of the Vector"
00283         v=self.copy()
00284         v.normalize()
00285         return v

Here is the call graph for this function:

Definition at line 272 of file Vector.py.

00272 
00273     def normsq(self):
00274         "Return square of vector norm"
00275         return abs(sum(self._ar*self._ar))

def Bio.PDB.Vector.Vector.right_multiply (   self,
  matrix 
)

Definition at line 305 of file Vector.py.

00305 
00306     def right_multiply(self, matrix):
00307         "Return Vector=Vector x Matrix"
00308         a=numpy.dot(self._ar, matrix)
00309         return Vector(a)


Member Data Documentation

Definition at line 207 of file Vector.py.


The documentation for this class was generated from the following file: