def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments import libtbx.load_env usage = "%s [options] datablock.json" %( libtbx.env.dispatcher_name) import os if 'DIALS_EXPORT_DO_NOT_CHECK_FORMAT' in os.environ: parser = OptionParser( usage=usage, phil=phil_scope, read_datablocks=True, read_experiments=True, check_format=False, epilog=help_message) else: parser = OptionParser( usage=usage, phil=phil_scope, read_datablocks=True, read_experiments=True, check_format=True, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) if (len(datablocks) == 0 and len(experiments) == 0): parser.print_help() exit(0) if len(datablocks) == 0 and len(experiments) > 0: imagesets = experiments.imagesets() crystal = experiments[0].crystal else: imagesets = [] crystal = None for datablock in datablocks: imagesets.extend(datablock.extract_imagesets()) assert len(imagesets) == 1, len(imagesets) imageset = imagesets[0] gonio = imageset.get_goniometer() if not params.detector_distance: detector = imageset.get_detector() if len(detector) > 1: params.detector_distance = detector.hierarchy().get_directed_distance() else: params.detector_distance = detector[0].get_directed_distance() if gonio is not None and not isinstance(gonio, MultiAxisGoniometer): from dxtbx.model.goniometer import GoniometerFactory gonio = GoniometerFactory.multi_axis( axes=flex.vec3_double((gonio.get_rotation_axis(),)), angles=flex.double((0,)), names=flex.std_string(('GON_OMEGA',)), scan_axis=0) imageset.set_goniometer(gonio) if isinstance(gonio, MultiAxisGoniometer): if params.angle: assert len(params.angle) == len(gonio.get_angles()) else: for angle in gonio.get_angles(): params.angle.append(angle) import wxtbx.app a = wxtbx.app.CCTBXApp(0) a.settings = params f = ExperimentViewer( None, -1, "Experiment viewer", size=(1024,768)) f.load_imageset(imageset, crystal=crystal) f.Show() a.SetTopWindow(f) a.MainLoop()
def run(args): import os from dials.util.options import OptionParser, flatten_experiments usage = "dials.geometry_viewer [options] models.expt" parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(quick_parse=True, show_diff_phil=True) if "DIALS_EXPORT_DO_NOT_CHECK_FORMAT" in os.environ: print( "\nWarning: use of DIALS_EXPORT_DO_NOT_CHECK_FORMAT environment variable" "\nis no longer recommended, the recommended command is require_images=False" ) if not params.require_images or "DIALS_EXPORT_DO_NOT_CHECK_FORMAT" in os.environ: check_format = False else: check_format = True parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, check_format=check_format, epilog=help_message, ) try: params, options = parser.parse_args(show_diff_phil=False) except Exception as e: print(e) print( "dials.geometry_viewer help: Error in parsing data may be due to missing \n" "files. If so, this may be overcome by require_images=False\n") sys.exit() experiments = flatten_experiments(params.input.experiments) if len(experiments) == 0: parser.print_help() exit(0) imagesets = experiments.imagesets() crystal = experiments[0].crystal assert len(imagesets) == 1, len(imagesets) imageset = imagesets[0] gonio = imageset.get_goniometer() if not params.detector_distance: detector = imageset.get_detector() if len(detector) > 1: params.detector_distance = detector.hierarchy( ).get_directed_distance() else: params.detector_distance = detector[0].get_directed_distance() if gonio is not None and not isinstance(gonio, MultiAxisGoniometer): from dxtbx.model.goniometer import GoniometerFactory gonio = GoniometerFactory.multi_axis( axes=flex.vec3_double((gonio.get_rotation_axis(), )), angles=flex.double((0, )), names=flex.std_string(("GON_OMEGA", )), scan_axis=0, ) imageset.set_goniometer(gonio) if isinstance(gonio, MultiAxisGoniometer): if params.angle: assert len(params.angle) == len(gonio.get_angles()) else: for angle in gonio.get_angles(): params.angle.append(angle) import wxtbx.app a = wxtbx.app.CCTBXApp(0) a.settings = params f = ExperimentViewer(None, -1, "Experiment viewer", size=(1024, 768)) f.load_imageset(imageset, crystal=crystal) f.Show() a.SetTopWindow(f) a.MainLoop()
def test_multi_axis_goniometer(): from libtbx.test_utils import approx_equal from scitbx.array_family import flex alpha = 50 omega = -10 kappa = 30 phi = 20 direction = '-y' from dxtbx.model.goniometer import KappaGoniometer kappa_omega_scan = KappaGoniometer(alpha, omega, kappa, phi, direction, 'omega') axes = (kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(), kappa_omega_scan.get_omega_axis()) angles = (kappa_omega_scan.get_phi_angle(), kappa_omega_scan.get_kappa_angle(), kappa_omega_scan.get_omega_angle()) # First test a kappa goniometer with omega as the scan axis axes = flex.vec3_double(axes) angles = flex.double(angles) names = flex.std_string(('phi', 'kappa', 'omega')) scan_axis = 2 multi_axis_omega_scan = GoniometerFactory.multi_axis( axes, angles, names, scan_axis) assert approx_equal(multi_axis_omega_scan.get_fixed_rotation(), kappa_omega_scan.get_fixed_rotation()) assert approx_equal(multi_axis_omega_scan.get_rotation_axis(), kappa_omega_scan.get_rotation_axis()) recycle_omega = MultiAxisGoniometer.from_dict( multi_axis_omega_scan.to_dict()) assert approx_equal(recycle_omega.get_axes(), multi_axis_omega_scan.get_axes()) assert approx_equal(recycle_omega.get_angles(), multi_axis_omega_scan.get_angles()) assert recycle_omega.get_scan_axis( ) == multi_axis_omega_scan.get_scan_axis() # Now test a kappa goniometer with phi as the scan axis kappa_phi_scan = KappaGoniometer(alpha, omega, kappa, phi, direction, 'phi') scan_axis = 0 multi_axis_phi_scan = GoniometerFactory.multi_axis(axes, angles, names, scan_axis) assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(), kappa_phi_scan.get_fixed_rotation()) from scitbx import matrix assert approx_equal( matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) * multi_axis_phi_scan.get_rotation_axis_datum(), kappa_phi_scan.get_rotation_axis()) assert approx_equal(multi_axis_phi_scan.get_rotation_axis(), kappa_phi_scan.get_rotation_axis()) recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict()) assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes()) assert approx_equal(recycle_phi.get_angles(), multi_axis_phi_scan.get_angles()) assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis() s = easy_pickle.dumps(multi_axis_phi_scan) recycle = easy_pickle.loads(s) assert recycle == multi_axis_phi_scan assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes()) assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles()) assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis() recycle.set_angles((0, 90, 180)) assert approx_equal(recycle.get_angles(), (0, 90, 180)) new_axes = (0.9, 0.1, 0.0), (0.6427876096865394, -0.766044443118978, 0.0), (1.0, 0.0, 0.0) new_axes = flex.vec3_double( ((0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674), (1.00000, -0.00013, -0.00064))) recycle.set_axes(new_axes) assert approx_equal(recycle.get_axes(), new_axes) # Check exception is raised if scan axis is out range try: GoniometerFactory.multi_axis(axes, angles, names, 3) except RuntimeError, e: pass
def test_multi_axis_goniometer(): from libtbx.test_utils import approx_equal from scitbx.array_family import flex alpha = 50 omega = -10 kappa = 30 phi = 20 direction = "-y" from dxtbx.model.goniometer import KappaGoniometer kappa_omega_scan = KappaGoniometer(alpha, omega, kappa, phi, direction, "omega") axes = ( kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(), kappa_omega_scan.get_omega_axis(), ) angles = ( kappa_omega_scan.get_phi_angle(), kappa_omega_scan.get_kappa_angle(), kappa_omega_scan.get_omega_angle(), ) # First test a kappa goniometer with omega as the scan axis axes = flex.vec3_double(axes) angles = flex.double(angles) names = flex.std_string(("phi", "kappa", "omega")) scan_axis = 2 multi_axis_omega_scan = GoniometerFactory.multi_axis( axes, angles, names, scan_axis) assert approx_equal( multi_axis_omega_scan.get_fixed_rotation(), kappa_omega_scan.get_fixed_rotation(), ) assert approx_equal(multi_axis_omega_scan.get_rotation_axis(), kappa_omega_scan.get_rotation_axis()) recycle_omega = MultiAxisGoniometer.from_dict( multi_axis_omega_scan.to_dict()) assert approx_equal(recycle_omega.get_axes(), multi_axis_omega_scan.get_axes()) assert approx_equal(recycle_omega.get_angles(), multi_axis_omega_scan.get_angles()) assert recycle_omega.get_scan_axis( ) == multi_axis_omega_scan.get_scan_axis() # Now test a kappa goniometer with phi as the scan axis kappa_phi_scan = KappaGoniometer(alpha, omega, kappa, phi, direction, "phi") scan_axis = 0 multi_axis_phi_scan = GoniometerFactory.multi_axis(axes, angles, names, scan_axis) assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(), kappa_phi_scan.get_fixed_rotation()) assert approx_equal( matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) * multi_axis_phi_scan.get_rotation_axis_datum(), kappa_phi_scan.get_rotation_axis(), ) assert approx_equal(multi_axis_phi_scan.get_rotation_axis(), kappa_phi_scan.get_rotation_axis()) recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict()) assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes()) assert approx_equal(recycle_phi.get_angles(), multi_axis_phi_scan.get_angles()) assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis() s = easy_pickle.dumps(multi_axis_phi_scan) recycle = easy_pickle.loads(s) assert recycle == multi_axis_phi_scan assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes()) assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles()) assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis() recycle.set_angles((0, 90, 180)) assert approx_equal(recycle.get_angles(), (0, 90, 180)) new_axes = flex.vec3_double(( (0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674), (1.00000, -0.00013, -0.00064), )) recycle.set_axes(new_axes) assert approx_equal(recycle.get_axes(), new_axes) # Check exception is raised if scan axis is out range try: GoniometerFactory.multi_axis(axes, angles, names, 3) except RuntimeError: pass else: raise Exception_expected # Single axis is just a special case of a multi axis goniometer single_axis = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )), flex.double((0, )), flex.std_string(("PHI", )), 0) assert single_axis.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1) assert single_axis.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1) assert single_axis.get_rotation_axis() == (1, 0, 0)
((0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674), (1.00000, -0.00013, -0.00064))) recycle.set_axes(new_axes) assert approx_equal(recycle.get_axes(), new_axes) # Check exception is raised if scan axis is out range try: GoniometerFactory.multi_axis(axes, angles, names, 3) except RuntimeError, e: pass else: raise Exception_expected # Single axis is just a special case of a multi axis goniometer single_axis = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )), flex.double((0, )), flex.std_string(('PHI', )), 0) assert single_axis.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1) assert single_axis.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1) assert single_axis.get_rotation_axis() == (1, 0, 0) print 'OK' def test_goniometer_from_phil(): from dxtbx.model.goniometer import GoniometerFactory from dxtbx.model.goniometer import goniometer_phil_scope from libtbx.phil import parse params = goniometer_phil_scope.fetch( parse('''