//  [python]
def test_dunbrack_table_read(rosetta_database, default_database):
    # clean up if previous unit test execution failed
    if os.path.isfile("test_dunbrack.bin"):
        os.remove("test_dunbrack.bin")

    r3_beta16_dunbrack_dir = os.path.join(rosetta_database, "rotamer/beta_nov2016")
    r3_beta15_dunbrack_dir = os.path.join(rosetta_database, "rotamer/ExtendedOpt1-5")
    write_binary_version_of_dunbrack_rotamer_library(
        r3_beta16_dunbrack_dir, r3_beta15_dunbrack_dir, "test_dunbrack.bin"
    )
    fresh = DunbrackRotamerLibrary.from_zarr_archive(
        os.path.join(os.path.dirname(__file__), "copy_dunbrack.yml"),
        "test_dunbrack.bin",
    )

    default = default_database.scoring.dun

    assert len(default.dun_lookup) == len(fresh.dun_lookup)
    assert len(default.rotameric_libraries) == len(fresh.rotameric_libraries)
    assert len(default.semi_rotameric_libraries) == len(fresh.semi_rotameric_libraries)

    def compare_rotameric_data(default_rotdat, fresh_rotdat):
        t.assert_close(default_rotdat.rotamers, fresh_rotdat.rotamers)
        t.assert_close(
            default_rotdat.rotamer_probabilities, fresh_rotdat.rotamer_probabilities
        )
        t.assert_close(
            default_rotdat.rotamer_means, fresh_rotdat.rotamer_means
        )
        t.assert_close(
            default_rotdat.backbone_dihedral_start, fresh_rotdat.backbone_dihedral_start
        )
        t.assert_close(
            default_rotdat.backbone_dihedral_step, fresh_rotdat.backbone_dihedral_step
        )
        t.assert_close(
            default_rotdat.rotamer_alias, fresh_rotdat.rotamer_alias
        )

    for i in range(len(default.rotameric_libraries)):
        assert (
            default.rotameric_libraries[i].table_name
            == fresh.rotameric_libraries[i].table_name
        )
        compare_rotameric_data(
            default.rotameric_libraries[i].rotameric_data,
            fresh.rotameric_libraries[i].rotameric_data,
        )

    def compare_semirotameric_data(default_srdat, fresh_srdat):
        compare_rotameric_data(default_srdat.rotameric_data, fresh_srdat.rotameric_data)
        t.assert_close(
            default_srdat.non_rot_chi_start, fresh_srdat.non_rot_chi_start
        )
        t.assert_close(
            default_srdat.non_rot_chi_step, fresh_srdat.non_rot_chi_step
        )
        t.assert_close(
            default_srdat.non_rot_chi_period, fresh_srdat.non_rot_chi_period
        )
        t.assert_close(
            default_srdat.rotameric_chi_rotamers, fresh_srdat.rotameric_chi_rotamers
        )
        t.assert_close(
            default_srdat.nonrotameric_chi_probabilities,
            fresh_srdat.nonrotameric_chi_probabilities,
        )
        t.assert_close(
            default_srdat.rotamer_boundaries, fresh_srdat.rotamer_boundaries
        )

    for i in range(len(default.semi_rotameric_libraries)):
        assert (
            default.semi_rotameric_libraries[i].table_name
            == fresh.semi_rotameric_libraries[i].table_name
        )
        compare_semirotameric_data(
            default.semi_rotameric_libraries[i], fresh.semi_rotameric_libraries[i]
        )
    os.remove("test_dunbrack.bin")