def multi_axis_goniometer_from_phil(params, reference=None): # Check the axes parameter if params.goniometer.axes is not None: if len(params.goniometer.axes) % 3: raise RuntimeError( "Number of values for axes parameter must be multiple of 3." ) # Check the fixed rotation if params.goniometer.fixed_rotation is not None: raise RuntimeError( "Multi-axis goniometer requires fixed_rotation == None") # Check the setting rotation if params.goniometer.setting_rotation is not None: raise RuntimeError( "Multi-axis goniometer requires setting_rotation == None") # Check the input if reference is None: if params.goniometer.axes is None: raise RuntimeError("No axes set") # Create the axes axes = flex.vec3_double( params.goniometer.axes[i * 3:(i * 3) + 3] for i in range(len(params.goniometer.axes) // 3)) # Invert the rotation axis if params.goniometer.invert_rotation_axis is True: axes = flex.vec3_double([[-x for x in v] for v in axes]) # Create the angles if params.goniometer.angles is not None: angles = params.goniometer.angles if len(angles) != len(axes): raise RuntimeError("Number of angles must match axes") else: angles = flex.double([0] * len(axes)) # Create the names if params.goniometer.names is not None: names = params.goniometer.names if len(names) != len(axes): raise RuntimeError("Number of names must match axes") else: names = flex.std_string([""] * len(axes)) # Create the scan axis if params.goniometer.scan_axis is not None: scan_axis = params.goniometer.scan_axis else: scan_axis = 0 # Create the model goniometer = MultiAxisGoniometer(axes, angles, names, scan_axis) else: goniometer = reference # Set the axes if params.goniometer.axes is not None: axes = flex.vec3_double( params.goniometer.axes[i * 3:(i * 3) + 3] for i in range(len(params.goniometer.axes) // 3)) if len(goniometer.get_axes()) != len(axes): raise RuntimeError( "Number of axes must match the current goniometer (%s)" % len(goniometer.get_axes())) goniometer.set_axes(axes) # Invert rotation axis if params.goniometer.invert_rotation_axis is True: axes = flex.vec3_double([[-x for x in v] for v in goniometer.get_axes()]) goniometer.set_axes(axes) # Set the angles if params.goniometer.angles is not None: if len(goniometer.get_angles()) != len( params.goniometer.angles): raise RuntimeError( "Number of angles must match the current goniometer (%s)" % len(goniometer.get_angles())) goniometer.set_angles(params.goniometer.angles) # Set the namess if params.goniometer.names is not None: if len(goniometer.get_names()) != len(params.goniometer.names): raise RuntimeError( "Number of names must match the current goniometer (%s)" % len(goniometer.get_names())) goniometer.set_names(params.goniometer.names) # Set the scan axis if params.goniometer.scan_axis is not None: raise RuntimeError("Can not override scan axis") return goniometer
def multi_axis_goniometer_from_phil(params, reference=None): from scitbx.array_family import flex # Check the axes parameter if params.goniometer.axes is not None: if len(params.goniometer.axes) % 3: raise RuntimeError("Number of values for axes parameter must be multiple of 3.") # Check the fixed rotation if params.goniometer.fixed_rotation is not None: raise RuntimeError('Multi-axis goniometer requires fixed_rotation == None') # Check the setting rotation if params.goniometer.setting_rotation is not None: raise RuntimeError('Multi-axis goniometer requires setting_rotation == None') # Check the input if reference is None: if params.goniometer.axes is None: raise RuntimeError('No axes set') # Create the axes axes = flex.vec3_double( params.goniometer.axes[i*3:(i*3)+3] for i in range(len(params.goniometer.axes) // 3)) # Create the angles if params.goniometer.angles is not None: angles = params.goniometer.angles if len(angles) != len(axes): raise RuntimeError('Number of angles must match axes') else: angles = flex.double([0] * len(axes)) # Create the names if params.goniometer.names is not None: names = params.goniometer.names if len(names) != len(axes): raise RuntimeError('Number of names must match axes') else: names = flex.std_string([''] * len(axes)) # Create the scan axis if params.goniometer.scan_axis is not None: scan_axis = params.goniometer.scan_axis else: scan_axis = 0 # Create the model goniometer = MultiAxisGoniometer(axes, angles, names, scan_axis) else: goniometer = reference # Set the axes if params.goniometer.axes is not None: axes = flex.vec3_double( params.goniometer.axes[i*3:(i*3)+3] for i in range(len(params.goniometer.axes) // 3)) if len(goniometer.get_axes()) != len(axes): raise RuntimeError("Number of axes must match the current goniometer (%s)" %len(goniometer.get_axes())) goniometer.set_axes(axes) # Set the angles if params.goniometer.angles is not None: if len(goniometer.get_angles()) != len(params.goniometer.angles): raise RuntimeError("Number of angles must match the current goniometer (%s)" %len(goniometer.get_angles())) goniometer.set_angles(params.goniometer.angles) # Set the namess if params.goniometer.names is not None: if len(goniometer.get_names()) != len(params.goniometer.names): raise RuntimeError("Number of names must match the current goniometer (%s)" %len(goniometer.get_names())) goniometer.set_names(params.goniometer.names) # Set the scan axis if params.goniometer.scan_axis is not None: raise RuntimeError('Can not override scan axis') # Return the model return goniometer