def test_multi_axis_goniometer_from_phil(): params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (1, 0, 0, 0, 1, 0, 0, 0, 1) scan_axis = 2 } """ ) ).extract() g1 = GoniometerFactory.from_phil(params) assert tuple(g1.get_axes()) == ((1, 0, 0), (0, 1, 0), (0, 0, 1)) assert g1.get_scan_axis() == 2 # Test using a reference params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (0, 1, 0, 1, 0, 0, 0, 0, 1) } """ ) ).extract() g2 = GoniometerFactory.from_phil(params, reference=g1) assert tuple(g2.get_axes()) == ((0, 1, 0), (1, 0, 0), (0, 0, 1))
def test_single_axis_goniometer_with_fixed_rotation_and_reference_from_phil(): params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (1, 0, 0) } """ ) ).extract() g1 = GoniometerFactory.from_phil(params) params = goniometer_phil_scope.fetch( parse( """ goniometer { axis = (0, 1, 0) fixed_rotation = (0, 1, 0, 1, 0, 0, 0, 0, 1) } """ ) ).extract() g2 = GoniometerFactory.from_phil(params, reference=g1) assert g2.get_rotation_axis() == (0, 1, 0) assert g2.get_fixed_rotation() == (0, 1, 0, 1, 0, 0, 0, 0, 1)
def test_goniometer_from_phil(): params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (1, 0, 0) } """ ) ).extract() g1 = GoniometerFactory.from_phil(params) assert g1.get_rotation_axis() == (1, 0, 0) params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (0, 1, 0) fixed_rotation = (0, 1, 0, 1, 0, 0, 0, 0, 1) } """ ) ).extract() g2 = GoniometerFactory.from_phil(params, reference=g1) assert g2.get_rotation_axis() == (0, 1, 0) assert g2.get_fixed_rotation() == (0, 1, 0, 1, 0, 0, 0, 0, 1) params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (1, 0, 0, 0, 1, 0, 0, 0, 1) scan_axis = 2 } """ ) ).extract() g3 = GoniometerFactory.from_phil(params) assert tuple(g3.get_axes()) == ((1, 0, 0), (0, 1, 0), (0, 0, 1)) assert g3.get_scan_axis() == 2 params = goniometer_phil_scope.fetch( parse( """ goniometer { axes = (0, 1, 0, 1, 0, 0, 0, 0, 1) } """ ) ).extract() g4 = GoniometerFactory.from_phil(params, reference=g3) assert tuple(g4.get_axes()) == ((0, 1, 0), (1, 0, 0), (0, 0, 1))
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(''' goniometer { axes = (1, 0, 0) } ''')).extract() g1 = GoniometerFactory.from_phil(params) assert g1.get_rotation_axis() == (1, 0, 0) params = goniometer_phil_scope.fetch( parse(''' goniometer { axes = (0, 1, 0) fixed_rotation = (0, 1, 0, 1, 0, 0, 0, 0, 1) } ''')).extract() g2 = GoniometerFactory.from_phil(params, reference=g1) assert g2.get_rotation_axis() == (0, 1, 0) assert g2.get_fixed_rotation() == (0, 1, 0, 1, 0, 0, 0, 0, 1) params = goniometer_phil_scope.fetch( parse(''' goniometer { axes = (1, 0, 0, 0, 1, 0, 0, 0, 1) scan_axis = 2 } ''')).extract() g3 = GoniometerFactory.from_phil(params) assert tuple(g3.get_axes()) == ((1, 0, 0), (0, 1, 0), (0, 0, 1)) assert g3.get_scan_axis() == 2 params = goniometer_phil_scope.fetch( parse(''' goniometer { axes = (0, 1, 0, 1, 0, 0, 0, 0, 1) } ''')).extract() g4 = GoniometerFactory.from_phil(params, reference=g3) assert tuple(g4.get_axes()) == ((0, 1, 0), (1, 0, 0), (0, 0, 1)) print 'OK'
def test_single_axis_goniometer_using_axis_and_axes_from_phil_raises_error(): """Supplying both the 'axis' and 'axes' parameters is ambiguous, so it should be mutually exclusive. This test ensures that is the case.""" params = goniometer_phil_scope.fetch( parse(""" goniometer { axis = (1, 0, 0) axes = (1, 0, 0) } """)).extract() with pytest.raises(ValueError): GoniometerFactory.from_phil(params)
def _goniometer(self): ''' Create the goniometer model ''' from dxtbx.model.goniometer import GoniometerFactory return GoniometerFactory.single_axis()
def _construct_goniometer(phi, chi, omega): phi_axis = (1.0, 0.0, 0.0) chi_axis = (0, 0, -1) omega_axis = (1.0, 0.0, 0.0) axes = flex.vec3_double((phi_axis, chi_axis, omega_axis)) angles = flex.double((phi, chi, omega)) names = flex.std_string(("GON_PHI", "GON_CHI", "GON_OMEGA")) return GoniometerFactory.make_multi_axis_goniometer( axes, angles, names, scan_axis=2 )
def _construct_goniometer(phi, kappa, omega): phi_axis = (1.0, 0.0, 0.0) kappa_axis = (0.914, 0.279, -0.297) omega_axis = (1.0, 0.0, 0.0) axes = flex.vec3_double((phi_axis, kappa_axis, omega_axis)) angles = flex.double((phi, kappa, omega)) names = flex.std_string(("GON_PHI", "GON_KAPPA", "GON_OMEGA")) return GoniometerFactory.make_multi_axis_goniometer( axes, angles, names, scan_axis=2 )
def test_single_axis_goniometer_using_axes_from_phil(): params = goniometer_phil_scope.fetch( parse(""" goniometer { axes = (1, 0, 0) } """)).extract() g1 = GoniometerFactory.from_phil(params) assert g1.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('''
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 _goniometer(self): """ Create the goniometer model """ return GoniometerFactory.single_axis()
def test_goniometer(): """A test class for the goniometer class.""" axis = (1, 0, 0) fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1) xg = Goniometer(axis, fixed) assert len(xg.get_rotation_axis()) == 3 assert len(xg.get_fixed_rotation()) == 9 _compare_tuples(xg.get_rotation_axis(), axis) _compare_tuples(xg.get_fixed_rotation(), fixed) single = GoniometerFactory.single_axis() assert len(single.get_rotation_axis()) == 3 assert len(single.get_fixed_rotation()) == 9 _compare_tuples(single.get_rotation_axis(), axis) _compare_tuples(single.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) _compare_tuples(kappa.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) _compare_tuples(kappa.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "phi") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) _compare_tuples(kappa.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, "-y", "omega") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) with pytest.raises(AssertionError): _compare_tuples(kappa.get_fixed_rotation(), fixed) image = Path(__file__).parent / "phi_scan_001.cbf" assert GoniometerFactory.imgCIF(str(image)) kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, "-y", "phi") s = easy_pickle.dumps(kappa) kappa2 = easy_pickle.loads(s) assert kappa == kappa2 image = Path(__file__).parent / "omega_scan.cbf" assert GoniometerFactory.imgCIF(str(image)) kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, "-y", "omega") s = easy_pickle.dumps(kappa) kappa2 = easy_pickle.loads(s) assert kappa == kappa2
from dxtbx.datablock import DataBlockFactory, DataBlockDumper from dxtbx.imageset import ImageSetFactory, ImageSweep, ImageSetData from dxtbx.model.goniometer import GoniometerFactory from dxtbx.model.scan import ScanFactory import glob, os, sys """ Modification of AB's prepare_sweep.py. Usage: libtbx.python prepare_sweep.py img_dir start_img, end_img savefile """ root = sys.argv[1] start, end = int(sys.argv[2]), int(sys.argv[3]) g = GoniometerFactory.single_axis() s = ScanFactory.make_scan((start, end), 0, (0, 1), [0] * (end - start + 1)) sw = ImageSetFactory.from_template(template=os.path.join( root, "fft_frame_I_mf_####.cbf"), scan=s, goniometer=g, image_range=(start, end)) dump = DataBlockDumper(DataBlockFactory.from_imageset(sw)) dump.as_file(sys.argv[4])
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)
def test_goniometer(): """A test class for the goniometer class.""" axis = (1, 0, 0) fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1) xg = Goniometer(axis, fixed) assert len(xg.get_rotation_axis()) == 3 assert len(xg.get_fixed_rotation()) == 9 _compare_tuples(xg.get_rotation_axis(), axis) _compare_tuples(xg.get_fixed_rotation(), fixed) single = GoniometerFactory.single_axis() assert len(single.get_rotation_axis()) == 3 assert len(single.get_fixed_rotation()) == 9 _compare_tuples(single.get_rotation_axis(), axis) _compare_tuples(single.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) _compare_tuples(kappa.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) _compare_tuples(kappa.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "phi") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) _compare_tuples(kappa.get_fixed_rotation(), fixed) kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, "-y", "omega") assert len(kappa.get_rotation_axis()) == 3 assert len(kappa.get_fixed_rotation()) == 9 _compare_tuples(kappa.get_rotation_axis(), axis) with pytest.raises(AssertionError): _compare_tuples(kappa.get_fixed_rotation(), fixed) import libtbx.load_env dxtbx_dir = libtbx.env.dist_path("dxtbx") image = os.path.join(dxtbx_dir, "tests", "phi_scan_001.cbf") assert GoniometerFactory.imgCIF(image) kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, "-y", "phi") s = easy_pickle.dumps(kappa) kappa2 = easy_pickle.loads(s) assert kappa == kappa2 image = os.path.join(dxtbx_dir, "tests", "omega_scan.cbf") assert GoniometerFactory.imgCIF(image) kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, "-y", "omega") s = easy_pickle.dumps(kappa) kappa2 = easy_pickle.loads(s) assert kappa == kappa2
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_goniometer(): '''A test class for the goniometer class.''' axis = (1, 0, 0) fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1) xg = Goniometer(axis, fixed) assert (len(xg.get_rotation_axis()) == 3) assert (len(xg.get_fixed_rotation()) == 9) assert (compare_tuples(xg.get_rotation_axis(), axis)) assert (compare_tuples(xg.get_fixed_rotation(), fixed)) single = GoniometerFactory.single_axis() assert (len(single.get_rotation_axis()) == 3) assert (len(single.get_fixed_rotation()) == 9) assert (compare_tuples(single.get_rotation_axis(), axis)) assert (compare_tuples(single.get_fixed_rotation(), fixed)) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega') assert (len(kappa.get_rotation_axis()) == 3) assert (len(kappa.get_fixed_rotation()) == 9) assert (compare_tuples(kappa.get_rotation_axis(), axis)) assert (compare_tuples(kappa.get_fixed_rotation(), fixed)) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega') assert (len(kappa.get_rotation_axis()) == 3) assert (len(kappa.get_fixed_rotation()) == 9) assert (compare_tuples(kappa.get_rotation_axis(), axis)) assert (compare_tuples(kappa.get_fixed_rotation(), fixed)) kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'phi') assert (len(kappa.get_rotation_axis()) == 3) assert (len(kappa.get_fixed_rotation()) == 9) assert (compare_tuples(kappa.get_rotation_axis(), axis)) assert (compare_tuples(kappa.get_fixed_rotation(), fixed)) kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, '-y', 'omega') assert (len(kappa.get_rotation_axis()) == 3) assert (len(kappa.get_fixed_rotation()) == 9) assert (compare_tuples(kappa.get_rotation_axis(), axis)) assert (not compare_tuples(kappa.get_fixed_rotation(), fixed)) import libtbx.load_env import os dxtbx_dir = libtbx.env.dist_path('dxtbx') image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf') cbf = GoniometerFactory.imgCIF(image) kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, '-y', 'phi') s = easy_pickle.dumps(kappa) kappa2 = easy_pickle.loads(s) assert kappa == kappa2 image = os.path.join(dxtbx_dir, 'tests', 'omega_scan.cbf') cbf = GoniometerFactory.imgCIF(image) kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, '-y', 'omega') s = easy_pickle.dumps(kappa) kappa2 = easy_pickle.loads(s) assert kappa == kappa2 print 'OK'