Beispiel #1
0
def get_center(positions, cutoff):
    """ This function returns the approximate position with the most neighbors within the specified cutoff. If multiple
    positions have the most neighbors, the position with the lowest standard deviation of the distances to its
    neighbors is returned. """
    x_minimum, x_maximum, y_minimum, y_maximum, z_minimum, z_maximum = grid_characteristics(
        positions)[:-1]
    x_center, y_center, z_center = [
        round((x_minimum + x_maximum) / 2, 1),
        round((y_minimum + y_maximum) / 2, 1),
        round((z_minimum + z_maximum) / 2, 1)
    ]
    x_length, y_length, z_length = [
        round(x_maximum - x_minimum, 1),
        round(y_maximum - y_minimum, 1),
        round(z_maximum - z_minimum, 1)
    ]
    grid = generate_grid([x_center, y_center, z_center],
                         [x_length, y_length, z_length], 0.1)
    tree = cKDTree(positions)
    length_positions = len(positions)
    less_positions = [
        positions[x]
        for x in set(tree.query(grid, distance_upper_bound=0.1)[1])
        if x != length_positions
    ]
    small_tree = cKDTree(less_positions)
    indices_lists = small_tree.query_ball_tree(tree, cutoff)
    indices_maximal_neighbors = []
    maximal_neighbours = max([len(x) for x in indices_lists])
    for index, x in enumerate(indices_lists):
        if len(x) == maximal_neighbours:
            indices_maximal_neighbors.append(index)
    if len(indices_maximal_neighbors) > 1:
        minimal_stddev = None
        index_minimal_stddev = None
        for index in indices_maximal_neighbors:
            stddev = standard_deviation([
                distance(x, less_positions[index])
                for x in [positions[x] for x in indices_lists[index]]
            ])
            if minimal_stddev is None:
                minimal_stddev = stddev
                index_minimal_stddev = index
            elif stddev < minimal_stddev:
                minimal_stddev = stddev
                index_minimal_stddev = index
        return [
            less_positions[index_minimal_stddev],
            indices_lists[index_minimal_stddev]
        ]
    else:
        return [
            less_positions[indices_maximal_neighbors[0]],
            indices_lists[indices_maximal_neighbors[0]]
        ]
Beispiel #2
0
     directory = os.getcwd() + '/pyrod'
 logger = setup_logger('main', directory, debugging)
 update_user('\n'.join(logo), logger)
 logger.debug('\n'.join(
     [': '.join(list(_)) for _ in config.items('directory')]))
 # defining grid
 if config.has_section('test grid parameters'):
     logger.debug('\n'.join([
         ': '.join(list(_)) for _ in config.items('test grid parameters')
     ]))
     center, edge_lengths, name = test_grid_parameters(config)
     # determine space resulting in less than 100000 grid points
     space = 0.5
     space_found = False
     while not space_found:
         grid = generate_grid(center, edge_lengths, space)
         if len(grid) < 100000:
             space_found = True
             pdb_grid(grid, name, '{}/test'.format(directory))
             update_user('Writing test grid to {}/test.'.format(directory),
                         logger)
         else:
             if space == 0.5:
                 space += 0.5
             else:
                 space += 1
 # point properties
 if config.has_section('point properties parameters'):
     logger.debug('\n'.join([
         ': '.join(list(_))
         for _ in config.items('point properties parameters')