예제 #1
0
    def run(self):
        """Execute the script."""

        # Parse the command line
        self.params, options, filelist = self.parser.parse_args(
            show_diff_phil=True, return_unhandled=True
        )

        if len(filelist) != 1:
            raise Sorry(
                "Please provide input in the form:\n  {0}".format(self.parser.usage)
            )

        # Read the filelist and tidy it up
        try:
            with open(filelist[0], "r") as f:
                self.filelist = f.readlines()
        except IOError:
            raise Sorry("Cannot read the specified file list")
        self.filelist = [l.rstrip() for l in self.filelist]
        self.filelist = [l for l in self.filelist if l != ""]

        # Create output directory if it does not already exist
        self._directory = os.path.abspath(self.params.output.directory)
        ensure_directory(self._directory)
        print("Analysis will be performed in {0}".format(self._directory))

        # locate centroid_analysis script
        dials_dir = libtbx.env.find_in_repositories("dials")
        self._ca = os.path.join(
            dials_dir, "algorithms", "refinement", "analysis", "centroid_analysis.py"
        )

        # Do analysis for the files in filelist
        for i, f in enumerate(self.filelist):
            # strip newline from the filenames
            s = "{:%Y-%m-%d %H:%M:%S} ".format(datetime.datetime.now())
            s += "Processing file {0}: ".format(i) + f
            print(s)
            status = self.process(f, i)
            if status:
                print("Incomplete:", status)

        return
예제 #2
0
    def run(self):
        """Execute the script."""

        # Parse the command line
        self.params, options, filelist = self.parser.parse_args(show_diff_phil=True, return_unhandled=True)

        if len(filelist) != 1:
            raise Sorry("Please provide input in the form:\n  {0}".format(self.parser.usage))

        # Read the filelist and tidy it up
        try:
            with open(filelist[0], "r") as f:
                self.filelist = f.readlines()
        except IOError:
            raise Sorry("Cannot read the specified file list")
        self.filelist = [l.rstrip() for l in self.filelist]
        self.filelist = [l for l in self.filelist if l != ""]

        # Create output directory if it does not already exist
        self._directory = os.path.abspath(self.params.output.directory)
        ensure_directory(self._directory)
        print "Analysis will be performed in {0}".format(self._directory)

        # locate centroid_analysis script
        dials_dir = libtbx.env.find_in_repositories("dials")
        self._ca = os.path.join(dials_dir, "algorithms", "refinement", "analysis", "centroid_analysis.py")

        # Do analysis for the files in filelist
        for i, f in enumerate(self.filelist):
            # strip newline from the filenames
            s = "{:%Y-%m-%d %H:%M:%S} ".format(datetime.datetime.now())
            s += "Processing file {0}: ".format(i) + f
            print s
            status = self.process(f, i)
            if status:
                print "Incomplete:", status

        return
예제 #3
0
    def run(self):
        """Run the script."""
        from dials.util.options import flatten_experiments

        params, options = self.parser.parse_args()
        if len(params.input.experiments) == 0:
            self.parser.print_help()
            raise Sorry("No experiments found in the input")
        experiments = flatten_experiments(params.input.experiments)

        # Determine output path
        self._directory = os.path.join(params.output.directory, "scan-varying_crystal")
        self._directory = os.path.abspath(self._directory)
        ensure_directory(self._directory)
        self._format = "." + params.output.format

        self._debug = params.output.debug

        # Decomposition axes
        self._e1 = params.orientation_decomposition.e1
        self._e2 = params.orientation_decomposition.e2
        self._e3 = params.orientation_decomposition.e3

        # cell plot
        dat = []
        for iexp, exp in enumerate(experiments):

            crystal = exp.crystal
            scan = exp.scan

            if crystal.num_scan_points == 0:
                print "Ignoring scan-static crystal"
                continue

            scan_pts = range(crystal.num_scan_points)
            cells = [crystal.get_unit_cell_at_scan_point(t) for t in scan_pts]
            cell_params = [e.parameters() for e in cells]
            a, b, c, aa, bb, cc = zip(*cell_params)
            phi = [scan.get_angle_from_array_index(t) for t in scan_pts]
            vol = [e.volume() for e in cells]
            cell_dat = {"phi": phi, "a": a, "b": b, "c": c, "alpha": aa, "beta": bb, "gamma": cc, "volume": vol}
            if self._debug:
                print "Crystal in Experiment {0}".format(iexp)
                print "Phi\ta\tb\tc\talpha\tbeta\tgamma\tVolume"
                msg = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}"
                line_dat = zip(phi, a, b, c, aa, bb, cc, vol)
                for line in line_dat:
                    print msg.format(*line)
            dat.append(cell_dat)
        self.plot_cell(dat)

        # orientation plot
        dat = []
        for iexp, exp in enumerate(experiments):

            crystal = exp.crystal
            scan = exp.scan

            if crystal.num_scan_points == 0:
                print "Ignoring scan-static crystal"
                continue

            scan_pts = range(crystal.num_scan_points)
            phi = [scan.get_angle_from_array_index(t) for t in scan_pts]
            Umats = [crystal.get_U_at_scan_point(t) for t in scan_pts]
            if params.orientation_decomposition.relative_to_static_orientation:
                # factor out static U
                Uinv = crystal.get_U().inverse()
                Umats = [U * Uinv for U in Umats]
            # NB e3 and e1 definitions for the crystal are swapped compared
            # with those used inside the solve_r3_rotation_for_angles_given_axes
            # method
            angles = [solve_r3_rotation_for_angles_given_axes(U, self._e3, self._e2, self._e1, deg=True) for U in Umats]
            phi3, phi2, phi1 = zip(*angles)
            angle_dat = {"phi": phi, "phi3": phi3, "phi2": phi2, "phi1": phi1}
            if self._debug:
                print "Crystal in Experiment {0}".format(iexp)
                print "Image\tphi3\tphi2\tphi1"
                msg = "{0}\t{1}\t{2}\t{3}"
                line_dat = zip(phi, phi3, phi2, phi1)
                for line in line_dat:
                    print msg.format(*line)
            dat.append(angle_dat)
        self.plot_orientation(dat)
