示例#1
0
def run(params, target_files):
    assert params.normalization in ("no", "E")
    ofs = open(params.dat_out, "w")

    xac_files = util.read_path_list(params.lstin)
    targets = read_target_files(target_files, params.d_min, params.d_max,
                                params.normalization, ofs)

    cellcon = CellConstraints(targets.values()[0].space_group())

    #for i, t in enumerate(targets): ofs.write("# target%.3d = %s\n" % (i,t))
    ofs.write("# normalization = %s\n" % params.normalization)
    ofs.write("# d_min, d_max = %s, %s\n" % (params.d_min, params.d_max))
    ofs.write("file %s " % cellcon.get_label_for_free_params())
    ofs.write(" ".join(
        map(lambda x: "cc.%.3d nref.%.3d" % (x, x), xrange(len(targets)))))
    ofs.write("\n")

    for xac_file in xac_files:
        print "reading", xac_file
        xac = xds_ascii.XDS_ASCII(xac_file)
        xac.remove_rejected()
        iobs = xac.i_obs(anomalous_flag=False).merge_equivalents(
            use_internal_variance=False).array()
        ofs.write("%s %s" %
                  (xac_file, cellcon.format_free_params(iobs.unit_cell())))
        fail_flag = False
        if params.normalization == "E":
            try:
                normaliser = kernel_normalisation(iobs, auto_kernel=True)
                iobs = iobs.customized_copy(
                    data=iobs.data() / normaliser.normalizer_for_miller_array,
                    sigmas=iobs.sigmas() /
                    normaliser.normalizer_for_miller_array)
            except:
                fail_flag = True

        for i, ta in enumerate(targets.values()):
            if fail_flag:
                ofs.write(" % .4f %4d" % cc_num)
            else:
                cc_num = calc_cc(iobs, ta)
                ofs.write(" % .4f %4d" % cc_num)

        ofs.write("\n")
def make_plot(lp, log_out):
    ofs = open(log_out, "w")

    ofs.write("$TABLE: Parameters estimated for each frame:\n")
    ofs.write("$GRAPHS\n")
    ofs.write(":scales")
    ofs.write(":A:1,2:\n")
    ofs.write(":number of overloaded/strong/unexpected reflections")
    ofs.write(":A:1,3,4,5:\n")
    ofs.write(":SIGMAB (beam divergence e.s.d.)")
    ofs.write(":A:1,6:\n")
    ofs.write(":SIGMAR (reflecting range e.s.d.)")
    ofs.write(":A:1,7:\n")
    ofs.write("$$\n")
    ofs.write("Frame scale overlods nstrong nrej sigmaD sigmaM $$\n$$\n")
    for f, scale, novl, nstr, nrej, sd, sm in zip(lp.frames, lp.scales,
                                                  lp.overloads, lp.strongs,
                                                  lp.rejecteds, lp.sigmads,
                                                  lp.sigmars):
        ofs.write("%5d %s %d %d %d %s %s\n" %
                  (f, scale, novl, nstr, nrej, sd, sm))

    ofs.write("$$\n")
    ofs.write("\n\n\n")

    ofs.write("$TABLE: Parameters estimated for each block:\n")
    ofs.write("$GRAPHS\n")
    ofs.write(":unit cell length a")
    ofs.write(":A:1,2:\n")

    cellconstr = CellConstraints(lp.space_group)
    if not cellconstr.is_b_equal_a():
        ofs.write(":unit cell length b")
        ofs.write(":A:1,3:\n")
    if not cellconstr.is_c_equal_a_b():
        ofs.write(":unit cell length c")
        ofs.write(":A:1,4:\n")
    if not cellconstr.is_angle_constrained("alpha"):
        ofs.write(":unit cell angle alpha")
        ofs.write(":A:1,5:\n")
    if not cellconstr.is_angle_constrained("beta"):
        ofs.write(":unit cell angle beta")
        ofs.write(":A:1,6:\n")
    if not cellconstr.is_angle_constrained("gamma"):
        ofs.write(":unit cell angle gamma")
        ofs.write(":A:1,7:\n")
    ofs.write(":rotations off from initial orientation")
    ofs.write(":A:1,8,9,10:\n")
    ofs.write(":distance")
    ofs.write(":A:1,11:\n")
    ofs.write(":deviations from predicted positions")
    ofs.write(":A:1,12,13:\n")
    ofs.write(":beam center")
    ofs.write(":A:1,14,15:\n")
    ofs.write(":missetting angles")
    ofs.write(":A:1,16,17,18:\n")
    ofs.write("$$\n")
    ofs.write(
        "#image a b c alpha beta gamma rotx roty rotz dist spot spindle orgx orgy phix phiy phiz$$\n$$\n"
    )
    for images, param in sorted(lp.blockparams.items()):
        for i in images:
            print >> ofs, "%4d " % i, "  ".join(param.get(
                "cell", ["D"] * 6)), " ".join(param.get(
                    "rotation", ["D"] * 3)), param.get("dist", "D"), param.get(
                        "spot", "D"), param.get("spindle", "D"), " ".join(
                            param.get("orig", ["D"] * 2)), " ".join(
                                param.get("misset", ["D"] * 3))

    ofs.write("$$\n")
    ofs.write("\n\n\n")

    ofs.write("$TABLE: sigmaB and sigmaR on 9 areas for each block:\n")
    ofs.write("$GRAPHS\n")
    ofs.write(":SIGMAB")
    ofs.write(":A:1,2,3,4,5,6,7,8,9,10:\n")
    ofs.write(":SIGMAR")
    ofs.write(":A:1,11,12,13,14,15,16,17,18,19:\n")
    ofs.write("$$\n")
    ofs.write("#image %s %s$$\n$$\n" %
              (" ".join(["sigmab%d" % x for x in range(1, 10)]), " ".join(
                  ["sigmar%d" % x for x in range(1, 10)])))
    for images, param in sorted(lp.blockparams.items()):
        for i in images:
            print >> ofs, "%4d " % i, " ".join(param["sigmab9"]), " ".join(
                param["sigmar9"])

    ofs.write("$$\n")
    ofs.write("\n\n\n")
