def structured_array_unaligned_broadcast_rmsd(coordinates_a, coordinates_b): """Calculate rmsd between entries in the given structured coordinate arrays. coordinates_a - array(shape=([a], n), dtype=[(name, float, 3)...]) coordinates_b - array(shape=([b], n), dtype=[(name, float, 3)...]) out - array(shape=(a, b), dtype=float) coordinates_a and coordinates_b must contain dimension n and be of the same structured dtype. returns broadcast_rmsd - array(shape=(a,b), dtype=float) Flattened to 1 dimension if a or b is dimension 2. """ assert coordinates_a.shape[-1] == coordinates_b.shape[-1] assert coordinates_a.dtype == coordinates_b.dtype if coordinates_a.ndim == 1: ac = structured_array_to_basic(coordinates_a).reshape((-1, 3)) else: assert coordinates_a.ndim == 2 ac = structured_array_to_basic(coordinates_a).reshape( (coordinates_a.shape[0], -1, 3)) if coordinates_b.ndim == 1: bc = structured_array_to_basic(coordinates_b).reshape((-1, 3)) else: assert coordinates_b.ndim == 2 bc = structured_array_to_basic(coordinates_b).reshape( (coordinates_b.shape[0], -1, 3)) return coordinate_array_unaligned_broadcast_rmsd(ac, bc)
def pair_query(self, query_components, query_tolerance, primary_range=None): if primary_range: if isinstance(primary_range, collections.Iterable): min_primary_distance, max_primary_distance = primary_range elif primary_range: min_primary_distance, max_primary_distance = 0, primary_range q = StructurePairQuery( structured_array_to_basic(query_components[0][list( self.target_atoms)]), structured_array_to_basic(query_components[1][list( self.target_atoms)]), query_tolerance, min_primary_distance, max_primary_distance) else: q = StructurePairQuery( structured_array_to_basic(query_components[0][list( self.target_atoms)]), structured_array_to_basic(query_components[1][list( self.target_atoms)]), query_tolerance, ) e = PairQueryExecutor(q) e.execute(self.db) return e.query_results
def single_query(self, query_component, query_tolerance): q = StructureSingleQuery( structured_array_to_basic(query_component[list( self.target_atoms)]), query_tolerance) e = SingleQueryExecutor(q) e.execute(self.db) return e.query_results
def __init__(self, source_residues): """TODO: to be defined1. Args: source_residues (TODO): TODO """ self.source_residues = source_residues self.target_atoms = source_residues["orient"].dtype.names source_coords = structured_array_to_basic( self.source_residues["orient"]) structure_endpoints = numpy.flatnonzero( self.source_residues["structure_id"][:-1] != self.source_residues["structure_id"][1:]) chain_endpoints = numpy.flatnonzero( self.source_residues["chain_ending"]) self.db = StructureDatabase() self.db.initialize(source_coords, structure_endpoints, chain_endpoints)
def superimpose_structured_array(src, onto, superimpose=None): """Calculate and apply superposition transform between src and onto coordinates. src - array(shape=([a], n), dtype=[(name, float, 3)...]) onto - array(shape=([a|1], n), dtype=[(name, float, 3)...]) superimpose - array(shape=([a], n_2), dtype=[(name, float, 3)...]) src and onto must contain dimension n and be of the same structured dtype. returns superimposed - array(shape=([a], n_2), dtype=[(name, float, 3)...]) """ assert src.shape[-1] == onto.shape[-1] assert src.dtype == onto.dtype if src.ndim == 1: ac = structured_array_to_basic(src).reshape((-1, 3)) else: assert src.ndim == 2 ac = structured_array_to_basic(src).reshape((src.shape[0], -1, 3)) if onto.ndim == 1: bc = structured_array_to_basic(onto).reshape((-1, 3)) else: assert onto.ndim == 2 bc = structured_array_to_basic(onto).reshape((onto.shape[0], -1, 3)) if superimpose is None: superimpose = src.copy() if superimpose.ndim == 1: sc = structured_array_to_basic(superimpose).reshape((-1, 3)) else: assert superimpose.ndim == 2 sc = structured_array_to_basic( superimpose).reshape((onto.shape[0], -1, 3)) superimpose_coordinate_array(ac, bc, sc) sc = sc.reshape(sc.shape[:-2] + (-1, len(superimpose.dtype.names), 3)) structured_result = basic_array_to_structured( sc, superimpose.dtype.names, superimpose.dtype[superimpose.dtype.names[0]]) return numpy.squeeze(structured_result, axis=-1)