Matrix routines

Because matrices are rather large when expressed in text form, the following definitions are used for the examples.

**transidentity**- Returns the identity matrix.Example: vmd > transidentity Info) {1.0 0.0 0.0 0.0} {0.0 1.0 0.0 0.0} {0.0 0.0 1.0 0.0} {0.0 0.0 0.0 1.0}

**transtranspose**- Returns the matrix transpose of the given matrix*m*Example: vmd > transtranspose {{0 1 2 3 4} {5 6 7 8} {9 10 11 12} {13 14 15 16}} Info) {0 5 9 13} {1 6 10 14} {2 7 11 15} {3 8 12 16}

- (C++)
**transmult**- Returns the matrix multiplication of the given matrices*m1 m2*[*m3 ... mn*]Examples: vmd > set mat1 {{1 2 3 4} {-2 3 -4 5} {3 -4 5 -6} {4 5 -6 -7}} vmd > set mat2 {{1 0 0 0} {0 0.7071 -0.7071 0} {0 0.7071 0.7071 0} {0 0 0 1}} vmd > set mat3 {{0.866025 0 0 0} {0 1 0 0} {-0.5 0 0.866025 0} {0 0 0 1}} vmd > transmult $mat1 [transidentity] Info) {1.0 2.0 3.0 4.0} {-2.0 3.0 -4.0 5.0} {3.0 -4.0 5.0 -6.0} {4.0 5.0 -6.0 -7.0} vmd > transmult $mat1 $mat2 $mat3 Info) {0.512475 3.5355 0.612366 4.0} {0.7428 -0.7071 -4.28656 5.0} {-0.58387 0.7071 5.5113 -6.0} {7.35315 -0.7071 -6.73603 -7.0}

**transaxis x**- Returns the transformation matrix needed to rotate around the specified axis by a given amount. By default, the amount is specified in degrees, though it can also be given in radians or factors of pi.`|`

y`|`

z*amount*[deg`|`

rad`|`

pi]Examples: vmd > transaxis x 90 Info) {1.0 0.0 0.0 0.0} {0.0 -3.67321e-06 -1.0 0.0} {0.0 1.0 -3.67321e-06 0.0} {0.0 0.0 0.0 1.0} vmd > transaxis y 0.25 pi Info) {0.707107 0.0 0.707107 0.0} {0.0 1.0 0.0 0.0} {-0.707107 0.0 0.707107 0.0} {0.0 0.0 0.0 1.0} vmd > transaxis z 3.1415927 rad Info) {-1.0 -2.65359e-06 0.0 0.0} {2.65359e-06 -1.0 0.0 0.0} {0.0 0.0 1.0 0.0} {0.0 0.0 0.0 1.0}

**transvec**- Returns the transformation matrix needed to bring the x axis along the v vector. This matrix is not unique, since a final rotation is allowed around the vector. The matrix is made from a rotation around y, then one about z.*v*Examples: vmd > transvec {0 1 0} Info) {-3.67321e-06 -1.0 0.0 0.0} {1.0 -3.67321e-06 0.0 0.0} {0.0 0.0 1.0 0.0} {0.0 0.0 0.0 1.0} vmd > vectrans [transvec {0 0 2}] {1 0 0} Info) 0.0 0.0 1.0

**transvecinv**- Returns the transformation needed to bring the vector v to the x axis. This produces the inverse matrix to transvec, and is composed of a rotation about z then one about y.*v*Examples: vmd > transvecinv {0 -1 0} Info) {-3.67321e-06 -1.0 0.0 0.0} {1.0 -3.67321e-06 0.0 0.0} {0.0 0.0 1.0 0.0} {0.0 0.0 0.0 1.0} vmd > vectrans [transvecinv {-3 4 -12}] {-3 4 -12} Info) 13.0 -1.8e-05 5.8e-05 vmd > transmult [transvec {6 -5 7}] [transvecinv {6 -5 7}] Info) {0.999999 2.29254e-07 -6.262e-09 0.0} {2.29254e-07 0.999999 -4.52228e-07 0.0} {-6.262e-09 -4.52228e-07 1.0 0.0} {0.0 0.0 0.0 1.0}

