def scale_two_real_maps_in_fourier_space(m1, m2, cs, d_min, vector_map):
    f1 = maptbx.map_to_map_coefficients(m=m1, cs=cs, d_min=d_min)
    f2 = maptbx.map_to_map_coefficients(m=m2, cs=cs, d_min=d_min)
    if (vector_map):
        f2 = f2.phase_transfer(phase_source=f1)
    ss = 1. / flex.pow2(f1.d_spacings().data()) / 4.
    bs = flex.double([i for i in xrange(0, 100)])
    mc = mmtbx.bulk_solvent.complex_f_minus_f_kb_scaled(
        f1.data(), f2.data(), bs, ss)
    crystal_gridding = maptbx.crystal_gridding(
        unit_cell=cs.unit_cell(),
        space_group_info=cs.space_group_info(),
        pre_determined_n_real=m1.all())
    fft_map = miller.fft_map(crystal_gridding=crystal_gridding,
                             fourier_coefficients=f1.array(data=mc))
    return fft_map.real_map_unpadded()
Exemplo n.º 2
0
    def compute_if_altloc(self, altloc_indices, computed_results_AB):
        #
        def combine(mA, mB, sc):
            #m = (mA+mB*sc)/2
            m = maptbx.combine_and_maximize_maps(map_data_1=mA,
                                                 map_data_2=mB * sc,
                                                 n_real=mB.all())
            return m / m.sample_standard_deviation()

        def scale(x, y):
            x = flex.abs(x)
            y = flex.abs(y)
            d = flex.sum(y * y)
            return flex.sum(x * y) / d

        def get_map(mc):
            fft_map = mc.fft_map(resolution_factor=0.25)
            #fft_map.apply_volume_scaling()
            fft_map.apply_sigma_scaling()
            m = fft_map.real_map_unpadded()
            return m

        # Not sure if this definition of sel strings can be prone to errors...
        sel_A_string = self.selection_string + ' altloc %s' % list(
            altloc_indices)[0]
        sel_B_string = self.selection_string + ' altloc %s' % list(
            altloc_indices)[1]
        sel_AB_string = self.selection_string
        sel_A = self.model.selection(string=sel_A_string)
        sel_B = self.model.selection(string=sel_B_string)
        sel_AB = self.model.selection(string=sel_AB_string)
        sf_A = self.model.get_sites_frac().select(sel_A)
        sf_B = self.model.get_sites_frac().select(sel_B)
        sf_AB = self.model.get_sites_frac().select(sel_AB)
        #
        computed_results_A = self.compute(selection_bool=sel_A)
        computed_results_B = self.compute(selection_bool=sel_B)
        mc_A_polder = computed_results_A.mc_polder
        mc_B_polder = computed_results_B.mc_polder
        mc_AB_polder = computed_results_AB.mc_polder
        m_A = get_map(mc_A_polder)
        m_B = get_map(mc_B_polder)
        m_AB = get_map(mc_AB_polder)
        mv_A = flex.double()
        mv_B = flex.double()
        for sf_A_, sf_B_ in zip(sf_A, sf_B):
            mv_A.append(m_A.tricubic_interpolation(sf_A_))
            mv_B.append(m_B.tricubic_interpolation(sf_B_))
        sc = scale(mv_A, mv_B)
        m = combine(m_A, m_B, sc)
        ###
        mv_A = flex.double()
        mv_B = flex.double()
        for sf_ in sf_AB:
            mv_A.append(m.tricubic_interpolation(sf_))
            mv_B.append(m_AB.tricubic_interpolation(sf_))
        sc = scale(mv_A, mv_B)
        m = combine(m, m_AB, sc)
        #
        mc = maptbx.map_to_map_coefficients(m=m,
                                            cs=self.cs,
                                            d_min=mc_A_polder.d_min())
        #    mtz_dataset = mc.as_mtz_dataset(column_root_label='polder')
        #    mtz_object = mtz_dataset.mtz_object()
        #    mtz_object.write(file_name = "%s.mtz"%'polder_cl')
        #
        computed_results = computed_results_AB
        computed_results.mc_polder = mc

        return computed_results