Linear Algebra

Linear Algebra

linear_algebra.calculate_angle(a, b, c)[source]

Calculates the dihedral angle between three vectors

Parameters
a
float list : vector a
b
float list : vector b
c
float list : vector c
Returns:angle in radians
Return type:float

Examples

>>> import sasmol.linear_algebra as linear_algebra
>>> a = numpy.array([1.0, 2.0, 3.0])
>>> b = numpy.array([-1.0, 6.0, 8.0])
>>> c = numpy.array([-4.0, -1.0, 4.0])
>>> linear_algebra.calculate_angle(a, b, c)
0.7556508878558726
linear_algebra.cross_product(a, b)[source]

Returns cross product (vector product) on two vectors

Parameters
a
float list : vector a
b
float list : vector b
Returns:
Return type:numpy.array of cross product

Examples

>>> import sasmol.linear_algebra as linear_algebra
>>> a = [1.0, 2.0, 3.0]
>>> b = [-1.0, 6.0, 8.0]
>>> linear_algebra.cross_product(a, b)
array([ -2., -11.,   8.])
linear_algebra.dihedral_angle(a1, a2, a3, a4)[source]

Calculates the dihedral angle between four vectors

Parameters
a1
float list : vector a1
a2
float list : vector a2
a3
float list : vector a3
a4
float list : vector a4
Returns:dihedral angle in degrees
Return type:float

Examples

>>> import sasmol.linear_algebra as linear_algebra
>>> a1 = numpy.array([1.0, 2.0, 3.0])
>>> a2 = numpy.array([-1.0, 6.0, 8.0])
>>> a3 = numpy.array([-4.0, -1.0, 4.0])
>>> a4 = numpy.array([-3.0, -41, 3.0])
>>> linear_algebra.dihedral_angle(a1, a2, a3, a4)
85.950635659264
linear_algebra.find_u(x, y)[source]

Method to find the U matrix used to align two sets of 3 x 3 coordinate arrays

Parameters
x
numpy array : 3 x 3
y
numpy array : 3 x 3
Returns:containing U matrix for alignment of two vectors
Return type:numpy.array

Examples

>>> import sasmol.linear_algebra as linear_algebra
>>> import numpy
>>> a = numpy.array([[[1.0, 2.0, 3.0],[1.0, 2.0, 3.0],[1.0, 2.0, 3.0]],[[1.0, 2.0, 3.0],[1.0, 2.0, 3.0],[1.0, 2.0, 3.0]],[[1.0, 2.0, 3.0],[1.0, 2.0, 3.0],[1.0, 2.0, 3.0]]])
>>> b = numpy.array([[[-1.0, 6.0, 8.0],[-1.0, 6.0, 8.0],[-1.0, 6.0, 8.0]],[[-1.0, 6.0, 8.0],[-1.0, 6.0, 8.0],[-1.0, 6.0, 8.0]],[[-1.0, 6.0, 8.0],[-1.0, 6.0, 8.0],[-1.0, 6.0, 8.0]]])
>>> b = [-1.0, 6.0, 8.0]
>>> linear_algebra.find_u(a, b)
array([[-0.33333333, -0.33333333, -0.33333333],
    [-0.33333333, -0.33333333, -0.33333333],
    [-0.33333333, -0.33333333, -0.33333333]])
linear_algebra.matrix_multiply(a, b)[source]

Returns the result of multiplying matrix a by matrix b

Parameters
a
float list : matrix a
b
float list : matrix b
Returns:
error
list with error code (if error occurs)

numpy.array of matrix product

Return type:tuple

Examples

>>> import sasmol.linear_algebra as linear_algebra
>>> import numpy
>>> a=numpy.array([[5.0, 3.0, 1.0],[2.0, 3.0, 5.0]])
>>> b=numpy.array([[2.0, -4.0, 8.0]]).T
>>> linear_algebra.matrix_multiply(a, b)
([], array([[  6.],
   [ 32.]]))
linear_algebra.signed_angle(a, b, c)[source]

This method calcultes the sign of the angle which is used in the calculation of a dihedral angle. As such, this method is not validated for other uses. It will fail if the basis atoms for the dihedral (atom 2 and atom 3) overlap.

Parameters
a
float list : vector a
b
float list : vector b
c
float list : vector c
Returns:signed angle in degrees
Return type:float

Examples

>>> import sasmol.linear_algebra as linear_algebra
>>> a = [1.0, 2.0, 3.0]
>>> b = [-1.0, 6.0, 8.0]
>>> c = [-4.0, -1.0, 4]
>>> linear_algebra.signed_angle(a, b, c)
21.444512921997863