mdsuite.utils.linalg module¶
MDSuite: A Zincwarecode package.
License¶
This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zincwarecode Project.
Contact Information¶
email: zincwarecode@gmail.com github: https://github.com/zincware web: https://zincwarecode.com/
Citation¶
If you use this module please cite us with:
Summary¶
- mdsuite.utils.linalg.angle_between(v1, v2, acos=True)[source]¶
Returns the angle in radians between vectors ‘v1’ and ‘v2’.
- mdsuite.utils.linalg.apply_minimum_image(r_ij, box_array)[source]¶
- Parameters:
r_ij (tf.Tensor) – an r_ij matrix of size (batches, atoms, 3)
box_array (tf.Tensor) – a box array (3,)
- mdsuite.utils.linalg.apply_system_cutoff(tensor: Tensor, cutoff: float) Tensor [source]¶
Enforce a cutoff on a tensor.
- Parameters:
tensor (tf.Tensor) –
cutoff (flaot) –
- mdsuite.utils.linalg.cartesian_to_spherical_coordinates(point_cartesian, name='cartesian_to_spherical_coordinates')[source]¶
References
Function to transform Cartesian coordinates to spherical coordinates. This function assumes a right handed coordinate system with z pointing up. When x and y are both 0, the function outputs 0 for phi. Note that the function is not smooth when x = y = 0. .. note:: In the following, A1 to An are optional batch dimensions.
- Parameters:
point_cartesian – A tensor of shape [A1, …, An, 3]. In the last dimension, the data follows the x, y, z order.
eps – A small float, to be added to the denominator. If left as None, its value is automatically selected using point_cartesian.dtype.
name – A name for this op. Defaults to “cartesian_to_spherical_coordinates”.
- Returns:
A tensor of shape [A1, …, An, 3]. The last dimensions contains
(r,`theta`,`phi`), where r is the sphere radius, theta is the polar
angle and phi is the azimuthal angle. Returns NaN gradient if x = y = 0.
- mdsuite.utils.linalg.get2dHistogram(x, y, value_range, nbins=100, dtype=tf.int32)[source]¶
Bins x, y coordinates of points onto simple square 2d histogram.
Given the tensor x and y: x: x coordinates of points y: y coordinates of points this operation returns a rank 2 Tensor representing the indices of a histogram into which each element of values would be binned. The bins are equal width and determined by the arguments value_range and nbins.
- Parameters:
x (value_range[0] lims for) –
y (value_range[1] lims for) –
x –
y –
nbins (Scalar int32 Tensor. Number of histogram bins.) –
dtype (dtype for returned histogram.) –
References
https://gist.github.com/isentropic/a86effab2c007e86912a50f995cac52b
- mdsuite.utils.linalg.get_angles(r_ij_mat, indices, acos=True)[source]¶
Compute the cosine angle for the given triples.
Using :math theta = acos(r_ij * r_ik / (|r_ij| * |r_ik|))
- Parameters:
acos (bool) – Apply tf.math.acos to the output if true. default true.
r_ij_mat (tf.Tensor) – r_ij matrix. Shape is (n_timesteps, n_atoms, n_atoms, 3)
indices (tf.Tensor) – Indices of the triples. Shape is (triples, 4) where a single element is composed of (timestep, idx, jdx, kdx)
- Returns:
tf.Tensor
- Return type:
Tensor with the shape (triples)
- mdsuite.utils.linalg.get_partial_triu_indices(n_atoms: int, m_atoms: int, idx: int) Tensor [source]¶
Calculate the indices of a slice of the triu values.
- Parameters:
n_atoms (total number of atoms in the system) –
m_atoms (size of the slice (horizontal)) –
idx (start index of slize) –
- Return type:
tf.Tensor
- mdsuite.utils.linalg.spherical_to_cartesian_coordinates(point_spherical, name='spherical_to_cartesian_coordinates')[source]¶
References
Function to transform Cartesian coordinates to spherical coordinates. .. note:: In the following, A1 to An are optional batch dimensions.
- Parameters:
point_spherical – A tensor of shape [A1, …, An, 3]. The last dimension contains r, theta, and phi that respectively correspond to the radius, polar angle and azimuthal angle; r must be non-negative.
name – A name for this op. Defaults to “spherical_to_cartesian_coordinates”.
- Raises:
tf.errors.InvalidArgumentError – If r, theta or phi contains out of range:
data. –
- Returns:
A tensor of shape [A1, …, An, 3], where the last dimension contains the
cartesian coordinates in x,y,z order.