num
cartesian_product(*arrays)
Efficiently calculate the Cartesian product of the provided vectors A x B x C ... etc. This will maintain order in loops from the right most array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*arrays |
array_like
|
1D arrays to use for the Cartesian product |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The Cartesian product of the provided vectors. |
Source code in chmpy/util/num.py
cartesian_to_spherical(xyz, dtype=np.float64)
Given an N by 3 array of (x, y, z) spherical coordinates return an N by 3 array of Cartesian(r, theta, phi) coordinates.
Uses the following convention::
x = r sin(theta) cos(phi)
y = r sin(theta) sin(phi)
z = r cos(theta)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rtp |
array_like
|
(N,3) array of of r, theta, phi coordinates in the above spherical coordinate system. |
required |
dtype |
numpy datatype or string |
float64
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: (N,3) array of x,y,z Cartesian coordinates |
Source code in chmpy/util/num.py
cartesian_to_spherical_mgrid(x, y, z)
Given 3 arrays of of (x, y, z) Cartesian coordinates return 3 arrays of of spherical (r, theta, phi) coordinates.
Uses the following convention::
x = r sin(theta) cos(phi)
y = r sin(theta) sin(phi)
z = r cos(theta)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
array_like
|
(N) array of of z coordinates in the above spherical coordinate system. |
required |
y |
array_like
|
(N) array of of y coordinates in the above spherical coordinate system. |
required |
z |
array_like
|
(N) array of of z coordinates in the above spherical coordinate system. |
required |
Returns: Tuple[np.ndarray]: 3 arrays of r, theta, phi spherical coordinates
Source code in chmpy/util/num.py
is_perfect_square(value)
Check if a number is perfect square.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Number
|
the number in question |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
Source code in chmpy/util/num.py
kabsch_rotation_matrix(A, B)
Calculate the optimal rotation matrix R
to rotate
A
onto B
, minimising root-mean-square deviation so that
this may be then calculated.
See https://en.wikipedia.org/wiki/Kabsch_algorithm
References
Kabsch, W. Acta Cryst. A, 32, 922-923, (1976) DOI: http://dx.doi.org/10.1107/S0567739476001873
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
ndarray
|
(N,D) matrix where N is the number of vectors and D is the dimension of each vector |
required |
B |
ndarray
|
(N,D) matrix where N is the number of vectors and D is the dimension of each vector |
required |
Returns: np.ndarray (D,D) rotation matrix where D is the dimension of each vector
Source code in chmpy/util/num.py
reorient_points(A, B, method='kabsch')
Rotate the points in A
onto B
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
ndarray
|
(N,D) matrix where N is the number of vectors and D is the dimension of each vector |
required |
B |
ndarray
|
(N,D) matrix where N is the number of vectors and D is the dimension of each vector |
required |
Returns:
Type | Description |
---|---|
np.ndarray: (N,D) matrix where N is the number of vectors and D is the dimension of each vector, now rotated to align with B |
Source code in chmpy/util/num.py
rmsd_points(A, B, reorient='kabsch')
Rotate the points in A
onto B
and calculate
their RMSD
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
ndarray
|
(N,D) matrix where N is the number of vectors and D is the dimension of each vector |
required |
B |
ndarray
|
(N,D) matrix where N is the number of vectors and D is the dimension of each vector |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
root mean squared deviation |
Source code in chmpy/util/num.py
spherical_to_cartesian(rtp, dtype=np.float64)
Given an N by 3 array of (r, theta, phi) spherical coordinates return an N by 3 array of Cartesian(x, y, z) coordinates.
Uses the following convention::
x = r sin(theta) cos(phi)
y = r sin(theta) sin(phi)
z = r cos(theta)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rtp |
array_like
|
(N,3) array of of r, theta, phi coordinates in the above spherical coordinate system. |
required |
dtype |
numpy datatype or string |
float64
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: (N,3) array of x,y,z Cartesian coordinates |
Source code in chmpy/util/num.py
spherical_to_cartesian_mgrid(r, t, p)
Given 3 arrays of (r, theta, phi) spherical coordinates return 3 arrays of Cartesian(x, y, z) coordinates.
Uses the following convention::
x = r sin(theta) cos(phi)
y = r sin(theta) sin(phi)
z = r cos(theta)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r |
array_like
|
array of of r coordinates in the above spherical coordinate system. |
required |
t |
array_like
|
array of of theta coordinates in the above spherical coordinate system. |
required |
p |
array_like
|
array of phi coordinates in the above spherical coordinate system. |
required |
dtype |
numpy datatype or string |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray]: 3 arrays of x,y,z Cartesian coordinates |