Back to index

python-biopython  1.60
Classes | Functions | Variables
Bio.PDB.Vector Namespace Reference

Classes

class  Vector

Functions

def m2rotaxis
def vector_to_axis
def rotaxis2m
def refmat
def rotmat
def calc_angle
def calc_dihedral

Variables

tuple v1 = Vector(0,0,1)
tuple v2 = Vector(0,0,0)
tuple v3 = Vector(0,1,0)
tuple v4 = Vector(1,1,0)
tuple dih = calc_dihedral(v1, v2, v3, v4)
tuple ref = refmat(v1, v3)
tuple rot = rotmat(v1, v3)
tuple angle = random()
tuple axis = Vector(random(3)-random(3))
tuple m = rotaxis(angle, axis)

Function Documentation

def Bio.PDB.Vector.calc_angle (   v1,
  v2,
  v3 
)
Calculate the angle between 3 vectors
representing 3 connected points.

@param v1, v2, v3: the tree points that define the angle
@type v1, v2, v3: L{Vector}

@return: angle
@rtype: float

Definition at line 158 of file Vector.py.

00158 
00159 def calc_angle(v1, v2, v3):
00160     """
00161     Calculate the angle between 3 vectors
00162     representing 3 connected points.
00163 
00164     @param v1, v2, v3: the tree points that define the angle
00165     @type v1, v2, v3: L{Vector}
00166     
00167     @return: angle
00168     @rtype: float
00169     """
00170     v1=v1-v2
00171     v3=v3-v2
00172     return v1.angle(v3)

Here is the caller graph for this function:

def Bio.PDB.Vector.calc_dihedral (   v1,
  v2,
  v3,
  v4 
)
Calculate the dihedral angle between 4 vectors
representing 4 connected points. The angle is in
]-pi, pi].

@param v1, v2, v3, v4: the four points that define the dihedral angle
@type v1, v2, v3, v4: L{Vector}

Definition at line 173 of file Vector.py.

00173 
00174 def calc_dihedral(v1, v2, v3, v4):
00175     """
00176     Calculate the dihedral angle between 4 vectors
00177     representing 4 connected points. The angle is in
00178     ]-pi, pi].
00179 
00180     @param v1, v2, v3, v4: the four points that define the dihedral angle
00181     @type v1, v2, v3, v4: L{Vector}
00182     """
00183     ab=v1-v2
00184     cb=v3-v2
00185     db=v4-v3
00186     u=ab**cb
00187     v=db**cb
00188     w=u**v
00189     angle=u.angle(v)
00190     # Determine sign of angle
00191     try:
00192         if cb.angle(w)>0.001:
00193             angle=-angle
00194     except ZeroDivisionError:
00195         # dihedral=pi
00196         pass
00197     return angle

Here is the caller graph for this function:

Return angles, axis pair that corresponds to rotation matrix m.

Definition at line 11 of file Vector.py.

00011 
00012 def m2rotaxis(m):
00013     """
00014     Return angles, axis pair that corresponds to rotation matrix m.
00015     """
00016     # Angle always between 0 and pi
00017     # Sense of rotation is defined by axis orientation
00018     t=0.5*(numpy.trace(m)-1)
00019     t=max(-1, t)
00020     t=min(1, t)
00021     angle=numpy.arccos(t)
00022     if angle<1e-15:
00023         # Angle is 0
00024         return 0.0, Vector(1,0,0)
00025     elif angle<numpy.pi:
00026         # Angle is smaller than pi
00027         x=m[2,1]-m[1,2]
00028         y=m[0,2]-m[2,0]
00029         z=m[1,0]-m[0,1]
00030         axis=Vector(x,y,z)
00031         axis.normalize()
00032         return angle, axis
00033     else:
00034         # Angle is pi - special case!
00035         m00=m[0,0]
00036         m11=m[1,1]
00037         m22=m[2,2]
00038         if m00>m11 and m00>m22:
00039             x=numpy.sqrt(m00-m11-m22+0.5)
00040             y=m[0,1]/(2*x)
00041             z=m[0,2]/(2*x)
00042         elif m11>m00 and m11>m22:
00043             y=numpy.sqrt(m11-m00-m22+0.5)
00044             x=m[0,1]/(2*y)
00045             z=m[1,2]/(2*y)
00046         else:
00047             z=numpy.sqrt(m22-m00-m11+0.5)
00048             x=m[0,2]/(2*z)
00049             y=m[1,2]/(2*z)
00050         axis=Vector(x,y,z)
00051         axis.normalize()
00052         return numpy.pi, axis
00053 

def Bio.PDB.Vector.refmat (   p,
  q 
)
Return a (left multiplying) matrix that mirrors p onto q.

Example:
    >>> mirror=refmat(p,q)
    >>> qq=p.left_multiply(mirror)
    >>> print q, qq # q and qq should be the same

@type p,q: L{Vector}
@return: The mirror operation, a 3x3 Numeric array. 

Definition at line 114 of file Vector.py.

