def to_structure(matrix, alpha=<NUM_LIT:1>):
connected = largest_connected_component(matrix)<EOL>distances = to_distance(connected, alpha)<EOL>n, m = connected.shape<EOL>bary = np.sum(np.triu(distances, <NUM_LIT:1>)) / (n**<NUM_LIT:2>)  <EOL>d = np.array(np.sum(distances**<NUM_LIT:2>, <NUM_LIT:0>) / n - bary)  <EOL>gram = np.array([(d[i] + d[j] - distances[i][j]**<NUM_LIT:2>) / <NUM_LIT:2> for i,<EOL>j in itertools.product(range(n), range(m))]).reshape(n, m)<EOL>normalized = gram / np.linalg.norm(gram, '<STR_LIT>')<EOL>try:<EOL><INDENT>symmetric = np.array((normalized + normalized.T) / <NUM_LIT:2>,<EOL>dtype=np.longfloat)  <EOL><DEDENT>except AttributeError:<EOL><INDENT>symmetric = np.array((normalized + normalized.T) / <NUM_LIT:2>)<EOL><DEDENT>from scipy import linalg<EOL>eigen_values, eigen_vectors = linalg.eigh(symmetric)<EOL>if not (eigen_values >= <NUM_LIT:0>).all():<EOL><INDENT>warnings.warn("<STR_LIT>")<EOL><DEDENT>idx = eigen_values.argsort()[-<NUM_LIT:3>:][::-<NUM_LIT:1>]<EOL>values = eigen_values[idx]<EOL>vectors = eigen_vectors[:, idx]<EOL>coordinates = vectors * np.sqrt(values)<EOL>return coordinates<EOL>
Compute best matching 3D genome structure from underlying input matrix
    using ShRec3D-derived method from Lesne et al., 2014.

    Link: https://www.ncbi.nlm.nih.gov/pubmed/25240436

    The method performs two steps: first compute distance matrix by treating
    contact data as an adjacency graph (of weights equal to a power law
    function of the data), then embed the resulting distance matrix into
    3D space.

    The alpha parameter influences the weighting of contacts: if alpha < 1
    long-range interactions are prioritized; if alpha >> 1 short-range
    interactions have more weight wahen computing the distance matrix.