Ejemplo n.º 1
0
    def run_strategies(strategies):
      # starting from scratch
      observed_hkls = {}

      total_score = 0.0
      degrees = 0

      from itertools import izip, count
      for (run, strategy) in izip(count(1), strategies):
        print
        print "Sweep %d:" % run
        evaluation_function = evaluation_function_factory(possible_hkl, observed_hkls, map_hkl_to_symmhkl, map_symmhkl_to_hkl)

        goniometer = goniometer_factory.make_kappa_goniometer(alpha=54.7,
                                                              kappa=strategy['kappa'],
                                                              phi=strategy['phi'],
                                                              omega=strategy['omega'],
                                                              direction="-y",
                                                              scan_axis=strategy['scan_axis'])

        degrees += strategy['scan']

        from math import radians
        if strategy['scan_axis'] == 'omega':
          oscillation_range = (radians(strategy['omega']), radians(strategy['omega'] + strategy['scan']))
        else:
          oscillation_range = (radians(strategy['phi']), radians(strategy['phi'] + strategy['scan']))

        # repeat sweep: expt.goniometer
        proposed_hkls = calculate_observations(expt.detector, goniometer, oscillation_range)

        strategy_results = evaluate_concrete_strategy(proposed_hkls, evaluation_function)
        combined_observations = self.add_seen_multiplicity(observed_hkls, proposed_hkls)

        num_observed_hkls      = len(set([map_hkl_to_symmhkl[hkl] for hkl in combined_observations.keys()]))
        count_hkl_observations = sum(combined_observations.values())
        completeness = 100 * num_observed_hkls / completeness_limit
        multiplicity = count_hkl_observations / num_observed_hkls
        total_score += strategy_results['score']
        print "Estimated total completeness: %5.1f %%   total multiplicity : %.1f   total score: %.1f" %\
              (completeness, multiplicity, total_score)

        # keep the repeat sweep and continue
        observed_hkls = combined_observations
      export_mtz(observed_hkls, expt, "mtzout.mtz")
      return {'completeness': completeness, 'multiplicity': multiplicity, 'score': total_score, 'degrees': degrees}
Ejemplo n.º 2
0
        def calculate_miller_rings(detector):
            import time

            t = time.clock()
            mrings = {}
            for scan_axis in ["phi", "omega"]:
                mrings[scan_axis] = {}
                for other_axis in range(0, 360, 10):
                    gonio = goniometer_factory.make_kappa_goniometer(
                        alpha=54.7356,  # fixed magic angle
                        kappa=0,  # fixed 0 kappa
                        phi=0 if scan_axis == "phi" else other_axis,
                        omega=0 if scan_axis == "omega" else other_axis,
                        direction="-y",
                        scan_axis=scan_axis,
                    )
                    ring = tools.determine_miller_ring_sectors(
                        detector, gonio, s0, possible_hkl_flex, crystal_A)
                    mrings[scan_axis][other_axis] = ring

            print(time.clock() - t)
            print(list(mrings.iterkeys()))
            print([list(x.iterkeys()) for x in mrings.itervalues()])

            t = time.clock()
            sc = scorings
            all_scorings = {
                "%s:%s:%s" % (scan, str(x1), str(x2)): tools.geometric_scoring(
                    [hkl_to_id[hkl] for hkl in mrings[scan][x1][x2]],
                    sc)["total"]
                for scan in mrings.iterkeys()
                for x1 in mrings[scan].iterkeys() for x2 in range(0, 36)
            }
            #     print list(all_scorings.itervalues())
            print(
                len(list(all_scorings.itervalues())),
                min(all_scorings.itervalues()),
                max(all_scorings.itervalues()),
                sum(all_scorings.itervalues()) /
                len(list(all_scorings.itervalues())),
            )
            print(time.clock() - t)

            sys.exit(0)
Ejemplo n.º 3
0
    def calculate_miller_rings(detector):
      import time
      t = time.clock()
      mrings = {}
      for scan_axis in ['phi', 'omega']:
        mrings[scan_axis] = {}
        for other_axis in range(0, 360, 10):
          gonio = goniometer_factory.make_kappa_goniometer(alpha=54.7356, # fixed magic angle
                                                           kappa=0,       # fixed 0 kappa
                                                           phi=0 if scan_axis == "phi" else other_axis,
                                                           omega=0 if scan_axis == "omega" else other_axis,
                                                           direction="-y",
                                                           scan_axis=scan_axis)
          ring = tools.determine_miller_ring_sectors(detector, gonio, s0, possible_hkl_flex, crystal_A)
          mrings[scan_axis][other_axis] = ring

      print time.clock() - t
      print list(mrings.iterkeys())
      print [ list(x.iterkeys()) for x in mrings.itervalues() ]
Ejemplo n.º 4
0
        def run_strategies(strategies):
            # starting from scratch
            observed_hkls = {}

            total_score = 0.0
            degrees = 0

            from itertools import izip, count

            for (run, strategy) in izip(count(1), strategies):
                print()
                print("Sweep %d:" % run)
                evaluation_function = evaluation_function_factory(
                    possible_hkl, observed_hkls, map_hkl_to_symmhkl,
                    map_symmhkl_to_hkl)

                goniometer = goniometer_factory.make_kappa_goniometer(
                    alpha=54.7,
                    kappa=strategy["kappa"],
                    phi=strategy["phi"],
                    omega=strategy["omega"],
                    direction="-y",
                    scan_axis=strategy["scan_axis"],
                )

                degrees += strategy["scan"]

                from math import radians

                if strategy["scan_axis"] == "omega":
                    oscillation_range = (
                        radians(strategy["omega"]),
                        radians(strategy["omega"] + strategy["scan"]),
                    )
                else:
                    oscillation_range = (
                        radians(strategy["phi"]),
                        radians(strategy["phi"] + strategy["scan"]),
                    )

                # repeat sweep: expt.goniometer
                proposed_hkls = calculate_observations(expt.detector,
                                                       goniometer,
                                                       oscillation_range)

                strategy_results = evaluate_concrete_strategy(
                    proposed_hkls, evaluation_function)
                combined_observations = self.add_seen_multiplicity(
                    observed_hkls, proposed_hkls)

                num_observed_hkls = len(
                    set([
                        map_hkl_to_symmhkl[hkl]
                        for hkl in combined_observations.keys()
                    ]))
                count_hkl_observations = sum(combined_observations.values())
                completeness = 100 * num_observed_hkls / completeness_limit
                multiplicity = count_hkl_observations / num_observed_hkls
                total_score += strategy_results["score"]
                print(
                    "Estimated total completeness: %5.1f %%   total multiplicity : %.1f   total score: %.1f"
                    % (completeness, multiplicity, total_score))

                # keep the repeat sweep and continue
                observed_hkls = combined_observations
            export_mtz(observed_hkls, expt, "mtzout.mtz")
            return {
                "completeness": completeness,
                "multiplicity": multiplicity,
                "score": total_score,
                "degrees": degrees,
            }