示例#3
0
    def add_cells_and_files(self, cells, symm_str):
        self.cells = cells
        # Table
        table_str = ""
        for idx, xac in enumerate(cells):
            cell = cells[xac]
            table_str += "<tr>\n"
            table_str += " <td>%.4d</td><td>%s</td>" % (idx+1, xac) # idx, file
            table_str += "".join(map(lambda x: "<td>%.2f</td>"%x, cell))
            table_str += "\n</tr>\n"

        # Hist
        cellconstr = CellConstraints(sgtbx.space_group_info(symm_str).group())
        show_flags = (True, not cellconstr.is_b_equal_a(), not cellconstr.is_c_equal_a_b(),
                      not cellconstr.is_angle_constrained("alpha"),
                      not cellconstr.is_angle_constrained("beta"),
                      not cellconstr.is_angle_constrained("gamma"))
        names = ("a", "b", "c", "&alpha;", "&beta;", "&gamma;")

        hist_str = ""
        label1 = ""
        for i, (name, show) in enumerate(zip(names, show_flags)):
            tmp = ""
            if i in (0,3): tmp += "<tr>"
            if show: tmp += "<th>%s</th>" % name
            if i in (2,5): tmp += "</tr>"

            if i < 3: hist_str += tmp
            else: label1 += tmp

        hist_str += "\n<tr>\n"

        for idx, (name, show) in enumerate(zip(names, show_flags)):
            if idx==3: hist_str += "</tr>" + label1 + "<tr>"
            if not show: continue
            vals = flex.double(map(lambda x: x[idx], cells.values()))
            if len(vals) == 0: continue
            nslots = max(30, int((max(vals) - min(vals)) / 0.5))
            hist = flex.histogram(vals, n_slots=nslots)
            x_vals = map(lambda i: hist.data_min() + hist.slot_width() * (i+.5), xrange(len(hist.slots())))
            y_vals = hist.slots()
            hist_str += """
<td>
<div id="chartdiv_cell%(idx)d" style="width: 500px; height: 400px;"></div>
<script>
 var chart_cell%(idx)d = AmCharts.makeChart("chartdiv_cell%(idx)d", {
    "type": "serial",
    "theme": "none",  
    "legend": {
        "useGraphSettings": true,
        "markerSize":12,
        "valueWidth":0,
        "verticalGap":0
    },
    "dataProvider": [%(data)s],
    "valueAxes": [{
        "minorGridAlpha": 0.08,
        "minorGridEnabled": true,
        "position": "top",
        "axisAlpha":0
    }],
    "graphs": [{
        "balloonText": "[[category]]: [[value]]",
        "title": "%(name)s",
        "type": "column",
        "fillAlphas": 0.8,
        "valueField": "yval"
    }],
    "rotate": false,
    "categoryField": "xval",
    "categoryAxis": {
        "gridPosition": "start",
        "title": ""
    }
});
</script>
</td>
""" % dict(idx=idx, name=name,
           data=",".join(map(lambda x: '{"xval":%.2f,"yval":%d}'%x, zip(x_vals,y_vals)))
           )

        hist_str += "</tr>"

        self.html_inputfiles = """
<h2>Input files</h2>
%d files for merging in %s symmetry

<h3>Unit cell histogram</h3>
<table>
%s
</table>

<h3>Files</h3>
<a href="#" onClick="toggle_show('div-input-files'); return false;">Show/Hide</a>
<div id="div-input-files" style="display:none;">
<table class="cells">
<tr>
 <th>idx</th> <th>file</th> <th>a</th> <th>b</th> <th>c</th> <th>&alpha;</th> <th>&beta;</th> <th>&gamma;</th>
</tr>
%s
</table>
</div>
""" % (len(cells), symm_str, hist_str, table_str)
        self.write_html()
示例#4
0
def make_plot(lp, log_out):
    ofs = open(log_out, "w")

    ofs.write("$TABLE: Parameters estimated for each frame:\n")
    ofs.write("$GRAPHS\n")
    ofs.write(":scales")
    ofs.write(":A:1,2:\n")
    ofs.write(":number of overloaded reflections")
    ofs.write(":A:1,3:\n")
    ofs.write(":number of unexpected reflections")
    ofs.write(":A:1,4:\n")
    ofs.write(":SIGMAB (beam divergence e.s.d.)")
    ofs.write(":A:1,5:\n")
    ofs.write(":SIGMAR (reflecting range e.s.d.)")
    ofs.write(":A:1,6:\n")
    ofs.write("$$\n")
    ofs.write("Frame scale overlods nrej sigmaD sigmaM $$\n$$\n")
    for f, scale, novl, nrej, sd, sm in zip(lp.frames, lp.scales, lp.overloads, lp.rejecteds, lp.sigmads, lp.sigmars):
        ofs.write("%5d %s %d %d %s %s\n" % (f, scale, novl, nrej, sd, sm))

    ofs.write("$$\n")
    ofs.write("\n\n\n")

    ofs.write("$TABLE: Parameters estimated for each block:\n")
    ofs.write("$GRAPHS\n")
    ofs.write(":unit cell length a")
    ofs.write(":A:1,2:\n")

    cellconstr = CellConstraints(lp.space_group)
    if not cellconstr.is_b_equal_a():
        ofs.write(":unit cell length b")
        ofs.write(":A:1,3:\n")
    if not cellconstr.is_c_equal_a_b():
        ofs.write(":unit cell length c")
        ofs.write(":A:1,4:\n")
    if not cellconstr.is_angle_constrained("alpha"):
        ofs.write(":unit cell angle alpha")
        ofs.write(":A:1,5:\n")
    if not cellconstr.is_angle_constrained("beta"):
        ofs.write(":unit cell angle beta")
        ofs.write(":A:1,6:\n")
    if not cellconstr.is_angle_constrained("gamma"):
        ofs.write(":unit cell angle gamma")
        ofs.write(":A:1,7:\n")
    ofs.write(":rotations off from initial orientation")
    ofs.write(":A:1,8,9,10:\n")
    ofs.write(":distance")
    ofs.write(":A:1,11:\n")
    ofs.write(":deviations from predicted positions")
    ofs.write(":A:1,12,13:\n")
    ofs.write(":beam center")
    ofs.write(":A:1,14,15:\n")
    ofs.write(":missetting angles")
    ofs.write(":A:1,16,17,18:\n")
    ofs.write("$$\n")
    ofs.write("#image a b c alpha beta gamma rotx roty rotz dist spot spindle orgx orgy phix phiy phiz$$\n$$\n")
    for images, param in sorted(lp.blockparams.items()):
        for i in images:
            print >>ofs, "%4d " % i, "  ".join(param.get("cell", ["D"]*6)), " ".join(param.get("rotation", ["D"]*3)), param.get("dist","D"), param.get("spot","D"), param.get("spindle","D"), " ".join(param.get("orig",["D"]*2)), " ".join(param.get("misset",["D"]*3))

    ofs.write("$$\n")
    ofs.write("\n\n\n")


    ofs.write("$TABLE: sigmaB and sigmaR on 9 areas for each block:\n")
    ofs.write("$GRAPHS\n")
    ofs.write(":SIGMAB")
    ofs.write(":A:1,2,3,4,5,6,7,8,9,10:\n")
    ofs.write(":SIGMAR")
    ofs.write(":A:1,11,12,13,14,15,16,17,18,19:\n")
    ofs.write("$$\n")
    ofs.write("#image %s %s$$\n$$\n" % (" ".join(["sigmab%d"%x for x in range(1,10)]), " ".join(["sigmar%d"%x for x in range(1,10)])))
    for images, param in sorted(lp.blockparams.items()):
        for i in images:
            print >>ofs, "%4d " % i, " ".join(param["sigmab9"]), " ".join(param["sigmar9"])

    ofs.write("$$\n")
    ofs.write("\n\n\n")
