def _retrieve_label(self, node): universe = self.retrieve(node.attrs['universe']) data = node[...] name = py_str(node.attrs['name']) label_type = py_str(node.attrs['label_type']) return mosaic.array_model.Label.from_arrays(universe, name, data, label_type)
def _retrieve_property(self, node): universe = self.retrieve(node.attrs['universe']) data = node[...] name = py_str(node.attrs['name']) units = py_str(node.attrs['units']) property_type = py_str(node.attrs['property_type']) return mosaic.array_model.Property(universe, name, units, data, property_type)
def retrieve(self, path_or_node): """ :param path_or_node: a HDF5 path, relative to the group used by the HDF5Store, or an HDF5 node :type path_or_node: str or h5py.Node :returns: a Mosaic data item :rtype: :class:`mosaic.api.MosaicDataItem` """ if isinstance(path_or_node, h5py.h5r.Reference): path_or_node = self.root[path_or_node] if isinstance(path_or_node, str): path = path_or_node else: # Group, Dataset, or classes with the same interface path = path_or_node.name if path[0] == '/': if path.startswith(self.root.name): path = path[len(self.root.name):] if path[0] == '/': path = path[1:] else: raise ValueError("path name not inside root group") data = self._get_data(path) if data is not None: return data node = self.root[path] label = py_str(self._read_stamp(node)) if label not in self._node_types: raise ValueError("Undefined node type %s" % label) handler = self.storage_handler[label] if handler is None: raise ValueError("Retrieval of node type %s not yet implemented" % label) data = handler(self, node) self._register_data_item(path, data) return data
def _retrieve_universe(self, node): # Work around a restriction/bug in h5py that prevents reading # arrays of length zero. if node['symmetry_transformations'].shape[0] == 0: st = N.zeros((0,), dtype=node['symmetry_transformations'].dtype) else: st = node['symmetry_transformations'][...] return mosaic.array_model.Universe.from_arrays( node['atoms'][...], node['bonds'][...], node['fragments'][...], node['polymers'][...] if 'polymers' in node else None, node['molecules'][...], tuple(py_str(s) for s in node['symbols'][...]), st, py_str(node['cell_shape'][()]), py_str(node['convention'][()]))
def strings(self): eos = N.repeat(N.arange(self._string_array.shape[0]), self._string_array.view(dtype=N.uint8) == 0) strings = [] f = 0 for l in eos: strings.append(py_str(self._string_array[f:l].tostring())) f = l + 1 return strings
def _retrieve_selection(self, node): universe = self.retrieve(node.attrs['universe']) indices = node[...] selection_type = py_str(node.attrs['selection_type']) return mosaic.array_model.Selection(universe, indices, selection_type)