Exemplo n.º 1
0
def cns_xplor_text(positions, scores, dmif_format):
    """ This function generates a list of strings for writing cns and xplor maps. """
    density = ['\n', '{0:>8}\n'.format(1), 'REMARKS {} file generated by PyRod\n'.format(dmif_format)]
    x_minimum, x_maximum, y_minimum, y_maximum, z_minimum, z_maximum, space = grid_characteristics(positions)
    density.append('{0:>8}{1:>8}{2:>8}{3:>8}{4:>8}{5:>8}{6:>8}{7:>8}{8:>8}\n'.format(
        int(((x_maximum - x_minimum) / space) + 1), int(x_minimum / space), int(x_maximum / space),
        int(((y_maximum - y_minimum) / space) + 1), int(y_minimum / space), int(y_maximum / space),
        int(((z_maximum - z_minimum) / space) + 1), int(z_minimum / space), int(z_maximum / space)))
    density.append('{0:>12.5E}{1:>12.5E}{2:>12.5E}{3:>12.5E}{3:>12.5E}{3:>12.5E}\n'.format(
        x_maximum - x_minimum, y_maximum - y_minimum, z_maximum - z_minimum, 90))
    density.append('ZYX\n')
    index_z = 0
    index_xy = 0
    xy = int(((x_maximum - x_minimum) / space) + 1) * int(((y_maximum - y_minimum) / space) + 1)
    for score in scores:
        if index_xy % xy == 0:
            if index_xy % 6 == 0:
                density.append('{0:>8}\n'.format(index_z))
            else:
                density.append('\n{0:>8}\n'.format(index_z))
            index_z += 1
            index_xy = 0
        density.append('{0:>12.5E}'.format(score))
        index_xy += 1
        if index_xy % 6 == 0:
            density.append('\n')
    if dmif_format == 'cns':
        if index_xy % 6 == 0:
            density.append('{0:>8}\n'.format(-9999))
        else:
            density.append('\n{0:>8}\n'.format(-9999))
        density.append(' {0:>12.5E}{1:>12.5E}\n'.format(mean(scores), standard_deviation(scores)))
        density.append('\n')
    return density
Exemplo n.º 2
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]]
        ]
Exemplo n.º 3
0
 def test_population_standard_deviation(self):
     """ This function tests the population_standard_deviation function. """
     test_cases = [[
         np.array([
             -1.0, -2, -5, -1, -5, -5, -5, 5, 0, 5, -5, -4, -5, -1, -2, 3,
             -2, -1, 0, 1, -3, 0, 3, -5, 2, -3, 5, 3, 1, -1
         ]), 3.20347034046239
     ],
                   [[
                       -1.0, -2, -5, -1, -5, -5, -5, 5, 0, 5, -5, -4, -5,
                       -1, -2, 3, -2, -1, 0, 1, -3, 0, 3, -5, 2, -3, 5, 3,
                       1, -1
                   ], 3.20347034046239]]
     for test_case in test_cases:
         self.assertAlmostEqual(standard_deviation(test_case[0]),
                                test_case[1])