def add_dose_time_to_mtz(hklin, hklout, doses, times=None): """Add doses and times from dictionaries doses, times (optional) to hklin to produce hklout. The dictionaries are indexed by the BATCH column in hklin. Will raise exception if no BATCH column.""" # instantiate the MTZ object representation from iotbx import mtz from cctbx.array_family import flex mtz_obj = mtz.object(file_name=hklin) batch_column = None batch_dataset = None for crystal in mtz_obj.crystals(): for dataset in crystal.datasets(): for column in dataset.columns(): if column.label() == "BATCH": batch_column = column batch_dataset = dataset if not batch_column: raise RuntimeError("no BATCH column found in %s" % hklin) # right, so get the values out from the batch column, create a flex # array of the same size and assign DOSE, TIME, then add these to the # same dataset. batch_column_values = batch_column.extract_values( not_a_number_substitute=-1) dose_column = batch_dataset.add_column(label="DOSE", type="R") dose_column_values = flex.float() if times: time_column = batch_dataset.add_column(label="TIME", type="R") time_column_values = flex.float() valid = flex.bool() for b in batch_column_values: valid.append(True) dose_column_values.append(doses.get(b, -1.0)) if times: time_column_values.append(times.get(b, -1.0)) # add the columns back to the MTZ file structure dose_column.set_values(values=dose_column_values, selection_valid=valid) if times: time_column.set_values(values=time_column_values, selection_valid=valid) # and write this lot out as hklout mtz_obj.write(file_name=hklout)
def exercise_change_basis_in_place(): from cctbx import sgtbx space_group_info = sgtbx.space_group_info(symbol='P4') unit_cell = space_group_info.any_compatible_unit_cell(volume=1000) miller_set = crystal.symmetry( unit_cell=unit_cell, space_group_info=space_group_info).build_miller_set( d_min=1, anomalous_flag=True) miller_set = miller_set.expand_to_p1().customized_copy( space_group_info=miller_set.space_group_info()) m = mtz.object() m.set_title('This is a title') m.set_space_group_info(miller_set.space_group_info()) x = m.add_crystal('XTAL', 'CCTBX', miller_set.unit_cell().parameters()) d = x.add_dataset('TEST', 1) indices = miller_set.indices() original_indices = indices.deep_copy() # map the miller indices to one hemisphere (i.e. just I+) miller.map_to_asu(m.space_group().type(), False, indices) h, k, l = [i.iround() for i in indices.as_vec3_double().parts()] m.adjust_column_array_sizes(len(h)) m.set_n_reflections(len(h)) # assign H, K, L d.add_column('H', 'H').set_values(h.as_double().as_float()) d.add_column('K', 'H').set_values(k.as_double().as_float()) d.add_column('L', 'H').set_values(l.as_double().as_float()) d.add_column('M_ISYM', 'Y').set_values(flex.float(len(indices))) b = m.add_batch() b.set_cell(flex.float(unit_cell.parameters())) b.set_umat( flex.float( (-0.9542511701583862, -0.1780465543270111, -0.2402169108390808, -0.13100790977478027, 0.9711279273033142, -0.19936780631542206, 0.26877808570861816, -0.1587766408920288, -0.9500254392623901))) m.change_basis_in_place(sgtbx.change_of_basis_op('-h,k,-l')) assert approx_equal( b.umat(), (0.9542511701583862, 0.1780465543270111, 0.2402169108390808, -0.13100790977478027, 0.9711279273033142, -0.19936780631542206, -0.26877808570861816, 0.1587766408920288, 0.9500254392623901))
def change_basis_in_place(self, cb_op, new_space_group_info=None, assert_is_compatible_unit_cell=False): assert len(column_type_legend) == 17 # programmer alert # force update if column_type_legend is changed for column_type in self.column_types(): if (column_type == "P"): raise RuntimeError( "In-place transformation of phase angles not implemented.") if (column_type == "A"): raise RuntimeError( "In-place transformation of Hendrickson-Lattman coefficients" " not implemented.") if (new_space_group_info is None): new_space_group_info = self.space_group_info().change_basis(cb_op) if "M_ISYM" in self.column_labels(): original_miller_indices = self.extract_original_index_miller_indices() indices = cb_op.apply(original_miller_indices) isym = flex.int(len(indices)) self.replace_original_index_miller_indices(indices) else: self.replace_miller_indices(cb_op.apply(self.extract_miller_indices())) self.set_space_group_info(space_group_info=new_space_group_info) for crystal in self.crystals(): crystal_symmetry = cctbx.crystal.symmetry( unit_cell=crystal.unit_cell().change_basis(cb_op=cb_op), space_group_info=new_space_group_info, assert_is_compatible_unit_cell=assert_is_compatible_unit_cell, raise_sorry_if_incompatible_unit_cell=True) crystal.set_unit_cell_parameters( crystal_symmetry.unit_cell().parameters()) # transform & symmetrize per-batch unit cell to support Scala 6.0 (NKS) # re-zero the U-matrix so nobody tries to use it downstream for batch in self.batches(): batch_uc = uctbx.unit_cell(list(batch.cell())) batch_crystal_symmetry = cctbx.crystal.symmetry( unit_cell=batch_uc.change_basis(cb_op=cb_op), space_group_info=new_space_group_info, assert_is_compatible_unit_cell=assert_is_compatible_unit_cell) batch.set_cell(flex.float( batch_crystal_symmetry.unit_cell().parameters())) batch.set_umat(flex.float( (0,0,0,0,0,0,0,0,0)))
def numpy_map_as_flex_standard_order(np_array=None, mapc=None, mapr=None, maps=None, internal_standard_order=None): # Convert numpy version of map (from CCP4-EM mrcfile) to flex.float array assert np_array is not None and mapc is not None and \ mapr is not None and maps is not None # Verify that the numpy array is float. If it isn't then this conversion # will not work below when we convert to a flex array (but it will not # give an error message). assert type(np_array[0, 0, 0].tolist()) == type(float(1)) # Input map can have columns, rows, sections corresponding to any of (X,Y,Z) # Get the order for transposing input map (columns are mapc (X=1, Y=2, Z=3), # rows are mapr (X=1, Y=2, Z=3), sections are maps (X=1, Y=2, Z=3). i_order = get_standard_order( mapc, mapr, maps, internal_standard_order=internal_standard_order) # Transpose the input numpy array to match Phenix expected order of (3,2,1) np_array_standard_order = np.transpose(np_array, i_order) # this np array may have any actual memory layout. We have to # flatten it out, read into flex array and reshape # Save the shape shape = tuple(np_array_standard_order.shape) # Flatten it out np_array_standard_order_1d = np_array_standard_order.flatten().tolist() # Read in to flex array flex_array = flex.float(np_array_standard_order_1d) # set up new shape (same as was in the numpy array after transposing it) flex_grid = grid(shape) # Reshape the flex array flex_array.reshape(flex_grid) # All done. Returning float array return flex_array
def ncs_averaging(self): if not self.params.ncs_averaging: self.ncs_cc = None return if resolve_ncs_average is None: raise RuntimeError( "solve_resolve must be available for NCS averaging functionality" ) assert self.ncs_object is not None s = StringIO() resolve_mask = flex.float(self.mask.accessor(), 0) resolve_mask.set_selected(self.protein_selection, 1) na = resolve_ncs_average(map=self.map.as_float(), mask=resolve_mask, space_group=self.map_coeffs.space_group(), unit_cell=self.map_coeffs.unit_cell(), ncs_object=self.ncs_object, resolution=self.d_min, out=s) average_map = na.average_map self.ncs_cc = na.ncs_cc n_ncs_oper = na.n_nc_oper self.map = average_map.as_double()
def ncs_averaging(self): if not self.params.ncs_averaging: self.ncs_cc = None return if resolve_ncs_average is None: raise RuntimeError( "solve_resolve must be available for NCS averaging functionality") assert self.ncs_object is not None s = StringIO() resolve_mask = flex.float(self.mask.accessor(), 0) resolve_mask.set_selected(self.protein_selection, 1) na=resolve_ncs_average( map=self.map.as_float(), mask=resolve_mask, space_group=self.map_coeffs.space_group(), unit_cell=self.map_coeffs.unit_cell(), ncs_object=self.ncs_object, resolution=self.d_min, out=s) average_map = na.average_map self.ncs_cc = na.ncs_cc n_ncs_oper=na.n_nc_oper self.map = average_map.as_double()
def recycle_one_dano(missing, verbose): assert missing in [None, "+", "-"] from cctbx import crystal cs = crystal.symmetry( unit_cell=(13,17,19,85,95,105), space_group_symbol="P1") from cctbx.array_family import flex mi = flex.miller_index([(1,2,3), (-1,-2,-3)]) fpm = flex.double([2.5, 5.5]) spm = flex.double([0.1, 0.3]) from cctbx import miller ms = miller.set(crystal_symmetry=cs, indices=mi, anomalous_flag=True) ma = ms.array(data=fpm, sigmas=spm) mtz_dataset = ma.as_mtz_dataset(column_root_label="X") if (missing is not None): for col in mtz_dataset.columns(): if (col.label() in ["X(%s)" % missing, "SIGX(%s)" % missing]): col.set_values( values=flex.float([0]), selection_valid=flex.bool([False])) if (missing == "+"): i = 1 else: i = 0 ma = ma.select(flex.size_t([i])) mtz_obj = mtz_dataset.mtz_object() from cctbx.xray import observation_types ma.set_observation_type(observation_types.reconstructed_amplitude()) mtz_obj_reco = ma.as_mtz_dataset(column_root_label="R").mtz_object() sio = StringIO() print >> sio, "Resulting mtz from .as_mtz_dataset():" mtz_obj_reco.show_column_data_human_readable(out=sio) print >> sio ma_reco = mtz_obj_reco.as_miller_arrays()[0] print >> sio, "mtz_obj_reco.as_miller_arrays result:" ma_reco.show_array(f=sio) print >> sio if (verbose): sys.stdout.write(sio.getvalue()) if (missing is None): expected = """\ Resulting mtz from .as_mtz_dataset(): Column data: ------------------------------------------------------------------------------- R SIGR DANOR SIGDANOR ISYMR 1 2 3 4 0.158114 -3 0.316228 0 ------------------------------------------------------------------------------- mtz_obj_reco.as_miller_arrays result: (1, 2, 3) 2.5 0.223606796247 (-1, -2, -3) 5.5 0.223606796247 """ elif (missing == "+"): expected = """\ Resulting mtz from .as_mtz_dataset(): Column data: ------------------------------------------------------------------------------- R SIGR DANOR SIGDANOR ISYMR 1 2 3 5.5 0.3 None None 2 ------------------------------------------------------------------------------- mtz_obj_reco.as_miller_arrays result: (-1, -2, -3) 5.5 0.300000011921 """ elif (missing == "-"): expected = """\ Resulting mtz from .as_mtz_dataset(): Column data: ------------------------------------------------------------------------------- R SIGR DANOR SIGDANOR ISYMR 1 2 3 2.5 0.1 None None 1 ------------------------------------------------------------------------------- mtz_obj_reco.as_miller_arrays result: (1, 2, 3) 2.5 0.10000000149 """ else: raise RuntimeError("Unreachable.") from libtbx.test_utils import show_diff assert not show_diff(sio.getvalue(), expected)
def change_basis_in_place(self, cb_op, new_space_group_info=None, assert_is_compatible_unit_cell=False): assert len(column_type_legend) == 17 # programmer alert # force update if column_type_legend is changed for column_type in self.column_types(): if (column_type == "P"): raise RuntimeError( "In-place transformation of phase angles not implemented.") if (column_type == "A"): raise RuntimeError( "In-place transformation of Hendrickson-Lattman coefficients" " not implemented.") if (new_space_group_info is None): new_space_group_info = self.space_group_info().change_basis(cb_op) if "M_ISYM" in self.column_labels(): original_miller_indices = self.extract_original_index_miller_indices() indices = cb_op.apply(original_miller_indices) isym = flex.int(len(indices)) self.replace_original_index_miller_indices(indices) else: self.replace_miller_indices(cb_op.apply(self.extract_miller_indices())) self.set_space_group_info(space_group_info=new_space_group_info) for crystal in self.crystals(): crystal_symmetry = cctbx.crystal.symmetry( unit_cell=crystal.unit_cell().change_basis(cb_op=cb_op), space_group_info=new_space_group_info, assert_is_compatible_unit_cell=assert_is_compatible_unit_cell, raise_sorry_if_incompatible_unit_cell=True) crystal.set_unit_cell_parameters( crystal_symmetry.unit_cell().parameters()) # transform & symmetrize per-batch unit cell to support Scala 6.0 (NKS) # MTZ stores umat corresponding to Busing & Levy convention def mosflm_B(unit_cell): from math import cos, sin, radians params = unit_cell.parameters() rparams = unit_cell.reciprocal_parameters() a, b, c = params[:3] alpha, beta, gamma = [radians(a) for a in params[3:]] ra, rb, rc = rparams[:3] ralpha, rbeta, rgamma = [radians(a) for a in rparams[3:]] B = (ra, rb * cos(rgamma), rc * cos(rbeta), 0, rb * sin(rgamma), -rc * sin(rbeta) * cos(alpha), 0, 0, 1/c) return B from scitbx import matrix for batch in self.batches(): batch_uc = uctbx.unit_cell(list(batch.cell())) B = matrix.sqr(mosflm_B(batch_uc)) U = matrix.sqr(batch.umat()).transpose() A = U * B direct_matrix = A.inverse() M = cb_op.c_inv().r().transpose().as_rational() new_direct_matrix = M * direct_matrix new_uc = batch_uc.change_basis(cb_op=cb_op) new_B = matrix.sqr(mosflm_B(new_uc)) new_U = (new_direct_matrix.inverse() * new_B.inverse()).transpose() batch_crystal_symmetry = cctbx.crystal.symmetry( unit_cell=new_uc, space_group_info=new_space_group_info, assert_is_compatible_unit_cell=assert_is_compatible_unit_cell) batch.set_cell(flex.float( batch_crystal_symmetry.unit_cell().parameters())) batch.set_umat(flex.float(new_U))
def exercise_unmerged(space_group_info): import random from cctbx import sgtbx # shuffle the space_group = sgtbx.space_group('P 1', no_expand=True) perm = list(range(len(space_group_info.group()))) random.shuffle(perm) for i in perm: space_group.expand_smx(space_group_info.group()[i]) unit_cell = space_group_info.any_compatible_unit_cell(volume=1000) for cb_op in (None, space_group.info().change_of_basis_op_to_primitive_setting(), unit_cell.change_of_basis_op_to_niggli_cell()): miller_set = crystal.symmetry( unit_cell=unit_cell, space_group=space_group).build_miller_set(d_min=1, anomalous_flag=True) miller_set = miller_set.expand_to_p1().customized_copy( space_group_info=miller_set.space_group_info()) if cb_op is not None: miller_set = miller_set.change_basis(cb_op) m = mtz.object() m.set_title('This is a title') m.set_space_group_info(miller_set.space_group_info()) x = m.add_crystal('XTAL', 'CCTBX', miller_set.unit_cell().parameters()) d = x.add_dataset('TEST', 1) indices = miller_set.indices() original_indices = indices.deep_copy() # map the miller indices to one hemisphere (i.e. just I+) miller.map_to_asu(m.space_group().type(), False, indices) h, k, l = [i.iround() for i in indices.as_vec3_double().parts()] m.adjust_column_array_sizes(len(h)) m.set_n_reflections(len(h)) # assign H, K, L d.add_column('H', 'H').set_values(h.as_double().as_float()) d.add_column('K', 'H').set_values(k.as_double().as_float()) d.add_column('L', 'H').set_values(l.as_double().as_float()) d.add_column('M_ISYM', 'Y').set_values(flex.float(len(indices))) m.replace_original_index_miller_indices(original_indices) assert (m.extract_original_index_miller_indices() == original_indices ).count(False) == 0 # check the indices in the mtz file are actually in the asu extracted_indices = m.extract_miller_indices() miller.map_to_asu(m.space_group().type(), False, extracted_indices) assert ( extracted_indices == m.extract_miller_indices()).count(False) == 0 # test change_basis_in_place if appropriate for current space group import cctbx.sgtbx.cosets cb_op_to_niggli_cell \ = miller_set.change_of_basis_op_to_niggli_cell() minimum_cell_symmetry = crystal.symmetry.change_basis( miller_set.crystal_symmetry(), cb_op=cb_op_to_niggli_cell) lattice_group = sgtbx.lattice_symmetry.group( minimum_cell_symmetry.unit_cell(), max_delta=3.0) lattice_group.expand_inv(sgtbx.tr_vec((0, 0, 0))) lattice_group.make_tidy() cosets = sgtbx.cosets.left_decomposition_point_groups_only( g=lattice_group, h=minimum_cell_symmetry.reflection_intensity_symmetry( anomalous_flag=True).space_group( ).build_derived_acentric_group().make_tidy()) possible_twin_laws = cosets.best_partition_representatives( cb_op=cb_op_to_niggli_cell.inverse(), omit_first_partition=True, omit_negative_determinants=True) for twin_law in possible_twin_laws: cb_op = sgtbx.change_of_basis_op(twin_law.as_xyz()) #print cb_op.as_hkl() # forward direction m.change_basis_in_place(cb_op) assert (m.extract_original_index_miller_indices() == cb_op.apply( original_indices)).count(False) == 0 ## check the indices in the mtz file are actually in the asu #extracted_indices = m.extract_miller_indices() #miller.map_to_asu(m.space_group().type(), False, extracted_indices) #assert (extracted_indices == m.extract_miller_indices()).count(False) == 0 # and back again m.change_basis_in_place(cb_op.inverse()) assert (m.extract_original_index_miller_indices() == original_indices).count(False) == 0
def add_dose_time_to_mtz(hklin, hklout, doses, times = None): '''Add doses and times from dictionaries doses, times (optional) to hklin to produce hklout. The dictionaries are indexed by the BATCH column in hklin. Will raise exception if no BATCH column.''' # instantiate the MTZ object representation from iotbx import mtz from cctbx.array_family import flex mtz_obj = mtz.object(file_name = hklin) batch_column = None batch_dataset = None for crystal in mtz_obj.crystals(): for dataset in crystal.datasets(): for column in dataset.columns(): if column.label() == 'BATCH': batch_column = column batch_dataset = dataset if not batch_column: raise RuntimeError, 'no BATCH column found in %s' % hklin # right, so get the values out from the batch column, create a flex # array of the same size and assign DOSE, TIME, then add these to the # same dataset. batch_column_values = batch_column.extract_values( not_a_number_substitute = -1) dose_column = batch_dataset.add_column(label = 'DOSE', type = 'R') dose_column_values = flex.float() if times: time_column = batch_dataset.add_column(label = 'TIME', type = 'R') time_column_values = flex.float() valid = flex.bool() for b in batch_column_values: valid.append(True) dose_column_values.append(doses.get(b, -1.0)) if times: time_column_values.append(times.get(b, -1.0)) # add the columns back to the MTZ file structure dose_column.set_values(values = dose_column_values, selection_valid = valid) if times: time_column.set_values(values = time_column_values, selection_valid = valid) # and write this lot out as hklout mtz_obj.write(file_name = hklout)
def exercise_unmerged(space_group_info): import random from cctbx import sgtbx # shuffle the space_group = sgtbx.space_group("P 1", no_expand=True) perm = list(range(len(space_group_info.group()))) random.shuffle(perm) for i in perm: space_group.expand_smx(space_group_info.group()[i]) unit_cell = space_group_info.any_compatible_unit_cell(volume=1000) for cb_op in ( None, space_group.info().change_of_basis_op_to_primitive_setting(), unit_cell.change_of_basis_op_to_niggli_cell(), ): miller_set = crystal.symmetry(unit_cell=unit_cell, space_group=space_group).build_miller_set( d_min=1, anomalous_flag=True ) miller_set = miller_set.expand_to_p1().customized_copy(space_group_info=miller_set.space_group_info()) if cb_op is not None: miller_set = miller_set.change_basis(cb_op) m = mtz.object() m.set_title("This is a title") m.set_space_group_info(miller_set.space_group_info()) x = m.add_crystal("XTAL", "CCTBX", miller_set.unit_cell().parameters()) d = x.add_dataset("TEST", 1) indices = miller_set.indices() original_indices = indices.deep_copy() # map the miller indices to one hemisphere (i.e. just I+) miller.map_to_asu(m.space_group().type(), False, indices) h, k, l = [i.iround() for i in indices.as_vec3_double().parts()] m.adjust_column_array_sizes(len(h)) m.set_n_reflections(len(h)) # assign H, K, L d.add_column("H", "H").set_values(h.as_double().as_float()) d.add_column("K", "H").set_values(k.as_double().as_float()) d.add_column("L", "H").set_values(l.as_double().as_float()) d.add_column("M_ISYM", "Y").set_values(flex.float(len(indices))) m.replace_original_index_miller_indices(original_indices) assert (m.extract_original_index_miller_indices() == original_indices).count(False) == 0 # check the indices in the mtz file are actually in the asu extracted_indices = m.extract_miller_indices() miller.map_to_asu(m.space_group().type(), False, extracted_indices) assert (extracted_indices == m.extract_miller_indices()).count(False) == 0 # test change_basis_in_place if appropriate for current space group import cctbx.sgtbx.cosets cb_op_to_niggli_cell = miller_set.change_of_basis_op_to_niggli_cell() minimum_cell_symmetry = crystal.symmetry.change_basis(miller_set.crystal_symmetry(), cb_op=cb_op_to_niggli_cell) lattice_group = sgtbx.lattice_symmetry.group(minimum_cell_symmetry.unit_cell(), max_delta=3.0) lattice_group.expand_inv(sgtbx.tr_vec((0, 0, 0))) lattice_group.make_tidy() cosets = sgtbx.cosets.left_decomposition_point_groups_only( g=lattice_group, h=minimum_cell_symmetry.reflection_intensity_symmetry(anomalous_flag=True) .space_group() .build_derived_acentric_group() .make_tidy(), ) possible_twin_laws = cosets.best_partition_representatives( cb_op=cb_op_to_niggli_cell.inverse(), omit_first_partition=True, omit_negative_determinants=True ) for twin_law in possible_twin_laws: cb_op = sgtbx.change_of_basis_op(twin_law.as_xyz()) # print cb_op.as_hkl() # forward direction m.change_basis_in_place(cb_op) assert (m.extract_original_index_miller_indices() == cb_op.apply(original_indices)).count(False) == 0 ## check the indices in the mtz file are actually in the asu # extracted_indices = m.extract_miller_indices() # miller.map_to_asu(m.space_group().type(), False, extracted_indices) # assert (extracted_indices == m.extract_miller_indices()).count(False) == 0 # and back again m.change_basis_in_place(cb_op.inverse()) assert (m.extract_original_index_miller_indices() == original_indices).count(False) == 0
def __call__ (self, map_coeffs, fmodel, generate_new_mask=False, map_type=None) : # XXX probably not a good idea to average anomalous maps #if (map_type is not None) and (map_type.lower().startswith("anom")) : # return map_coeffs from solve_resolve.resolve_python.resolve_utils import get_map_mask_sg_cell from solve_resolve.resolve_python.ncs_average import ncs_average from cctbx import maptbx from scitbx.array_family import flex if (map_coeffs.anomalous_flag()) : map_coeffs = map_coeffs.average_bijvoet_mates() fft_map = map_coeffs.fft_map( symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.params.resolution_factor) map = fft_map.apply_volume_scaling().real_map_unpadded().as_float() if (self.verbose) : out = self.log else : out = null_out() if (self.mask is None) or (generate_new_mask) : if (self.params.use_molecule_mask) : self.mask = flex.float(real_map.size(), 0) sites_cart = fmodel.xray_structure.sites_cart() if (self.params.exclude_hd) : sites_cart = sites_cart.select(~fmodel.xray_structure.hd_selection()) indices = maptbx.grid_indices_around_sites( unit_cell=map_coeffs.unit_cell(), fft_n_real=real_map.focus(), fft_m_real=real_map.all(), sites_cart=sites_cart, site_radii=flex.double(sites_cart.size(), self.params.averaging_radius)) mask.set_selected(indices, 1) mask.reshape(real_map.accessor()) else : mask_map_coeffs = fmodel.electron_density_map().map_coefficients( map_type="2mFo-DFc") mask_fft_map = mask_map_coeffs.fft_map( symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.params.resolution_factor) mask_map = mask_fft_map.apply_volume_scaling().real_map_unpadded().as_float() map_db,mask_map_db,space_group_object,unit_cell_object=\ get_map_mask_sg_cell( map_coeffs=mask_map_coeffs, map=mask_map, space_group=map_coeffs.space_group(), unit_cell=map_coeffs.unit_cell(), solvent_content=self.params.solvent_content, wang_radius=self.params.averaging_radius, resolution=map_coeffs.d_min(), out=out, resolve_command_list=None) #map = map_db.map self.mask = mask_map_db.map averaged = ncs_average( map=map, mask=self.mask, ncs_object=self.ncs_object, space_group=map_coeffs.space_group(), unit_cell=map_coeffs.unit_cell(), resolution=map_coeffs.d_min(), out=out) new_map_coeffs = map_coeffs.structure_factors_from_map( map=averaged.average_map.as_double(), use_sg=True) return new_map_coeffs
def __call__ (self, map_coeffs, fmodel, generate_new_mask=False, map_type=None) : # XXX probably not a good idea to average anomalous maps #if (map_type is not None) and (map_type.lower().startswith("anom")) : # return map_coeffs from solve_resolve.resolve_python.resolve_utils import get_map_mask_sg_cell from solve_resolve.resolve_python.ncs_average import ncs_average from cctbx import maptbx from scitbx.array_family import flex if (map_coeffs.anomalous_flag()) : map_coeffs = map_coeffs.average_bijvoet_mates() fft_map = map_coeffs.fft_map( symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.params.resolution_factor) map = fft_map.apply_volume_scaling().real_map_unpadded().as_float() if (self.verbose) : out = self.log else : out = null_out() if (self.mask is None) or (generate_new_mask) : if (self.params.use_molecule_mask) : self.mask = flex.float(real_map.size(), 0) sites_cart = fmodel.xray_structure.sites_cart() if (self.params.exclude_hd) : sites_cart = sites_cart.select(~fmodel.xray_structure.hd_selection()) indices = maptbx.grid_indices_around_sites( unit_cell=map_coeffs.unit_cell(), fft_n_real=real_map.focus(), fft_m_real=real_map.all(), sites_cart=sites_cart, site_radii=flex.double(sites_cart.size(), self.params.averaging_radius)) mask.set_selected(indices, 1) mask.reshape(real_map.accessor()) else : mask_map_coeffs = fmodel.electron_density_map().map_coefficients( map_type="2mFo-DFc") mask_fft_map = mask_map_coeffs.fft_map( symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.params.resolution_factor) mask_map = mask_fft_map.apply_volume_scaling().real_map_unpadded().as_float() map_db,mask_map_db,space_group_object,unit_cell_object=\ get_map_mask_sg_cell( map_coeffs=mask_map_coeffs, map=mask_map, space_group=map_coeffs.space_group(), unit_cell=map_coeffs.unit_cell(), solvent_content=self.params.solvent_content, wang_radius=self.params.averaging_radius, resolution=map_coeffs.d_min(), out=out, resolve_command_list=None) #map = map_db.map self.mask = mask_map_db.map averaged = ncs_average( map=map, mask=self.mask, ncs_object=self.ncs_object, space_group=map_coeffs.space_group(), unit_cell=map_coeffs.unit_cell(), resolution=map_coeffs.d_min(), out=out) new_map_coeffs = map_coeffs.structure_factors_from_map( map=averaged.average_map.as_double(), use_sg=True) return new_map_coeffs