- (C++)
**transoffset**- Returns the transformation matrix needed to translate by the given offset*v*Examples: vmd > transoffset {1 0 0} Info) {1.0 0.0 0.0 1} {0.0 1.0 0.0 0} {0.0 0.0 1.0 0} {0.0 0.0 0.0 1.0} vmd > transoffset {-6 5 -4.3} Info) {1.0 0.0 0.0 -6} {0.0 1.0 0.0 5} {0.0 0.0 1.0 -4.3} {0.0 0.0 0.0 1.0}

**transabout**- Generates the transformation matrix needed to rotate by the given amount counter-clockwise around axis which goes through the origin and along the given vector. As with transvec, the units of the amount of rotation can be degrees, radians, or multiples of pi.*v amount*[deg`|`

rad`|`

pi]Examples: # this is a rotation about x by 180 degrees vmd > transabout {1 0 0} 180 Info) {1.0 0.0 0.0 0.0} {0.0 -1.0 -2.65359e-06 0.0} {0.0 2.65359e-06 -1.0 0.0} {0.0 0.0 0.0 1.0} # a rotation about z by 90 degrees # (compare this to "transaxis z 90" vmd > transabout {0 0 1} 1.5709 rad Info) {0.999624 -0.027414 0.0 0.0} {0.027414 0.999624 0.0 0.0} {0.0 0.0 1.0 0.0} {0.0 0.0 0.0 1.0} vmd > transabout {1 1 1} 1 pi Info) {-0.333335 0.666665 0.666669 0.0} {0.666668 -0.333334 0.666666 0.0} {0.666666 0.66667 -0.333332 0.0} {0.0 0.0 0.0 1.0}

**trans [center {**-*x y z*}] [origin {*x y z*}] [offset {*x y z*}] [axis x*amount*[rad`|`

deg`|`

pi]] [axis y*amount*[rad`|`

deg`|`

pi]] [axis z*amount*[rad`|`

deg`|`

pi]] [x*amount*[rad`|`

deg`|`

pi]] [y*amount*[rad`|`

deg`|`

pi]] [z*amount*[rad`|`

deg`|`

pi]] [axis {*x y z*}*amount*[rad`|`

deg`|`

pi]] [bond {*x1 y1 z1*} {*x2 y2 z2*}*amount*[rad`|`

deg`|`

pi]] [angle {*x1 y1 z1*} {*x2 y2 z2*} {*x3 y3 z3*}*amount*[rad`|`

deg`|`

pi]]This command can do almost everything the other ones can do, and then some. It is designed to be the main function used for generating transformation matrices.

Using it correctly calls for understanding how it works internally. There are three matrices: centering, rotation, and offset. The centering matrix determines where the center of rotation is located. By default, this is the origin, but it can be changed to pivot about any point. The rotation matrix defines the rotation about that centering point, and the offset matrix defines the final translation after the rotation.

For example, to rotate around a given point, the transformations would be 1) the centering matrix to bring that point to the origin, 2) the rotation about the center, and 3) the final offset to return the origin back to its original location.

The different options for the `trans` command modify the
matrices in various ways.

**-**

**center {**- Sets the centering matrix so that point x y z is brought to the origin*x y z*}**offset {**- Sets the offset matrix so that the origin is brought to x y z*x y z*}**origin {**- Sets both the centering and offset matrices to x y z*x y z*}**axis x**- Adds a rotation about the x axis by the given amount to the rotation matrix*amount*[rad`|`

deg`|`

pi]**axis y**- Adds a rotation about the y axis by the given amount to the rotation matrix*amount*[rad`|`

deg`|`

pi]**axis z**- Adds a rotation about the z axis by the given amount to the rotation matrix*amount*[rad`|`

deg`|`

pi]**axis {**- Adds a rotation of the given amount about the given vector to the rotation matrix*x y z*}*amount*[rad`|`

deg`|`

pi]**bond {**- Sets the center and offset transformations to the first point, and defines a rotation about the bond axis by the given amount.*x1 y1 z1*} {*x2 y2 z2*}*amount*[rad`|`

deg`|`

pi]**angle {**- Sets the center and offset transformation to the second point, and defines a rotation about the axis perpendicular to the plane made by the three points (the vector is computed from the cross product of the vector connecting the first two points with that connected the last two).*x1 y1 z1*} {*x2 y2 z2*} {*x3 y3 z3*}*amount*[rad`|`

deg`|`

pi]