Пример #1
0
    def modify_xds_ascii_files(self, suffix="_reidx", cells_dat_out=None):
        #ofs_lst = open("for_merge_new.lst", "w")
        if cells_dat_out: cells_dat_out.write("file a b c al be ga\n")

        new_files = []
        print >> self.log_out, "Writing reindexed files.."
        for i, (f, op) in enumerate(zip(self.xac_files, self.best_operators)):
            xac = XDS_ASCII(f, read_data=False)
            if op.is_identity_op():
                new_files.append(f)
                if cells_dat_out:
                    cell = xac.symm.unit_cell().parameters()
                    cells_dat_out.write(
                        f + " " + " ".join(map(lambda x: "%7.3f" % x, cell)) +
                        "\n")

                continue

            newf = f.replace(
                ".HKL", suffix + ".HKL"
            ) if ".HKL" in f else os.path.splitext(f)[0] + suffix + ".HKL"
            print >> self.log_out, "%4d %s" % (i, newf)

            cell_tr = xac.write_reindexed(
                op,
                newf,
                space_group=self.arrays[0].crystal_symmetry().space_group())
            #ofs_lst.write(newf+"\n")
            new_files.append(newf)

            if cells_dat_out:
                cells_dat_out.write(newf + " " + " ".join(
                    map(lambda x: "%7.3f" % x, cell_tr.parameters())) + "\n")

        return new_files
Пример #2
0
    def modify_xds_ascii_files(self, suffix="_reidx", cells_dat_out=None):
        #ofs_lst = open("for_merge_new.lst", "w")
        if cells_dat_out: cells_dat_out.write("file a b c al be ga\n")

        new_files = []
        print >>self.log_out, "Writing reindexed files.."
        for i, (f, op) in enumerate(zip(self.xac_files, self.best_operators)):
            xac = XDS_ASCII(f, read_data=False)
            if op.is_identity_op():
                new_files.append(f)
                if cells_dat_out:
                    cell = xac.symm.unit_cell().parameters()
                    cells_dat_out.write(f+" "+" ".join(map(lambda x:"%7.3f"%x, cell))+"\n")

                continue

            newf = f.replace(".HKL", suffix+".HKL") if ".HKL" in f else os.path.splitext(f)[0]+suffix+".HKL"
            print >>self.log_out, "%4d %s" % (i, newf)

            cell_tr = xac.write_reindexed(op, newf, space_group=self.arrays[0].crystal_symmetry().space_group())
            #ofs_lst.write(newf+"\n")
            new_files.append(newf)

            if cells_dat_out:
                cells_dat_out.write(newf+" "+" ".join(map(lambda x:"%7.3f"%x, cell_tr.parameters()))+"\n")

        return new_files
Пример #3
0
def reindex_with_specified_symm(topdir, reference_symm, dirs, out):
    print >>out
    print >>out,  "Re-index to specified symmetry:"
    reference_symm.show_summary(out, "  ")
    print >>out
    print >>out

    cells = {} # cell and file

    sgnum_laue = reference_symm.space_group().build_derived_reflection_intensity_group(False).type().number()

    for wd in dirs:
        print >>out, "%s:" % os.path.relpath(wd, topdir),

        # Find appropriate data
        xac_file = util.return_first_found_file(("XDS_ASCII.HKL_noscale.org", "XDS_ASCII.HKL_noscale", 
                                                 "XDS_ASCII_fullres.HKL.org", "XDS_ASCII_fullres.HKL",
                                                 "XDS_ASCII.HKL.org", "XDS_ASCII.HKL"),
                                                wd=wd)
        if xac_file is None:
            print >>out, "Can't find XDS_ASCII file in %s" % wd
            continue

        if xac_file.endswith(".org"): xac_file_org, xac_file = xac_file, xac_file[:-4]
        else: xac_file_org = xac_file+".org"

        if not os.path.isfile(xac_file_org):
            os.rename(xac_file, xac_file_org)

        xac = XDS_ASCII(xac_file_org, read_data=False)
        print >>out, "%s %s (%s)" % (os.path.basename(xac_file), xac.symm.space_group_info(),
                                   ",".join(map(lambda x: "%.2f"%x, xac.symm.unit_cell().parameters())))

        if xac.symm.reflection_intensity_symmetry(False).space_group_info().type().number() == sgnum_laue:
            if xac.symm.unit_cell().is_similar_to(reference_symm.unit_cell(), 0.1, 10):
                print >>out,  "  Already scaled with specified symmetry"
                os.rename(xac_file_org, xac_file) # rename back
                cells[wd] = (numpy.array(xac.symm.unit_cell().parameters()), xac_file)
                continue

        cosets = reindex.reindexing_operators(reference_symm, xac.symm, 0.2, 20)

        if len(cosets.combined_cb_ops())==0:
            print >>out, "Can't find operator:"
            xac.symm.show_summary(out, " ")
            reference_symm.show_summary(out, " ")
            continue

        newcell = xac.write_reindexed(op=cosets.combined_cb_ops()[0],
                                      space_group=reference_symm.space_group(),
                                      hklout=xac_file)
        cells[wd] = (numpy.array(newcell.parameters()), xac_file)

        newcell = " ".join(map(lambda x: "%.3f"%x, newcell.parameters()))
        print >>out,  "  Reindexed to transformed cell: %s with %s" % (newcell, cosets.combined_cb_ops()[0].as_hkl())

    return cells
