def _setup_grid(self, cutoff, unit_cell, grid):
if grid is None:<EOL><INDENT>if unit_cell is None:<EOL><INDENT>grid = cutoff/<NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>divisions = np.ceil(unit_cell.spacings/cutoff)<EOL>divisions[divisions<<NUM_LIT:1>] = <NUM_LIT:1><EOL>grid = unit_cell/divisions<EOL><DEDENT><DEDENT>if isinstance(grid, float):<EOL><INDENT>grid_cell = UnitCell(np.array([<EOL>[grid, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, grid, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:0>, grid]<EOL>]))<EOL><DEDENT>elif isinstance(grid, UnitCell):<EOL><INDENT>grid_cell = grid<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if unit_cell is not None:<EOL><INDENT>integer_matrix = grid_cell.to_fractional(unit_cell.matrix.transpose()).transpose()<EOL>if abs((integer_matrix - np.round(integer_matrix))*self.unit_cell.active).max() > <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>integer_matrix = integer_matrix.round()<EOL>integer_cell = UnitCell(integer_matrix, unit_cell.active)<EOL><DEDENT>else:<EOL><INDENT>integer_cell = None<EOL><DEDENT>return grid_cell, integer_cell<EOL>
Choose a proper grid for the binning process