From: <nat...@us...> - 2011-07-07 23:18:56
|
Revision: 13439 http://cctbx.svn.sourceforge.net/cctbx/?rev=13439&view=rev Author: natechols Date: 2011-07-07 23:18:50 +0000 (Thu, 07 Jul 2011) Log Message: ----------- display of systematic absences; major rearrangements, minor fixes Modified Paths: -------------- trunk/crys3d/hklview/__init__.py trunk/crys3d/hklview/frames.py trunk/crys3d/hklview/view_2d.py trunk/crys3d/hklview/view_3d.py Modified: trunk/crys3d/hklview/__init__.py =================================================================== --- trunk/crys3d/hklview/__init__.py 2011-07-07 22:34:52 UTC (rev 13438) +++ trunk/crys3d/hklview/__init__.py 2011-07-07 23:18:50 UTC (rev 13439) @@ -3,26 +3,102 @@ # - cached scenes from libtbx.utils import Sorry +from libtbx import object_oriented_patterns as oop from math import sqrt +def generate_systematic_absences (array, + expand_to_p1=False, + generate_bijvoet_mates=False) : + from cctbx import crystal + sg = array.space_group() + base_symm = crystal.symmetry( + unit_cell=array.unit_cell(), + space_group=sg.build_derived_reflection_intensity_group(False)) + base_array = array.customized_copy(crystal_symmetry=base_symm) + complete_set = base_array.complete_set().customized_copy( + crystal_symmetry=array.crystal_symmetry()) + absence_array = complete_set.sys_absent_flags() + if (generate_bijvoet_mates) : + absence_array = absence_array.generate_bijvoet_mates() + if (expand_to_p1) : + absence_array = absence_array.expand_to_p1().customized_copy( + crystal_symmetry=array.crystal_symmetry()) + #niggli_cell().expand_to_p1() + return absence_array + class scene (object) : def __init__ (self, miller_array, settings) : self.miller_array = miller_array + self.settings = settings from cctbx import miller - from scitbx import graphics_utils + from cctbx import crystal from cctbx.array_family import flex + self.process_input_array() + array = self.work_array + uc = array.unit_cell() + self.unit_cell = uc + self.slice_selection = None + if (settings.slice_mode) : + self.slice_selection = miller.simple_slice( + indices=array.indices(), + slice_axis=settings.slice_axis, + slice_index=settings.slice_index) + if (self.slice_selection.count(True) == 0) : + raise ValueError("No data selected!") + index_span = array.index_span() + self.hkl_range = index_span.abs_range() + self.axes = [ uc.reciprocal_space_vector((self.hkl_range[0],0,0)), + uc.reciprocal_space_vector((0,self.hkl_range[1],0)), + uc.reciprocal_space_vector((0,0,self.hkl_range[2])) ] + self.generate_view_data() + if (self.slice_selection is not None) : + self.indices = self.work_array.indices().select(self.slice_selection) + else : + self.indices = array.indices() + self.points = uc.reciprocal_space_vector(self.indices) * 100. + self.missing_flags = flex.bool(self.radii.size(), False) + self.sys_absent_flags = flex.bool(self.radii.size(), False) + if (settings.show_missing_reflections) : + self.generate_missing_reflections() + if (settings.show_systematic_absences) and (not settings.show_only_missing): + self.generate_systematic_absences() + # XXX hack for process_pick_points + self.visible_points = flex.bool(self.points.size(), True) + n_points = self.points.size() + assert (self.colors.size() == n_points) + assert (self.indices.size() == n_points) + assert (self.radii.size() == n_points) + assert (self.missing_flags.size() == n_points) + assert (self.sys_absent_flags.size() == n_points) + self.clear_labels() + + def process_input_array (self) : + from scitbx.array_family import flex array = self.miller_array.deep_copy() + settings = self.settings data = array.data() + self.missing_set = oop.null() if (array.is_xray_intensity_array()) : data.set_selected(data < 0, flex.double(data.size(), 0.)) if (array.is_unique_set_under_symmetry()) : array = array.map_to_asu() + else : + print "not unique" if (settings.d_min is not None) : array = array.resolution_filter(d_min=settings.d_min) - if (settings.expand_to_p1) : - array = array.niggli_cell().expand_to_p1() + self.filtered_array = array.deep_copy() if (settings.expand_anomalous) : array = array.generate_bijvoet_mates() + if (self.settings.show_missing_reflections) : + self.missing_set = array.complete_set().lone_set(array) + if (settings.expand_to_p1) : + original_symmetry = array.crystal_symmetry() + array = array.expand_to_p1().customized_copy( + crystal_symmetry=original_symmetry) + #array = array.niggli_cell().expand_to_p1() + #self.missing_set = self.missing_set.niggli_cell().expand_to_p1() + self.missing_set = self.missing_set.expand_to_p1().customized_copy( + crystal_symmetry=original_symmetry) data = array.data() assert (isinstance(data, flex.double) or isinstance(data, flex.bool)) self.r_free_mode = False @@ -39,20 +115,13 @@ raise Sorry("sigmas not defined.") sigmas = array.sigmas() array = array.select(sigmas != 0).customized_copy(data=data/sigmas) - uc = array.unit_cell() - self.unit_cell = uc - slice_selection = None - if (settings.slice_mode) : - slice_selection = miller.simple_slice( - indices=array.indices(), - slice_axis=settings.slice_axis, - slice_index=settings.slice_index) - index_span = array.index_span() - self.hkl_range = index_span.abs_range() - self.axes = [ uc.reciprocal_space_vector((self.hkl_range[0],0,0)), - uc.reciprocal_space_vector((0,self.hkl_range[1],0)), - uc.reciprocal_space_vector((0,0,self.hkl_range[2])) ] - indices = array.indices() + self.work_array = array + + def generate_view_data (self) : + from scitbx.array_family import flex + from scitbx import graphics_utils + settings = self.settings + data = self.data #self.work_array.data() if (settings.sqrt_scale_colors) and (isinstance(data, flex.double)) : data_for_colors = flex.sqrt(data) else : @@ -61,16 +130,21 @@ data_for_radii = flex.sqrt(data) else : data_for_radii = data.deep_copy() + if (settings.slice_mode) : + data = data.select(self.slice_selection) + if (not settings.keep_constant_scale) : + data_for_radii = data_for_radii.select(self.slice_selection) + data_for_colors = data_for_colors.select(self.slice_selection) if (settings.color_scheme == 0) : colors = graphics_utils.color_by_property( properties=data_for_colors, - selection=flex.bool(data.size(), True), + selection=flex.bool(data_for_colors.size(), True), color_all=False, use_rb_color_gradient=False) elif (settings.color_scheme == 1) : colors = graphics_utils.grayscale_by_property( properties=data_for_colors, - selection=flex.bool(data.size(), True), + selection=flex.bool(data_for_colors.size(), True), shade_all=False, invert=settings.black_background) else : @@ -78,34 +152,10 @@ base_color = (1.0,1.0,1.0) else : base_color = (0.0,0.0,0.0) - colors = flex.vec3_double(data.size(), base_color) - if (slice_selection is not None) : - data = data.select(slice_selection) - self.data = self.data.select(slice_selection) - if (data.size() == 0) : - raise ValueError("No data selected!") - indices = indices.select(slice_selection) - if (settings.keep_constant_scale) : - colors = colors.select(slice_selection) - elif (settings.color_scheme == 0) : - colors = graphics_utils.color_by_property( - properties=data_for_colors.select(slice_selection), - selection=flex.bool(data.size(), True), - color_all=False, - use_rb_color_gradient=False) - elif (settings.color_scheme == 1) : - colors = graphics_utils.grayscale_by_property( - properties=data_for_colors.select(slice_selection), - selection=flex.bool(data.size(), True), - shade_all=False, - invert=settings.black_background) - elif (settings.color_scheme == 2) : - colors = flex.vec3_double(data.size(), (1.0,1.0,1.0)) - if (not settings.keep_constant_scale) : - data_for_radii = data_for_radii.select(slice_selection) - self.colors = colors - self.points = uc.reciprocal_space_vector(indices) * 100. - self.indices = indices + colors = flex.vec3_double(data_for_colors.size(), base_color) + if (settings.slice_mode) and (settings.keep_constant_scale) : + colors = colors.select(self.slice_selection) + uc = self.work_array.unit_cell() abc = uc.parameters()[0:3] min_radius = 0.20 / max(abc) max_radius = 40 / max(abc) @@ -117,43 +167,86 @@ too_small = radii < min_radius radii.set_selected(too_small, flex.double(radii.size(), min_radius)) self.radii = radii - self.max_radius = flex.max(radii) - self.missing = flex.bool(self.radii.size(), False) - if (settings.show_missing_reflections) : - if (settings.show_only_missing) : - self.colors = flex.vec3_double() - self.points = flex.vec3_double() - self.radii = flex.double() - self.missing = flex.bool() - self.indices = flex.miller_index() - self.data = flex.double() - complete_set = array.complete_set() - if (settings.slice_mode) : - slice_selection = miller.simple_slice( - indices=complete_set.indices(), - slice_axis=settings.slice_axis, - slice_index=settings.slice_index) - missing = complete_set.select(slice_selection).lone_set(array).indices() + self.max_radius = max_radius + self.colors = colors + + def generate_missing_reflections (self) : + from cctbx import miller + from cctbx.array_family import flex + settings = self.settings + array = self.work_array + uc = array.unit_cell() + if (settings.show_only_missing) : + self.colors = flex.vec3_double() + self.points = flex.vec3_double() + self.radii = flex.double() + self.missing_flags = flex.bool() + self.indices = flex.miller_index() + self.data = flex.double() + self.sys_absent_flags = flex.bool() + if (settings.slice_mode) : + slice_selection = miller.simple_slice( + indices=self.missing_set.indices(), + slice_axis=settings.slice_axis, + slice_index=settings.slice_index) + missing = self.missing_set.select(slice_selection).indices() + else : + missing = self.missing_set.indices() + n_missing = missing.size() + if (n_missing > 0) : + points_missing = uc.reciprocal_space_vector(missing) * 100. + self.points.extend(points_missing) + if (settings.color_scheme != 0) : + self.colors.extend(flex.vec3_double(n_missing, (1.,0,0))) else : - missing = complete_set.lone_set(array).indices() - n_missing = missing.size() - if (n_missing > 0) : - points_missing = uc.reciprocal_space_vector(missing) * 100. - self.points.extend(points_missing) - if (settings.color_scheme != 0) : - self.colors.extend(flex.vec3_double(n_missing, (1.,0,0))) - else : - self.colors.extend(flex.vec3_double(n_missing, (1.,1.,1.))) - self.radii.extend(flex.double(n_missing, max_radius / 2)) - self.missing.extend(flex.bool(n_missing, True)) - self.indices.extend(missing) - self.data.extend(flex.double(n_missing, -1.)) - # XXX hack for process_pick_points - self.visible_points = flex.bool(self.points.size(), True) - assert (self.colors.size() == self.points.size() == self.indices.size() == - self.radii.size() == self.missing.size()) - self.clear_labels() + self.colors.extend(flex.vec3_double(n_missing, (1.,1.,1.))) + self.radii.extend(flex.double(n_missing, self.max_radius / 2)) + self.missing_flags.extend(flex.bool(n_missing, True)) + self.indices.extend(missing) + self.data.extend(flex.double(n_missing, -1.)) + self.sys_absent_flags.extend(flex.bool(n_missing, False)) + def generate_systematic_absences (self) : + from cctbx import miller + from cctbx import crystal + from cctbx.array_family import flex + settings = self.settings + array = self.filtered_array # XXX use original array here! + absence_array = generate_systematic_absences( + array=self.filtered_array, + expand_to_p1=settings.expand_to_p1, + generate_bijvoet_mates=settings.expand_anomalous) + if (settings.slice_mode) : + slice_selection = miller.simple_slice( + indices=absence_array.indices(), + slice_axis=settings.slice_axis, + slice_index=settings.slice_index) + absence_array = absence_array.select(slice_selection) + absence_flags = absence_array.data() + if (absence_flags.count(True) == 0) : + print "No systematic absences found!" + else : + new_indices = flex.miller_index() + for i_seq in absence_flags.iselection() : + hkl = absence_array.indices()[i_seq] + #if (hkl in self.indices) : + # j_seq = self.indices.index(hkl) + # self.colors[j_seq] = (1.0, 0.5, 1.0) + # self.radii[j_seq] = self.max_radius + # self.missing_flags[j_seq] = False + # self.sys_absent_flags[j_seq] = True + #else : + new_indices.append(hkl) + if (new_indices.size() > 0) : + uc = self.work_array.unit_cell() + points = uc.reciprocal_space_vector(new_indices) * 100 + self.points.extend(points) + self.radii.extend(flex.double(new_indices.size(), self.max_radius)) + self.indices.extend(new_indices) + self.colors.extend(flex.vec3_double(new_indices.size(), (1.,0.5,1.))) + self.missing_flags.extend(flex.bool(new_indices.size(), False)) + self.sys_absent_flags.extend(flex.bool(new_indices.size(), True)) + def clear_labels (self) : self.label_points = set([]) @@ -164,7 +257,7 @@ def get_reflection_info (self, k) : hkl = self.indices[k] d_min = self.unit_cell.d(hkl) - if (self.missing[k]) : + if (self.missing_flags[k]) or (self.sys_absent_flags[k]) : value = None else : value = self.data[k] @@ -182,6 +275,7 @@ self.display_as_spheres = True self.show_missing_reflections = False self.show_only_missing = False + self.show_systematic_absences = False self.sphere_detail = 20 self.pad_radii = False self.slice_mode = False Modified: trunk/crys3d/hklview/frames.py =================================================================== --- trunk/crys3d/hklview/frames.py 2011-07-07 22:34:52 UTC (rev 13438) +++ trunk/crys3d/hklview/frames.py 2011-07-07 23:18:50 UTC (rev 13439) @@ -82,6 +82,10 @@ self.panel_sizer.Add(box) box.Add(ctrls[0], 0, wx.ALL, 5) box.Add(ctrls2[0], 0, wx.ALL, 5) + ctrls = self.create_controls( + setting="show_systematic_absences", + label="Show systematic absences") + self.panel_sizer.Add(ctrls[0], 0, wx.ALL, 5) if (self.is_3d_view) : ctrls = self.create_controls( setting="sphere_detail", Modified: trunk/crys3d/hklview/view_2d.py =================================================================== --- trunk/crys3d/hklview/view_2d.py 2011-07-07 22:34:52 UTC (rev 13438) +++ trunk/crys3d/hklview/view_2d.py 2011-07-07 23:18:50 UTC (rev 13439) @@ -128,8 +128,7 @@ missing_pen = wx.Pen('red') else : missing_pen = wx.Pen('black') - max_radius = 40 / max(self.scene.unit_cell.parameters()[0:3]) - max_radius *= r / max(x_max, y_max) + max_radius = self.scene.max_radius * r / max(x_max, y_max) for k, hkl in enumerate(self.scene.points) : x_, y_ = hkl[i_x], hkl[i_y] x = center_x + r * x_ / x_max @@ -146,10 +145,15 @@ path.CloseSubpath() gc.PushState() gc.Translate(x,y) - if (self.scene.missing[k]) : + if (self.scene.missing_flags[k]) : gc.SetBrush(wx.TRANSPARENT_BRUSH) gc.SetPen(missing_pen) gc.StrokePath(path) + elif (self.scene.sys_absent_flags[k]) : + gc.SetBrush(wx.TRANSPARENT_BRUSH) + c = self.scene.colors[k] + gc.SetPen(wx.Pen((c[0]*255,c[1]*255,c[2]*255))) + gc.StrokePath(path) else : c = self.scene.colors[k] gc.SetBrush(wx.Brush((c[0]*255,c[1]*255,c[2]*255))) Modified: trunk/crys3d/hklview/view_3d.py =================================================================== --- trunk/crys3d/hklview/view_3d.py 2011-07-07 22:34:52 UTC (rev 13438) +++ trunk/crys3d/hklview/view_3d.py 2011-07-07 23:18:50 UTC (rev 13439) @@ -117,14 +117,15 @@ colors = self.scene.colors radii = self.scene.radii max_radius = self.scene.max_radius + scale_factor = self.settings.sphere_detail / self.scene.max_radius assert (colors.size() == radii.size() == self.scene.points.size()) + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.1, 0.1, 0.1, 1.0]) + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0.1, 0.1, 0.1, 1.0]) for i, hkl in enumerate(self.scene.points) : col = list(colors[i]) + [1.0] - detail = max(4, int(self.settings.sphere_detail*radii[i]/max_radius)) + detail = max(4, int(radii[i] * scale_factor)) #glColor3f(*colors[i]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col) - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.1, 0.1, 0.1, 1.0]) - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0.1, 0.1, 0.1, 1.0]) glPushMatrix() glTranslated(*hkl) gltbx.util.SolidSphere(radius=radii[i], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |