code: def get_signs(M, cutoff=1e-10, validate=True, ambiguous=True):
      
      # Is this a symmetric matrix?
      assert is_symmetric(M), "the matrix is not symmetric:\n{0}".format(str(M))
      N, x = M.shape
  
      # eigh() works on symmetric matrix (Hermitian)
      w, v = np.linalg.eigh(M)
      m = np.argmax(w)
      mv = v[:, m]
      f = lambda x: (x if abs(x) > cutoff else 0)
      mv = [f(x) for x in mv]
  
      sign_array = np.array(np.sign(mv), dtype=int)
  
      # it does not really matter, but we prefer as few flippings as possible
      if np.sum(sign_array) < 0:
          sign_array = -sign_array
  
      if validate:
          diag = np.matrix(np.eye(N, dtype=int) * sign_array)
          final = diag * M * diag
          # The final result should have all pairwise in the same direction
          assert (final >= 0).all(), \
                  "result check fails:\n{0}".format(final)
  
      if not ambiguous:   # Do we allow ambiguous orientation (=0) ?
          sign_array[sign_array == 0] = 1
  
      return sign_array
docs: Given a numpy array M that contains pairwise orientations, find the largest
      eigenvalue and associated eigenvector and return the signs for the
      eigenvector. This should correspond to the original orientations for the
      individual molecule. In the first example below, let's say 3 molecules A, B
      and C, A-B:same direction, A-C:opposite direction, B-C:opposite
      direction. The final solution is to flip C.
  
      >>> M = np.array([[0,1,-1],[1,0,-1],[-1,-1,0]])
      >>> get_signs(M)
      array([ 1,  1, -1])
      >>> M = np.array([[0,1,-1],[1,0,0],[-1,0,0]])
      >>> get_signs(M)
      array([ 1,  1, -1])