Пример #4
0
    def modify_xds_ascii_files(self, suffix="_reidx"):
        #ofs_lst = open("for_merge_new.lst", "w")
        new_files = []
        print >>self.log_out, "Writing reindexed files.."
        for i, (f, op) in enumerate(zip(self.xac_files, self.best_operators)):
            if op.is_identity_op():
                #ofs_lst.write(f+"\n")
                new_files.append(f)
                continue

            newf = f.replace(".HKL", suffix+".HKL") if ".HKL" in f else os.path.splitext(f)[0]+suffix+".HKL"
            print >>self.log_out, "%4d %s" % (i, newf)

            xac = XDS_ASCII(f, read_data=False)
            xac.write_reindexed(op, newf)
            #ofs_lst.write(newf+"\n")
            new_files.append(newf)

        return new_files
Пример #5
0
def reindex_with_specified_symm_worker(wd,
                                       wdr,
                                       topdir,
                                       log_out,
                                       reference_symm,
                                       sgnum_laue,
                                       prep_dials_files=False):
    """
    wd: directory where XDS file exists
    wdr: wd to return; a directory where transformed file should be saved.

    If wd!=wdr, files in wd/ are unchanged during procedure. Multiprocessing is unsafe when wd==wdr.
    """

    out = StringIO()
    print >> out, "%s:" % os.path.relpath(wd, topdir),

    # Find appropriate data
    xac_file = util.return_first_found_file(
        ("XDS_ASCII.HKL_noscale.org", "XDS_ASCII.HKL_noscale",
         "XDS_ASCII_fullres.HKL.org", "XDS_ASCII_fullres.HKL",
         "XDS_ASCII.HKL.org", "XDS_ASCII.HKL", "DIALS.HKL.org", "DIALS.HKL"),
        wd=wd)
    if xac_file is None:
        print >> out, "Can't find XDS_ASCII file in %s" % wd
        log_out.write(out.getvalue())
        log_out.flush()
        return (wdr, None)

    if xac_file.endswith(".org"): xac_file_out = xac_file[:-4]
    else: xac_file_out = xac_file

    xac = XDS_ASCII(xac_file, read_data=False)
    print >> out, "%s %s (%s)" % (os.path.basename(xac_file),
                                  xac.symm.space_group_info(), ",".join(
                                      map(lambda x: "%.2f" % x,
                                          xac.symm.unit_cell().parameters())))

    if xac.symm.reflection_intensity_symmetry(
            False).space_group_info().type().number() == sgnum_laue:
        if xac.symm.unit_cell().is_similar_to(
                reference_symm.unit_cell(), 0.1,
                10):  # XXX Check unit cell consistency!!
            print >> out, "  Already scaled with specified symmetry"
            log_out.write(out.getvalue())
            log_out.flush()

            if wd != wdr: shutil.copy2(xac_file, wdr)

            if prep_dials_files and "DIALS.HKL" not in xac_file:
                prepare_dials_files(wd, out, moveto=wdr)

            return (wdr, (numpy.array(xac.symm.unit_cell().parameters()),
                          os.path.join(wdr, os.path.basename(xac_file))))

    cosets = reindex.reindexing_operators(reference_symm, xac.symm, 0.2,
                                          20)  # XXX ISN'T THIS TOO LARGE?

    if len(cosets.combined_cb_ops()) == 0:
        print >> out, "Can't find operator:"
        xac.symm.show_summary(out, " ")
        reference_symm.show_summary(out, " ")
        log_out.write(out.getvalue())
        log_out.flush()
        return (wdr, None)

    if wd == wdr:
        dest = tempfile.mkdtemp(prefix="multiprep", dir=wd)
    else:
        dest = wdr

    hklout = os.path.join(dest, os.path.basename(xac_file_out))

    newcell = xac.write_reindexed(op=cosets.combined_cb_ops()[0],
                                  space_group=reference_symm.space_group(),
                                  hklout=hklout)

    if "DIALS.HKL" in os.path.basename(xac_file):
        outstr = 'output.experiments="%sreindexed_experiments.json" ' % os.path.join(
            dest, "")
        outstr += 'output.reflections="%sreindexed_reflections.pickle" ' % os.path.join(
            dest, "")
        for f in ("experiments.json", "indexed.pickle"):
            if not os.path.isfile(os.path.join(os.path.dirname(xac_file), f)):
                continue
            util.call(
                'dials.reindex %s change_of_basis_op=%s space_group="%s" %s' %
                (f, cosets.combined_cb_ops()[0].as_abc(),
                 reference_symm.space_group_info(), outstr),
                wdir=os.path.dirname(xac_file))
    elif prep_dials_files:
        prepare_dials_files(wd,
                            out,
                            space_group=reference_symm.space_group(),
                            reindex_op=cosets.combined_cb_ops()[0],
                            moveto=dest)

    newcell_str = " ".join(map(lambda x: "%.3f" % x, newcell.parameters()))
    print >> out, "  Reindexed to transformed cell: %s with %s" % (
        newcell_str, cosets.combined_cb_ops()[0].as_hkl())
    log_out.write(out.getvalue())
    log_out.flush()

    if wd == wdr:
        for f in glob.glob(os.path.join(dest, "*")):
            f_in_wd = os.path.join(wd, os.path.basename(f))
            if os.path.exists(f_in_wd) and not os.path.exists(f_in_wd +
                                                              ".org"):
                os.rename(f_in_wd, f_in_wd + ".org")
            os.rename(f, f_in_wd)

        shutil.rmtree(dest)
        ret = (numpy.array(newcell.parameters()),
               os.path.join(wd, os.path.basename(xac_file_out)))
    else:
        ret = (numpy.array(newcell.parameters()), hklout)

    return (wdr, ret)
Пример #6
0
def reindex_with_specified_symm(topdir, reference_symm, dirs, out):
    print >> out
    print >> out, "Re-index to specified symmetry:"
    reference_symm.show_summary(out, "  ")
    print >> out
    print >> out

    cells = {}  # cell and file

    sgnum_laue = reference_symm.space_group(
    ).build_derived_reflection_intensity_group(False).type().number()

    for wd in dirs:
        print >> out, "%s:" % os.path.relpath(wd, topdir),

        # Find appropriate data
        xac_file = util.return_first_found_file(
            ("XDS_ASCII.HKL_noscale.org", "XDS_ASCII.HKL_noscale",
             "XDS_ASCII_fullres.HKL.org", "XDS_ASCII_fullres.HKL",
             "XDS_ASCII.HKL.org", "XDS_ASCII.HKL"),
            wd=wd)
        if xac_file is None:
            print >> out, "Can't find XDS_ASCII file in %s" % wd
            continue

        if xac_file.endswith(".org"):
            xac_file_org, xac_file = xac_file, xac_file[:-4]
        else:
            xac_file_org = xac_file + ".org"

        if not os.path.isfile(xac_file_org):
            os.rename(xac_file, xac_file_org)

        xac = XDS_ASCII(xac_file_org, read_data=False)
        print >> out, "%s %s (%s)" % (
            os.path.basename(xac_file), xac.symm.space_group_info(), ",".join(
                map(lambda x: "%.2f" % x,
                    xac.symm.unit_cell().parameters())))

        if xac.symm.reflection_intensity_symmetry(
                False).space_group_info().type().number() == sgnum_laue:
            if xac.symm.unit_cell().is_similar_to(reference_symm.unit_cell(),
                                                  0.1, 10):
                print >> out, "  Already scaled with specified symmetry"
                os.rename(xac_file_org, xac_file)  # rename back
                cells[wd] = (numpy.array(xac.symm.unit_cell().parameters()),
                             xac_file)
                continue

        cosets = reindex.reindexing_operators(reference_symm, xac.symm, 0.2,
                                              20)

        if len(cosets.combined_cb_ops()) == 0:
            print >> out, "Can't find operator:"
            xac.symm.show_summary(out, " ")
            reference_symm.show_summary(out, " ")
            continue

        newcell = xac.write_reindexed(op=cosets.combined_cb_ops()[0],
                                      space_group=reference_symm.space_group(),
                                      hklout=xac_file)
        cells[wd] = (numpy.array(newcell.parameters()), xac_file)

        newcell = " ".join(map(lambda x: "%.3f" % x, newcell.parameters()))
        print >> out, "  Reindexed to transformed cell: %s with %s" % (
            newcell, cosets.combined_cb_ops()[0].as_hkl())

    return cells