Math helpers (qcip_tools.math
)
API documentation
- qcip_tools.math.BLA(lst)
Return the BLA of the atom in the positions givens.
- Parameters:
lst (list) – list of position
- Return type:
float
- qcip_tools.math.angle(c1, c2, c3)
Get the angle (in degree) between three position. Note that c2 is the center coordinate !!
- Parameters:
c1 (list) – coordinate
c2 (list) – coordinate
c3 (list) – coordinate
- Return type:
float
- qcip_tools.math.angle_vector(v1, v2)
Get the angle (in degree) between two vectors
- Parameters:
v1 (numpy.ndarray) – vector
v2 (numpy.ndarray) – vector
- Return type:
float
- qcip_tools.math.closest_fraction(x, max_denominator=1081080)
A fairly simple algorithm to get the fraction out of a floating number. Try to get as close as possible to
x
.Notice that the maximum denominator is chosen to be the multiplication of the primes (and their even power)
- Parameters:
x (float) – the float
max_denominator (int) – the maximum denominator
- Return type:
tuple(int, int)
- qcip_tools.math.closest_int(x)
Compute the closest integer
- Parameters:
x (float) – a float
- Return type:
int
- qcip_tools.math.conjugate(z)
Get the conjugate complex of z
- Parameters:
z (complex) – complex number
- Returns:
the conjugate
- Return type:
complex
- qcip_tools.math.distance(c1, c2)
Get the distance between two position.
- Parameters:
c1 (list) – coordinate
c2 (list) – coordinate
- Return type:
float
- qcip_tools.math.normalize(c)
Normalize and return the vector
- Parameters:
c (numpy.ndarray|list) – vector
- Return type:
numpy.ndarray
- qcip_tools.math.num_of_unique_permutations(elements)
Get the number of unique elements. Compute the multinomial coefficients:
\[\begin{split}\prod_i^m \left(\begin{matrix}\sum_j^i k_j\\k_i\end{matrix}\right) = \frac{n!}{\prod_i k_i!}.\end{split}\]where \(n\) is the number of elements in the set and \(k_i\) is the number of \(i\) in the set (their multiplicities).
This is equivalent to
len(unique_permutation(elements))
(but faster).- Parameters:
elements (iterable) – a set
- Returns:
length
- Return type:
int
- qcip_tools.math.prod(iterable)
Same as sum(), but multiplying
- Parameters:
iterable (iterable) – an iterable
- Returns:
multiplication
- Return type:
float
- qcip_tools.math.torsion_angle(c1, c2, c3, c4)
Get the torsion angle (in degree) between four position.
- Parameters:
c1 (list) – coordinate
c2 (list) – coordinate
c3 (list) – coordinate
c4 (list) – coordinate
- Return type:
float
- qcip_tools.math.unique_everseen(iterable, key=None)
List unique elements, preserving order. Remember all elements ever seen.
Credit goes to the “recipes” in https://docs.python.org/dev/library/itertools.html.
- Parameters:
iterable (iterable) – any iterable
key (function) – apply a function to each element before checking if seen
- qcip_tools.math.unique_permutations(elements)
Like itertools.permutation(), but yield UNIQUE elements. Iterative. May be not as fast as possible.
Credit to http://stackoverflow.com/a/30558049.
- Parameters:
elements (iterable) – a set of elements