def Q_ssm(nres, rmsd, n1, n2):
    """
    Compute the SSM 'Q' score for an alignment of two proteins with n1
    and n2 residues, with nres residues aligned and RMSD value of rmsd
    (Angstroms).

    This score is defined in

    Kirssinel, E. & Henrick, K. 2004 'Secondary-structure matching (SSM), a new
    tool for fast protein structure alignment in three dimensions'
    Acta Crystallographica D60:2256-2268

    Parameters:
         nres - number of residues in alignment
         rmsd - root mean square deviation of aligned residues (Angstroms)
         n1 - number of residues in protein 1
         n2 - number of residues in protein 2

    Return value: Q score for alignment
        
    """
    R0 = 3.0 # Krissinel & Henrick p. 2262
    return nres**2 / ( (1 + (rmsd / R0)**2) * n1 * n2)