Rosetta  2020.37
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
pyrosetta.utility.array Namespace Reference

Functions

def to_structured_array
 
def extend_structured_array
 
def assign_by_field_names
 
def structured_array_to_basic
 
def basic_array_to_structured
 
def atom_array_to_coordinates
 
def coordinate_array_to_atoms
 
def rolling_window
 

Variables

string message = "Numpy.*viewing or writing to an array returned by selecting multiple fields in a structured array."
 
 category = FutureWarning,
 
string module = 'pyrosetta.utility.array'
 

Function Documentation

def pyrosetta.utility.array.assign_by_field_names (   to_array,
  from_array 
)
Copy structured array data by equivalent field names.

Copy data from 'from_array' to 'to_array' by matching, potentially nested,
field names. Partially replicates pre-1.13 numpy structured array
assignment behavior.
def pyrosetta.utility.array.atom_array_to_coordinates (   atom_array)
def pyrosetta.utility.array.basic_array_to_structured (   in_array,
  field_names,
  field_dtype = None 
)
Convert basic array to structured array with fields of homogenous dtype.

References ObjexxFCL.len().

Referenced by pyrosetta.utility.array.coordinate_array_to_atoms(), and pyrosetta.numeric.alignment.rmsd_calc.superimpose_structured_array().

def pyrosetta.utility.array.coordinate_array_to_atoms (   coordinate_array,
  atom_names 
)
Convert coordinate buffer into structured array of named atomic positions.

References pyrosetta.utility.array.basic_array_to_structured(), and ObjexxFCL.len().

def pyrosetta.utility.array.extend_structured_array (   source_array,
  extension_dtype 
)
Expand structured array with given fields.

Returns structured array with fields of source_array and fields defined in
extension_dtype. Fields present in source_array are initialzed with values of
source_array. Fields in extension_dtype are zero initialized.
def pyrosetta.utility.array.rolling_window (   array,
  window = (0,,
  asteps = None,
  wsteps = None,
  axes = None,
  toend = True 
)
Create a view of `array` which for every point gives the n-dimensional
neighbourhood of size window. New dimensions are added at the end of
`array` or after the corresponding original dimension.

Parameters
----------
array : array_like
    Array to which the rolling window is applied.
window : int or tuple
    Either a single integer to create a window of only the last axis or a
    tuple to create it for the last len(window) axes. 0 can be used as a
    to ignore a dimension in the window.
asteps : tuple
    Aligned at the last axis, new steps for the original array, ie. for
    creation of non-overlapping windows. (Equivalent to slicing result)
wsteps : int or tuple (same size as window)
    steps for the added window dimensions. These can be 0 to repeat values
    along the axis.
axes: int or tuple
    If given, must have the same size as window. In this case window is
    interpreted as the size in the dimension given by axes. IE. a window
    of (2, 1) is equivalent to window=2 and axis=-2.
toend : bool
    If False, the new dimensions are right after the corresponding original
    dimension, instead of at the end of the array. Adding the new axes at the
    end makes it easier to get the neighborhood, however toend=False will give
    a more intuitive result if you view the whole array.

Returns
-------
A view on `array` which is smaller to fit the windows and has windows added
dimensions (0s not counting), ie. every point of `array` is an array of size
window.

Examples
--------
>>> a = numpy.arange(9).reshape(3,3)
>>> rolling_window(a, (2,2))
array([[[[0, 1],
         [3, 4]],

        [[1, 2],
         [4, 5]]],


       [[[3, 4],
         [6, 7]],

        [[4, 5],
         [7, 8]]]])

Or to create non-overlapping windows, but only along the first dimension:
>>> rolling_window(a, (2,0), asteps=(2,1))
array([[[0, 3],
        [1, 4],
        [2, 5]]])

Note that the 0 is discared, so that the output dimension is 3:
>>> rolling_window(a, (2,0), asteps=(2,1)).shape
(1, 3, 2)

This is useful for example to calculate the maximum in all (overlapping)
2x2 submatrixes:
>>> rolling_window(a, (2,2)).max((2,3))
array([[4, 5],
       [7, 8]])

Or delay embedding (3D embedding with delay 2):
>>> x = numpy.arange(10)
>>> rolling_window(x, 3, wsteps=2)
array([[0, 2, 4],
       [1, 3, 5],
       [2, 4, 6],
       [3, 5, 7],
       [4, 6, 8],
       [5, 7, 9]])

References ObjexxFCL.len(), and basic::options::OptionKeys::in::file.zip.

def pyrosetta.utility.array.structured_array_to_basic (   in_array)
Convert structured array with fields of homogenous dtype to
high-dimensional basic array.

Convert structured array with fields of homogenous dtype to contiguous
array of field dtype. Result array will be of shape ([in_shape],
len(fields)) and of field dtype. Note, if field dtype is shaped, the field
shape will be included as additional minor axis.

Eg:
    in_array((10), [("a", "f", 3), ("b", "f", 3)]) ->
    out_array((10, 2, 3), "f")

References ObjexxFCL.len().

Referenced by pyrosetta.utility.array.atom_array_to_coordinates(), pyrosetta.protocols.structure_search.StructureSearchManager.pair_query(), pyrosetta.protocols.structure_search.StructureSearchManager.single_query(), pyrosetta.numeric.alignment.rmsd_calc.structured_array_broadcast_rmsd(), pyrosetta.numeric.alignment.rmsd_calc.structured_array_unaligned_broadcast_rmsd(), and pyrosetta.numeric.alignment.rmsd_calc.superimpose_structured_array().

def pyrosetta.utility.array.to_structured_array (   args,
  kwargs 
)
Create structured array via (str->array) field mapping.

Create structured array via concatenation of structured arrays or mapping of
named fields.

Args:
  *args:
    (array): Fields extracted from input structured array.
    (mapping(str, array)): Fields created from mapping entries.
    (tuple(str, array)): Single named field tuple

  *kwargs: Interpreted as mapping(str, array) argument.

  ndmin: Minimum dimension of result array.

Returns:
  Structured array of extracted fields. Field values are broadcast.

References basic::options::OptionKeys::in::file.list, max(), min(), and basic::options::OptionKeys::relax::range.range.

Variable Documentation

pyrosetta.utility.array.category = FutureWarning,
string pyrosetta.utility.array.message = "Numpy.*viewing or writing to an array returned by selecting multiple fields in a structured array."
string pyrosetta.utility.array.module = 'pyrosetta.utility.array'