Utilities

General utility functions used throughout AaronTools

AaronTools.utils.utils.range_list(number_list, sep=',', sort=True)

Takes a list of numbers and puts them into a string containing ranges, eg: [1, 2, 3, 5, 6, 7, 9, 10] -> “1-3,5-7,9,10”

Parameters:
  • sep (str) – the separator to use between consecutive ranges

  • sort (bool) – sort the list before parsing

AaronTools.utils.utils.proj(v_vec, u_vec)

projection of u_vec into v_vec

Parameters:
  • v_vec (nparray) –

  • u_vec (nparray) – should have the same shape as v_vec

Returns:

projection

Return type:

nparray

AaronTools.utils.utils.quat_matrix(pt1, pt2)

build quaternion matrix from pt1 and pt2

AaronTools.utils.utils.uptri2sym(vec, n=None, col_based=False)

Converts upper triangular matrix to a symmetric matrix

Parameters:
  • vec (np.ndarray) – the upper triangle array/matrix

  • n (int) – the number of rows/columns

  • col_based (bool) –

    if true, triangular matirx is of the form

    0 1 3 - 2 4 - - 5

    if false, triangular matrix is of the form

    0 1 2 - 3 4 - - 5

AaronTools.utils.utils.float_vec(word)

Turns strings into floating point vectors

Parameters:

word (str) – a comma-delimited string of numbers

if no comma or only one element: :returns: just the floating point number

if elements in word are strings: :returns: word unchanged

else :returns: a np.array() of floating point numbers

AaronTools.utils.utils.add_dict(this, other, skip=None)
Parameters:

skip (list) – items to avoid adding

Returns:

self

AaronTools.utils.utils.resolve_concatenation(*args)
Return type:

list

AaronTools.utils.utils.combine_dicts(*args, case_sensitive=False, dict2_conditional=False)

combine dictionaries d1 and d2 to return a dictionary with keys d1.keys() + d2.keys()

if a key is in d1 and d2, the items will be combined:

if they are both dictionaries, combine_dicts is called recursively otherwise, d2[key] is appended to d1[key]

if case_sensitive=False, the key in the output will be the lowercase of the d1 key and d2 key (only for combined items)

Parameters:
  • case_sensitive (bool) – considers letter case when True

  • dict2_conditional (bool) – if True, don’t add d2 keys unless they are also in d1

AaronTools.utils.utils.subtract_dicts(*args, case_sensitive=False)

removes items in d2 from d1 to return a new dictionary

Parameters:

case_sensitive (bool) – considers letter case when True

AaronTools.utils.utils.integrate(fun, start, stop, num=101)

numerical integration using Simpson’s method

Parameters:
  • fun (function) – function to integrate

  • start (float) – starting point for integration

  • stop (float) – stopping point for integration

  • num (int) – number of points used for integration

AaronTools.utils.utils.same_cycle(graph, a, b)

Determines if Atom a and Atom b are in the same cycle in an undirected graph

Returns:

True if cycle found containing a and b, False otherwise

Return type:

boolean

Parameters:
  • graph (list|Geometry) – connectivity matrix or Geometry

  • a (int|Atom) – index in connectivity matrix/Geometry or Atoms in Geometry

  • b (int|Atom) – index in connectivity matrix/Geometry or Atoms in Geometry

AaronTools.utils.utils.shortest_path(graph, start, end)

Find shortest path from start to end in graph using Dijkstra’s algorithm

Parameters:
  • graph (list|Geometry) – the connection matrix or Geometry

  • start (int|Atom) – the first atom or node index

  • end (int|Atom) – the last atom or node index

Returns:

list(node_index) if path found, None if path not found

AaronTools.utils.utils.prune_branches(graph)

modifies graph in place to remove parts that don’t connect to other parts of the graph graph is a list of lists defining the connectivity i.e. only cycles are kept

AaronTools.utils.utils.to_closing(string, brace, allow_escapes=False)

returns the portion of string from the beginning to the closing paratheses or bracket denoted by brace

brace can be ‘(’, ‘{’, or ‘[’

if the closing paratheses is not found, returns None instead

AaronTools.utils.utils.rotation_matrix(theta, axis, renormalize=True)

rotation matrix for rotating theta radians about axis

AaronTools.utils.utils.mirror_matrix(norm, renormalize=True)

mirror matrix for the specified norm

AaronTools.utils.utils.fibonacci_sphere(radius=1, center=array([0., 0., 0.]), num=500)

returns a grid of points that are equally spaced on a sphere with the specified radius and center number of points can be adjusted with num

AaronTools.utils.utils.lebedev_sphere(radius=1, center=array([0., 0., 0.]), num=302)

returns one of the Lebedev grid points (xi, yi, zi) and weights (wi) with the specified radius and center. Weights do not include r**2, so integral of F(x,y,z) over sphere is 4*pi*r**2sum_i{F(xi,yi,zi)wi}. The number of points (num) must be one of 110, 194, 302, 590, 974, 1454, 2030, 2702, 5810

Parameters:
  • radius (float) – radius of sphere

  • center (np.ndarray) – center of sphere

  • num (int) – number of points in the grid

AaronTools.utils.utils.gauss_legendre_grid(start=-1, stop=1, num=32)

returns a Gauss-Legendre grid points (xi) and weights (wi)for the range start to stop. Integral over F(x) is sum_i{F(xi)wi}. The number of points (num) must be one of 20, 32, 64, 75, 99, 127

Parameters:
  • start (float) – starting coordinate

  • stop (float) – final coordinate coordinate

  • num (int) – number of points in the grid

AaronTools.utils.utils.perp_vector(vec)

returns a vector orthonormal to vec (np.ndarray)

if vec is 2D, returns a vector orthonormal to the plane of best for the rows of vec

AaronTools.utils.utils.get_filename(path, include_parent_dir=True)

returns the name of the file without parent directories or extension

AaronTools.utils.utils.boltzmann_coefficients(energies, temperature, absolute=True)

returns boltzmann weights for the energies and T

Parameters:
  • energies (np.ndarray) – energies in kcal/mol

  • temperature (float) – T in K

  • absolute (bool) – True if the energies given are absolute, false if they are relative energies

AaronTools.utils.utils.boltzmann_average(energies, values, temperature, absolute=True)

returns the AVT result for the values corresponding to the energies

Parameters:
  • energies (np.ndarray) – energies in kcal/mol

  • values (np.ndarray) – values for which the weighting is applied; the ith value corresponds to the ith energy

  • temperature (float) – T in K

  • absolute (bool) – True if the energies given are absolute, false if they are relative energies

AaronTools.utils.utils.glob_files(infiles, parser=None, escape_brackets=True)

globs input files used for command line scripts because Windows doesn’t support globbing…

AaronTools.utils.utils.angle_between_vectors(v1, v2, renormalize=True)

returns the angle between v1 and v2 (numpy arrays)

AaronTools.utils.utils.getuser()

returns the username of the user

AaronTools.utils.utils.available_memory()

returns available memory in B

AaronTools.utils.utils.pascals_triangle(n)

returns row n of pascal’s triangle

AaronTools.utils.utils.get_outfile(basename, **substitutions)

replace text

AaronTools.utils.utils.xyzzy_cross(v1, v2)

quick cross product of two 3-D vectors