예제 #4
0
    def run(self):
        """Run the script."""
        from dials.util.options import flatten_experiments
        from scitbx import matrix

        params, options = self.parser.parse_args()
        if len(params.input.experiments) == 0:
            self.parser.print_help()
            return
        experiments = flatten_experiments(params.input.experiments)

        # Determine output path
        self._directory = os.path.join(params.output.directory,
                                       "scan-varying_model")
        self._directory = os.path.abspath(self._directory)
        ensure_directory(self._directory)
        self._format = "." + params.output.format

        self._debug = params.output.debug

        # Decomposition axes
        self._e1 = params.orientation_decomposition.e1
        self._e2 = params.orientation_decomposition.e2
        self._e3 = params.orientation_decomposition.e3

        # cell plot
        dat = []
        for iexp, exp in enumerate(experiments):

            crystal = exp.crystal
            scan = exp.scan

            if crystal.num_scan_points == 0:
                print("Ignoring scan-static crystal")
                continue

            scan_pts = list(range(crystal.num_scan_points))
            cells = [crystal.get_unit_cell_at_scan_point(t) for t in scan_pts]
            cell_params = [e.parameters() for e in cells]
            a, b, c, aa, bb, cc = zip(*cell_params)
            phi = [scan.get_angle_from_array_index(t) for t in scan_pts]
            vol = [e.volume() for e in cells]
            cell_dat = {
                "phi": phi,
                "a": a,
                "b": b,
                "c": c,
                "alpha": aa,
                "beta": bb,
                "gamma": cc,
                "volume": vol,
            }
            try:
                cell_esds = [
                    crystal.get_cell_parameter_sd_at_scan_point(t)
                    for t in scan_pts
                ]
                sig_a, sig_b, sig_c, sig_aa, sig_bb, sig_cc = zip(*cell_esds)
                cell_dat["sig_a"] = sig_a
                cell_dat["sig_b"] = sig_b
                cell_dat["sig_c"] = sig_c
                cell_dat["sig_aa"] = sig_aa
                cell_dat["sig_bb"] = sig_bb
                cell_dat["sig_cc"] = sig_cc
            except RuntimeError:
                pass

            if self._debug:
                print("Crystal in Experiment {}".format(iexp))
                print("Phi\ta\tb\tc\talpha\tbeta\tgamma\tVolume")
                msg = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}"
                line_dat = zip(phi, a, b, c, aa, bb, cc, vol)
                for line in line_dat:
                    print(msg.format(*line))
            dat.append(cell_dat)
        if dat:
            self.plot_cell(dat)

        # orientation plot
        dat = []
        for iexp, exp in enumerate(experiments):

            crystal = exp.crystal
            scan = exp.scan

            if crystal.num_scan_points == 0:
                print("Ignoring scan-static crystal")
                continue

            scan_pts = list(range(crystal.num_scan_points))
            phi = [scan.get_angle_from_array_index(t) for t in scan_pts]
            Umats = [
                matrix.sqr(crystal.get_U_at_scan_point(t)) for t in scan_pts
            ]
            if params.orientation_decomposition.relative_to_static_orientation:
                # factor out static U
                Uinv = matrix.sqr(crystal.get_U()).inverse()
                Umats = [U * Uinv for U in Umats]
            # NB e3 and e1 definitions for the crystal are swapped compared
            # with those used inside the solve_r3_rotation_for_angles_given_axes
            # method
            angles = [
                solve_r3_rotation_for_angles_given_axes(U,
                                                        self._e3,
                                                        self._e2,
                                                        self._e1,
                                                        deg=True)
                for U in Umats
            ]
            phi3, phi2, phi1 = zip(*angles)
            angle_dat = {"phi": phi, "phi3": phi3, "phi2": phi2, "phi1": phi1}
            if self._debug:
                print("Crystal in Experiment {}".format(iexp))
                print("Image\tphi3\tphi2\tphi1")
                msg = "{0}\t{1}\t{2}\t{3}"
                line_dat = zip(phi, phi3, phi2, phi1)
                for line in line_dat:
                    print(msg.format(*line))
            dat.append(angle_dat)
        if dat:
            self.plot_orientation(dat)

        # beam centre plot
        dat = []
        for iexp, exp in enumerate(experiments):

            beam = exp.beam
            detector = exp.detector
            scan = exp.scan

            if beam.num_scan_points == 0:
                print("Ignoring scan-static beam")
                continue

            scan_pts = range(beam.num_scan_points)
            phi = [scan.get_angle_from_array_index(t) for t in scan_pts]
            p = detector.get_panel_intersection(beam.get_s0())
            if p < 0:
                print("Beam does not intersect a panel")
                continue
            panel = detector[p]
            s0_scan_points = [
                beam.get_s0_at_scan_point(i)
                for i in range(beam.num_scan_points)
            ]
            bc_scan_points = [
                panel.get_beam_centre_px(s0) for s0 in s0_scan_points
            ]
            bc_x, bc_y = zip(*bc_scan_points)
            dat.append({
                "phi": phi,
                "beam_centre_x": bc_x,
                "beam_centre_y": bc_y
            })
        if dat:
            self.plot_beam_centre(dat)