Exemple #1
0
def numpy_svd_rmsd_rot(in_crds1, in_crds2):
    """
  Returns rmsd and optional rotation between 2 sets of [nx3] arrays.
  
  This requires numpy for svd decomposition.
  The transform direction: transform(m, ref_crd) => target_crd.
  """

    crds1 = numpy.array(in_crds1)
    crds2 = numpy.array(in_crds2)
    assert (crds1.shape[1] == 3)
    assert (crds1.shape == crds2.shape)

    n_vec = numpy.shape(crds1)[0]
    correlation_matrix = numpy.dot(numpy.transpose(crds1), crds2)
    v, s, w = numpy.linalg.svd(correlation_matrix)
    is_reflection = (numpy.linalg.det(v) * numpy.linalg.det(w)) < 0.0

    if is_reflection:
        s[-1] = -s[-1]
    E0 = sum(sum(crds1 * crds1)) + \
         sum(sum(crds2 * crds2))
    rmsd_sq = (E0 - 2.0 * sum(s)) / float(n_vec)
    rmsd_sq = max([rmsd_sq, 0.0])
    rmsd = numpy.sqrt(rmsd_sq)

    if is_reflection:
        v[-1, :] = -v[-1, :]
    rot33 = numpy.dot(v, w)
    m = v3.identity()
    m[:3, :3] = rot33.transpose()

    return rmsd, m
def numpy_svd_rmsd_rot(in_crds1, in_crds2):
  """
  Returns rmsd and optional rotation between 2 sets of [nx3] arrays.

  This requires numpy for svd decomposition.
  The transform direction: transform(m, ref_crd) => target_crd.
  """

  crds1 = numpy.array(in_crds1)
  crds2 = numpy.array(in_crds2)
  assert(crds1.shape[1] == 3)
  assert(crds1.shape == crds2.shape)

  n_vec = numpy.shape(crds1)[0]
  correlation_matrix = numpy.dot(numpy.transpose(crds1), crds2)
  v, s, w = numpy.linalg.svd(correlation_matrix)
  is_reflection = (numpy.linalg.det(v) * numpy.linalg.det(w)) < 0.0

  if is_reflection:
    s[-1] = - s[-1]
  E0 = sum(sum(crds1 * crds1)) + \
       sum(sum(crds2 * crds2))
  rmsd_sq = (E0 - 2.0*sum(s)) / float(n_vec)
  rmsd_sq = max([rmsd_sq, 0.0])
  rmsd = numpy.sqrt(rmsd_sq)

  if is_reflection:
    v[-1,:] = -v[-1,:]
  rot33 = numpy.dot(v, w)
  m = v3.identity()
  m[:3,:3] = rot33.transpose()

  return rmsd, m
Exemple #3
0
def pyqcprot_rmsd_rot(crds1, crds2):
    """
  Returns rmsd and optional rotation between 2 sets of [nx3] arrays.
  
  This requires Joshua Adelman's pyqcrot library for quaternion-based
  calculation of Theobauld. The transform direction: 
      transform(m, ref_crd) => target_crd.
  """
    rms, rot9 = lib.pyqcprot.calc_rms_rot(crds1, crds2)
    matrix = v3.identity()
    for i in range(3):
        for j in range(3):
            v3.matrix_elem(matrix, i, j, rot9[i * 3 + j])
    return rms, matrix
def pyqcprot_rmsd_rot(crds1, crds2):
  """
  Returns rmsd and optional rotation between 2 sets of [nx3] arrays.

  This requires Joshua Adelman's pyqcrot library for quaternion-based
  calculation of Theobauld. The transform direction:
      transform(m, ref_crd) => target_crd.
  """
  rms, rot9 = lib.pyqcprot.calc_rms_rot(crds1, crds2)
  matrix = v3.identity()
  for i in range(3):
    for j in range(3):
       v3.matrix_elem(matrix, i, j, rot9[i*3+j])
  return rms, matrix