Example #1
0
def exercise_1(prefix="tst_add_arrows_on_plot_1"):
    model = mmtbx.model.manager(
        model_input=iotbx.pdb.input(source_info=None, lines=pdb_str))
    rama = ramalyze(model.get_hierarchy(), out=null_out())
    plots = rama.get_plots(show_labels=True,
                           point_style='bo',
                           markersize=1,
                           markeredgecolor="black",
                           dpi=300,
                           markerfacecolor="white")

    ad_testing = []
    ad_testing.append(((60, -120), (120, -120)))
    ad_testing.append(((-125, 120), (-125, 179)))
    ad_testing.append(((-120, 120), (-120, -120)))  # wrapping up
    ad_testing.append(((-115, -120), (-115, 120)))  # wrapping down
    ad_testing.append(((120, -60), (-120, -60)))  # wrapping right
    ad_testing.append(((-120, -65), (120, -65)))  # wrapping left
    ad_testing.append(((120, 0), (-120, 60)))  # diag right
    ad_testing.append(((-120, 55), (120, -5)))  # diag left
    ad_testing.append(((-60, 120), (0, -120)))  # diag up
    ad_testing.append(((5, -120), (-55, 120)))  # diag up
    ad_testing.append(
        ((150, 150), (-150, -150)))  # going to top right corner straight
    ad_testing.append(
        ((140, 155), (-130, -140)))  # going to top right corner not straight
    ad_testing.append(
        ((150, -150), (-150, 150)))  # going to bottom right corner straight
    ad_testing.append(
        ((140, -155), (-130,
                       140)))  # going to bottom right corner not straight
    ad_testing.append(
        ((-150, 150), (150, -150)))  # going to top left corner straight
    ad_testing.append(
        ((-140, 155), (130, -140)))  # going to top left corner not straight
    ad_testing.append(
        ((-150, -150), (150, 150)))  # going to bottom left corner straight
    ad_testing.append(
        ((-140, -155), (130, 140)))  # going to bottom left corner not straight

    plot = plots[0]
    add_arrows_on_plot(plot, ad_testing, color="red")
    plot_file_name = "%s.png" % prefix
    plot.save_image(plot_file_name, dpi=300)

    img = Image.open(plot_file_name)
    hist = img.histogram()
    # print(hist)
    hist_ok = True
    for ref, res in zip(reference_hist, hist):
        if (ref != res) and not (0.98 < ref / res < 1.02):
            hist_ok = False
            # print (ref, res, ref/res)
    assert hist_ok
Example #2
0
def exercise_1(prefix="tst_add_arrows_on_plot_1"):
    model = mmtbx.model.manager(
        model_input=iotbx.pdb.input(source_info=None, lines=pdb_str))
    rama = ramalyze(model.get_hierarchy(), out=null_out())
    plots = rama.get_plots(show_labels=True,
                           point_style='bo',
                           markersize=1,
                           markeredgecolor="black",
                           dpi=300,
                           markerfacecolor="white")

    ad_testing = []
    ad_testing.append(((60, -120), (120, -120)))
    ad_testing.append(((-125, 120), (-125, 179)))
    ad_testing.append(((-120, 120), (-120, -120)))  # wrapping up
    ad_testing.append(((-115, -120), (-115, 120)))  # wrapping down
    ad_testing.append(((120, -60), (-120, -60)))  # wrapping right
    ad_testing.append(((-120, -65), (120, -65)))  # wrapping left
    ad_testing.append(((120, 0), (-120, 60)))  # diag right
    ad_testing.append(((-120, 55), (120, -5)))  # diag left
    ad_testing.append(((-60, 120), (0, -120)))  # diag up
    ad_testing.append(((5, -120), (-55, 120)))  # diag up
    ad_testing.append(
        ((150, 150), (-150, -150)))  # going to top right corner straight
    ad_testing.append(
        ((140, 155), (-130, -140)))  # going to top right corner not straight
    ad_testing.append(
        ((150, -150), (-150, 150)))  # going to bottom right corner straight
    ad_testing.append(
        ((140, -155), (-130,
                       140)))  # going to bottom right corner not straight
    ad_testing.append(
        ((-150, 150), (150, -150)))  # going to top left corner straight
    ad_testing.append(
        ((-140, 155), (130, -140)))  # going to top left corner not straight
    ad_testing.append(
        ((-150, -150), (150, 150)))  # going to bottom left corner straight
    ad_testing.append(
        ((-140, -155), (130, 140)))  # going to bottom left corner not straight

    plot = plots[0]
    add_arrows_on_plot(plot, ad_testing, color="black")
    plot_file_name = "%s.png" % prefix
    plot.save_image(plot_file_name, dpi=300)

    hasher = hashlib.md5()
    with open(plot_file_name, 'rb') as afile:
        buf = afile.read()
        hasher.update(buf)
    fhash = hasher.hexdigest()
    assert fhash == reference_md5, "%s != %s" % (fhash, reference_md5)