Exemplo n.º 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
Exemplo n.º 2
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)