コード例 #1
0
    def __init__(self, universe, name, units,
                 data=None, dtype=None, element_shape=None):
        api.validate_type(universe, Universe, "universe")
        self._universe = universe
        api.validate_label(name, "name")
        self._name = name
        api.validate_units(units, "units")
        self._units = units
        if data is None:
            if dtype is None:
                dtype = N.float64
            if dtype not in self._allowed_dtypes:
                raise ValueError("dtype must be " +
                                 " or ".join(str(t)
                                             for t in self._allowed_dtypes))
            if element_shape is None:
                element_shape = ()
            array_shape = (self._number_of_values(),) + element_shape

            self._data = N.empty(array_shape, dtype)
        else:
            api.validate_array(data, None, self._allowed_dtypes, "data")
            if dtype is not None and data.dtype != dtype:
                raise ValueError("elements of data array do not have "
                                 "the requested type")
            if data.shape[0] != self._number_of_values():
                raise ValueError("data array has incorrect shape")
            if element_shape is not None and data.shape[1:] != element_shape:
                raise ValueError("elements of data array do not have "
                                 "the requested shape")
            self._data = data
コード例 #2
0
ファイル: array_model.py プロジェクト: khinsen/mosaic-python
 def __init__(self, universe, indices, selection_type):
     api.validate_type(universe, Universe, "universe")
     api.validate_array(indices, None,
                        [N.uint8, N.uint16, N.uint32, N.uint64], "indices")
     api.validate_value(selection_type, self._allowed_types,
                        "selection_type")
     self._universe = universe
     self._indices = indices
     self._type = selection_type
コード例 #3
0
ファイル: array_model.py プロジェクト: khinsen/mosaic-python
 def __init__(self, universe, positions, cell_parameters):
     api.validate_type(universe, Universe, "universe")
     api.validate_array(positions, (universe.number_of_sites, 3),
                        self._allowed_dtypes, "positions")
     api.validate_array(cell_parameters,
                        universe._cell_parameter_array_shapes
                                                   [universe.cell_shape],
                        [positions.dtype], "cell_parameters")
     self._universe = universe
     self._positions = positions
     self._cell_parameters = cell_parameters
コード例 #4
0
ファイル: array_model.py プロジェクト: khinsen/mosaic-python
 def __init__(self, universe, name, units, data, property_type):
     api.validate_type(universe, Universe, "universe")
     api.validate_label(name, "name")
     api.validate_units(units, "units")
     api.validate_array(data, None, self._allowed_dtypes, "data")
     api.validate_value(property_type, self._allowed_types, "property_type")
     self._universe = universe
     self._name = name
     self._units = units
     self._data = data
     self._type = property_type
コード例 #5
0
 def __init__(self, universe, name, units, data):
     api.validate_type(universe, Universe, "universe")
     self._universe = universe
     api.validate_label(name, "name")
     self._name = name
     api.validate_units(units, "units")
     self._units = units
     api.validate_array(data, None, self._allowed_dtypes, "data")
     if data.shape[0] != self._number_of_values():
         raise ValueError("data array has incorrect shape")
     self._data = data
コード例 #6
0
    def __init__(self, universe, positions, cell_parameters):
        api.validate_type(universe, Universe, "universe")
        cell_param_shape = universe.cell_parameter_array_shape
        nsites = universe.number_of_sites
        # Allow cell_parameters=None for universes that don't
        # need cell parameters.
        if cell_parameters is None and cell_param_shape == (0,):
            cell_parameters = IN.zeros(cell_param_shape, positions.dtype)
        # At this point, positions and cell_parameters must be arrays
        # of the required shapes.
        api.validate_array(positions, (nsites, 3), self._allowed_dtypes, "positions")
        api.validate_array(cell_parameters, cell_param_shape, self._allowed_dtypes, "cell_parameters")
        if positions.dtype != cell_parameters.dtype:
            raise ValueError("positions and cell parameters must have" " the same element type")

        self._universe = universe
        self._positions = positions
        self._cell_parameters = cell_parameters
コード例 #7
0
    def __init__(self, universe, positions=None, cell_parameters=None,
                 dtype=None):
        api.validate_type(universe, Universe, "universe")
        cell_param_shape = universe.cell_parameter_array_shape
        nsites = universe.number_of_sites
        if positions is None and cell_parameters is None:
            if dtype is None:
                dtype = N.float64
            if dtype not in self._allowed_dtypes:
                raise ValueError("dtype must be " +
                                 " or ".join(str(t)
                                             for t in self._allowed_dtypes))
            positions = N.empty((nsites, 3), dtype)
            cell_parameters = N.empty(cell_param_shape, dtype)
        else:
            # Allow cell_parameters=None for universes that don't
            # need cell parameters.
            if positions is not None and cell_parameters is None \
               and cell_param_shape == (0,):
                cell_parameters = N.empty(cell_param_shape,
                                          positions.dtype)
            # Require both positions and cell parameters, or neither
            if positions is None or cell_parameters is None:
                raise ValueError("configuration requires both "
                                 "positions and cell parameters")
            # At this point, positions and cell_parameters must be arrays
            # of the required shapes.
            api.validate_array(positions, (nsites, 3),
                               self._allowed_dtypes, "positions")
            api.validate_array(cell_parameters, cell_param_shape,
                               self._allowed_dtypes, "cell_parameters")
            if positions.dtype != cell_parameters.dtype:
                raise ValueError("positions and cell parameters must have"
                                 " the same element type")
            # If an explicit dtype is given, check arrays for conformance
            if dtype is not None:
                if positions.dtype != dtype:
                    raise ValueError("arrays don't have the requested"
                                     " element type " + str(dtype))

        self._universe = universe
        self._positions = positions
        self._cell_parameters = cell_parameters