Miscellaneous Tools

This module defines miscellaneous utility functions.

class Everything[source]

A place for everything.

rangeString(lint, sep=' ', rng=' to ', exc=False, pos=True)[source]

Returns a structured string for a given list of integers.

Parameters:
  • lint – integer list or array
  • sep – range or number separator
  • rng – range symbol
  • exc – set True if range symbol is exclusive
  • pos – only consider zero and positive integers
In [1]: from prody.utilities import rangeString

In [2]: lint = [1, 2, 3, 4, 10, 15, 16, 17]

In [3]: rangeString(lint)
Out[3]: '1 to 4 10 15 to 17'

In [4]: rangeString(lint, sep=',', rng='-')
Out[4]: '1-4,10,15-17'

In [5]: rangeString(lint, ',', ':', exc=True)
Out[5]: '1:5,10,15:18'
alnum(string, alt='_', trim=False, single=False)[source]

Replace non alpha numeric characters with alt. If trim is True remove preceding and trailing arg characters. If single is True, contain only a single joining alt character.

importLA()[source]

Returns one of scipy.linalg or numpy.linalg.

dictElement(element, prefix=None, number_multiples=False)[source]

Returns a dictionary built from the children of element, which must be a xml.etree.ElementTree.Element instance. Keys of the dictionary are tag of children without the prefix, or namespace. Values depend on the content of the child. If a child does not have any children, its text attribute is the value. If a child has children, then the child is the value.

intorfloat(x)[source]

Returns int(x), or float(x) upon ValueError.

startswith(this, that)[source]

Returns True if this or that starts with the other.

showFigure()[source]

Call show() function with block=False argument to avoid blocking behavior in non-interactive sessions. If block keyword argument is not recognized, try again without it.

countBytes(arrays, base=False)[source]

Returns total number of bytes consumed by elements of arrays. If base is True, use number of bytes from the base array.

sqrtm(matrix)[source]

Returns the square root of a matrix.

addEnds(x, y, axis=0)[source]

Finds breaks in x, extends them by one position and adds nan at the corresponding position in y. x needs to be an 1-D array, y can be a matrix of column (or row) vectors

isPDB()

match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string

isURL()

match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string

isSymmetric(M, rtol=1e-05, atol=1e-08)[source]

Checks if the matrix is symmetric.

makeSymmetric(M)[source]

Makes sure the matrix is symmetric.

div0(a, b, defval=0.0)[source]

Performs true_divide but ignores the error when division by zero (result is set to zero instead).

wmean(array, weights, axis=None)[source]

Calculates the weighted average of array given axis.

bin2dec(x)[source]

Converts the binary array to decimal.

fixArraySize(arr, sizes, value=0)[source]

Makes sure that arr is of sizes. If not, pad with value.

decToHybrid36(x, resnum=False)[source]

Convert a regular decimal number to a string in hybrid36 format

hybrid36ToDec(x, resnum=False)[source]

Convert string in hybrid36 format to a regular decimal number

checkIdentifiers(*pdb, **kwargs)[source]

Check whether pdb identifiers are valid, and replace invalid ones with None in place.