示例#5
0
    def add_cells_and_files(self, cells, symm_str):
        self.cells = cells
        # Table
        table_str = ""
        for idx, xac in enumerate(cells):
            cell = cells[xac]
            table_str += "<tr>\n"
            table_str += " <td>%.4d</td><td>%s</td>" % (idx+1, xac) # idx, file
            table_str += "".join(map(lambda x: "<td>%.2f</td>"%x, cell))
            table_str += "\n</tr>\n"

        # Hist
        cellconstr = CellConstraints(sgtbx.space_group_info(symm_str).group())
        show_flags = (True, not cellconstr.is_b_equal_a(), not cellconstr.is_c_equal_a_b(),
                      not cellconstr.is_angle_constrained("alpha"),
                      not cellconstr.is_angle_constrained("beta"),
                      not cellconstr.is_angle_constrained("gamma"))
        names = ("a", "b", "c", "&alpha;", "&beta;", "&gamma;")

        hist_str = ""
        label1 = ""
        for i, (name, show) in enumerate(zip(names, show_flags)):
            tmp = ""
            if i in (0,3): tmp += "<tr>"
            if show: tmp += "<th>%s</th>" % name
            if i in (2,5): tmp += "</tr>"

            if i < 3: hist_str += tmp
            else: label1 += tmp

        hist_str += "\n<tr>\n"

        for idx, (name, show) in enumerate(zip(names, show_flags)):
            if idx==3: hist_str += "</tr>" + label1 + "<tr>"
            if not show: continue
            vals = flex.double(map(lambda x: x[idx], cells.values()))
            if len(vals) == 0: continue
            nslots = max(30, int((max(vals) - min(vals)) / 0.5))
            hist = flex.histogram(vals, n_slots=nslots)
            x_vals = map(lambda i: hist.data_min() + hist.slot_width() * (i+.5), xrange(len(hist.slots())))
            y_vals = hist.slots()
            hist_str += """
<td>
<div id="chartdiv_cell%(idx)d" style="width: 500px; height: 400px;"></div>
<script>
 var chart_cell%(idx)d = AmCharts.makeChart("chartdiv_cell%(idx)d", {
    "type": "serial",
    "theme": "none",  
    "legend": {
        "useGraphSettings": true,
        "markerSize":12,
        "valueWidth":0,
        "verticalGap":0
    },
    "dataProvider": [%(data)s],
    "valueAxes": [{
        "minorGridAlpha": 0.08,
        "minorGridEnabled": true,
        "position": "top",
        "axisAlpha":0
    }],
    "graphs": [{
        "balloonText": "[[category]]: [[value]]",
        "title": "%(name)s",
        "type": "column",
        "fillAlphas": 0.8,
        "valueField": "yval"
    }],
    "rotate": false,
    "categoryField": "xval",
    "categoryAxis": {
        "gridPosition": "start",
        "title": ""
    }
});
</script>
</td>
""" % dict(idx=idx, name=name,
           data=",".join(map(lambda x: '{"xval":%.2f,"yval":%d}'%x, zip(x_vals,y_vals)))
           )

        hist_str += "</tr>"

        self.html_inputfiles = """
<h2>Input files</h2>
%d files for merging in %s symmetry

<h3>Unit cell histogram</h3>
<table>
%s
</table>

<h3>Files</h3>
<a href="#" onClick="toggle_show('div-input-files'); return false;">Show/Hide</a>
<div id="div-input-files" style="display:none;">
<table class="cells">
<tr>
 <th>idx</th> <th>file</th> <th>a</th> <th>b</th> <th>c</th> <th>&alpha;</th> <th>&beta;</th> <th>&gamma;</th>
</tr>
%s
</table>
</div>
""" % (len(cells), symm_str, hist_str, table_str)
        self.write_html()