p3d.vector module

From p3d
Jump to: navigation, search

The vector module holds the Vector class with a set of linear algebra functions. The Atom class inherits all properties from the Vector class thus allowing vector operations at an atomic level. The history of operations is collected in the Vector.desc property.

Vector class

p3d.vector.Vector(x,y,z)

Initialisation of an Vector object requires three float values corresponding to the x,y & z coordinates.

Attributes

x ⇒ x coordinate

y ⇒ y coordinate

z ⇒ z coordinate

desc ⇒ placeholder for history log of vector operations

Methods

The examples shown use

a = p3d.vector.Vector(1,1,1)
b = p3d.vector.Vector(2,2,2)
s = 0.4

.. any Atom will also work.

Information
returns information about the atom/vector object. Optional values for lvl:
optional key is:
lvl
usage: the lvl keyword will allow to specify the amount of data returned for the given atom/vector.
lvl=
  • none (default) Returns coordinates only
  • min Returns atom type, resname, chain and residue ID
  • max Returns atom type, resname, chain, alternative conformer labelling and coordinates
 >>> a.info()
'[   1.000,   1.000,   1.000]'
>>> a.info(lvl='min')
'       uNk uNk     -1'
>>> a.info(lvl='max')
'       uNk uNk     -1  [   1.000,   1.000,   1.000]'
Addition
returns a new vector object
 >>> (a+b).info()
 '[   3.000,   3.000,   3.000]'
Subtraction
returns new Vector = a - b, resulting Vector points towards a.
 >>> (a-b).info()
 '[  -1.000,  -1.000,  -1.000]'
Multiplication
returns a scaled Vector = a * s
 >>> (a*s).info()
 '[   0.400,   0.400,   0.400]'
 >>> (s*a).info()
 '[   0.400,   0.400,   0.400]'
Division
returns a scaled Vector = a / s
 >>> (a/s).info()
 '[   2.500,   2.500,   2.500]'
Absolute
returns length (float) of the vector/atom
 >>> abs(b)
3.4641016151377544
Dot product
returns (float) dot product of the two vectors
 >>> a.dot(b)
 6
Cross product
returns cross product (Vector) of the two vectors
 >>> a.cross(b).info()
 '[   0.000,   0.000,   0.000]'
Normalise
returns normalized vector, i.e. length == 1
 >>> b.normalize().info()
 '[   0.577,   0.577,   0.577]'
Translate
returns vector that has been translated by argument vector
 >>> a.translateBy(b).info()
 '[   3.000,   3.000,   3.000]'
Distance
returns distance (float) between two vectors
 >>> a.distanceTo(b)
1.7320508075688772
Angle between two Vectors
returns angle (float) between two vectors
 >>> a.angleBetween(b)
0.0
VMD output
returns string that can be used in the VMD tk console to draw a sphere at given vector coordinates. Optional keyword radius=(float) can be given to define size of sphere.
 >>> a.vmdOutput()
'graphics 0 sphere 3 3 3 radius 0.2;'
Evaluation of distance

Offers a faster way to test if two vectors are within a given distance.

returns distance (float) if the two vectors are within a given distance and false otherwise. Squared distance is recursively evaluated against each dimension prior to the square root operation.
 >>> a.evalDistance(b,2)
1.7320508075688772
>>> a.evalDistance(b,1)
False
Output
returns a formatted PDB file line generate from the atom/vector object. Currently supported formats are:
  • pdb (default)
 >>> a.output(format='pdb')
'p3dVec   -1uNk   uNk    -1       1.000   1.000   1.000 777.70 777.70'