00114 
00115 def refmat(p,q):
00116     """
00117     Return a (left multiplying) matrix that mirrors p onto q.
00118 
00119     Example:
00120         >>> mirror=refmat(p,q)
00121         >>> qq=p.left_multiply(mirror)
00122         >>> print q, qq # q and qq should be the same
00123 
00124     @type p,q: L{Vector}
00125     @return: The mirror operation, a 3x3 Numeric array. 
00126     """
00127     p.normalize()
00128     q.normalize()
00129     if (p-q).norm()<1e-5:
00130         return numpy.identity(3)
00131     pq=p-q
00132     pq.normalize()
00133     b=pq.get_array()
00134     b.shape=(3, 1)
00135     i=numpy.identity(3)
00136     ref=i-2*numpy.dot(b, numpy.transpose(b))
00137     return ref

Here is the caller graph for this function:

def Bio.PDB.Vector.rotaxis2m (   theta,
  vector 
)
Calculate a left multiplying rotation matrix that rotates
theta rad around vector.

Example: 

    >>> m=rotaxis(pi, Vector(1,0,0))
    >>> rotated_vector=any_vector.left_multiply(m)

@type theta: float
@param theta: the rotation angle


@type vector: L{Vector}
@param vector: the rotation axis

@return: The rotation matrix, a 3x3 Numeric array.

Definition at line 72 of file Vector.py.

00072 
00073 def rotaxis2m(theta, vector):
00074     """
00075     Calculate a left multiplying rotation matrix that rotates
00076     theta rad around vector.
00077 
00078     Example: 
00079     
00080         >>> m=rotaxis(pi, Vector(1,0,0))
00081         >>> rotated_vector=any_vector.left_multiply(m)
00082 
00083     @type theta: float
00084     @param theta: the rotation angle
00085 
00086 
00087     @type vector: L{Vector}
00088     @param vector: the rotation axis
00089 
00090     @return: The rotation matrix, a 3x3 Numeric array.
00091     """
00092     vector=vector.copy()
00093     vector.normalize()
00094     c=numpy.cos(theta)
00095     s=numpy.sin(theta)
00096     t=1-c
00097     x,y,z=vector.get_array()
00098     rot=numpy.zeros((3,3))
00099     # 1st row
00100     rot[0,0]=t*x*x+c
00101     rot[0,1]=t*x*y-s*z
00102     rot[0,2]=t*x*z+s*y
00103     # 2nd row
00104     rot[1,0]=t*x*y+s*z
00105     rot[1,1]=t*y*y+c
00106     rot[1,2]=t*y*z-s*x
00107     # 3rd row
00108     rot[2,0]=t*x*z-s*y
00109     rot[2,1]=t*y*z+s*x
00110     rot[2,2]=t*z*z+c
00111     return rot
00112 
00113 rotaxis=rotaxis2m

def Bio.PDB.Vector.rotmat (   p,
  q 
)
Return a (left multiplying) matrix that rotates p onto q.

Example:
    >>> r=rotmat(p,q)
    >>> print q, p.left_multiply(r)

@param p: moving vector
@type p: L{Vector}

@param q: fixed vector
@type q: L{Vector}

@return: rotation matrix that rotates p onto q
@rtype: 3x3 Numeric array

Definition at line 138 of file Vector.py.

00138 
00139 def rotmat(p,q):
00140     """
00141     Return a (left multiplying) matrix that rotates p onto q.
00142 
00143     Example:
00144         >>> r=rotmat(p,q)
00145         >>> print q, p.left_multiply(r)
00146 
00147     @param p: moving vector
00148     @type p: L{Vector}
00149 
00150     @param q: fixed vector
00151     @type q: L{Vector}
00152 
00153     @return: rotation matrix that rotates p onto q
00154     @rtype: 3x3 Numeric array
00155     """
00156     rot=numpy.dot(refmat(q, -p), refmat(p, -p))
00157     return rot

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PDB.Vector.vector_to_axis (   line,
  point 
)
Returns the vector between a point and
the closest point on a line (ie. the perpendicular
projection of the point on the line).

@type line: L{Vector}
@param line: vector defining a line

@type point: L{Vector}
@param point: vector defining the point

Definition at line 54 of file Vector.py.

00054 
00055 def vector_to_axis(line, point):
00056     """
00057     Returns the vector between a point and
00058     the closest point on a line (ie. the perpendicular
00059     projection of the point on the line).
00060 
00061     @type line: L{Vector}
00062     @param line: vector defining a line
00063 
00064     @type point: L{Vector}
00065     @param point: vector defining the point
00066     """
00067     line=line.normalized()
00068     np=point.norm()
00069     angle=line.angle(point)
00070     return point-line**(np*numpy.cos(angle))
00071 


Variable Documentation

tuple Bio.PDB.Vector.angle = random()

Definition at line 372 of file Vector.py.

tuple Bio.PDB.Vector.axis = Vector(random(3)-random(3))

Definition at line 373 of file Vector.py.

Definition at line 328 of file Vector.py.

tuple Bio.PDB.Vector.m = rotaxis(angle, axis)

Definition at line 376 of file Vector.py.

Definition at line 333 of file Vector.py.

Definition at line 334 of file Vector.py.

tuple Bio.PDB.Vector.v1 = Vector(0,0,1)

Definition at line 318 of file Vector.py.

tuple Bio.PDB.Vector.v2 = Vector(0,0,0)

Definition at line 319 of file Vector.py.

tuple Bio.PDB.Vector.v3 = Vector(0,1,0)

Definition at line 320 of file Vector.py.

tuple Bio.PDB.Vector.v4 = Vector(1,1,0)

Definition at line 321 of file Vector.py.