Esempio n. 1
0
def run(args=None):
    '''
    Extract l=0 slice from mtz file, export as new .mtz, .npy and plot
    '''
    ###########################################################################
    #                         Start log file                                  #
    ###########################################################################
    # init log file
    l = Log(log_name='slice_mtz_log.txt')
    l.title("exp.check_2d_detail")

    ###########################################################################
    #                      Process input Params                               #
    ###########################################################################

    l.process_message('Processing input...\n')
    working_params = slice_phil.phil_parse(args=args,
                                           log=l)  # use phil to process input
    p = working_params.slice_mtz

    ###########################################################################
    #                         Reading .mtz file                               #
    ###########################################################################

    if p.input.mtz_in != None:
        l.process_message('Reading mtz file...')
        mtz_obj = MTZClass(p.input.mtz_in)

        ###########################################################################
        #                        Slicing .mtz file                                #
        ###########################################################################

        # Select which array to slice
        l.process_message('Slicing mtz file and writing to {}...'.format(
            p.output.mtz_out))
        ar = p.params.array
        if ar == 'Ibrg':
            ar_num = 0
            l.warning('Array name: Ibrg')
        if ar == 'Itot':
            ar_num = 1
            l.warning('Array name: Itot')
        if ar == 'Idff':
            ar_num = 2
            l.warning('Array name: Idff')
        slice_2D = mtz_obj.slice_mtz(mtz_out_name=p.output.mtz_out,
                                     array_num=ar_num)
        l.process_message('Saving 2D slice as .npy file: {}...'.format(
            p.output.npy_out))
        np.save(p.output.npy_out, slice_2D)

###########################################################################
#                          Reading .npy Slice                             #
###########################################################################

    if p.input.npy_in != None:
        l.process_message('Loading 2D array from npy file...')
        slice_2D = np.load(p.input.npy_in)

###########################################################################
#                          Cut 2D map!                                    #
###########################################################################

    sp = np.shape(slice_2D)[0] + 1
    delta = int(round(sp / 10))
    delta_y = int(round(delta / 2))
    center = int((sp / 2) - 1)

    print sp, delta, delta_y, center

    slice_2D = slice_2D[-delta:, center - delta_y:center + delta_y]

    print np.shape(slice_2D)

    ###########################################################################
    #                             Plotting Slice                              #
    ###########################################################################

    l.process_message('Plotting 2D slice and saving to: {}...'.format(
        p.output.plt_out))
    l.show_info('Minimum of slice: {:.2f}'.format(np.nanmin(slice_2D)))
    l.show_info('Maximum of slice: {:.2f}'.format(np.nanmax(slice_2D)))
    if p.params.vmin == None and p.params.vmax == None:
        l.warning('Automatic determination of minimum and maximum values')
    else:
        l.show_info('Minimum value for plotting: {:.2f}'.format(p.params.vmin))
        l.show_info('Maximum value for plotting: {:.2f}'.format(p.params.vmax))
    pt = Plot()
    pt.contour2D(slice_2D,
                 plotfile_name=p.output.plt_out,
                 vmin=p.params.vmin,
                 vmax=p.params.vmax)

    ###########################################################################
    #                            Close Log File                               #
    ###########################################################################

    l.close_log()
Esempio n. 2
0
def run(args=None):
    '''
    Check additivity of motion in reciprocal space, subtract mtz files
    '''

    ###########################################################################
    #                         Start log file                                  #
    ###########################################################################
    # init log file
    l = Log(log_name='additivity_all_log.txt')
    l.title("exp.additivity_all module")

    ###########################################################################
    #                      Process input Params                               #
    ###########################################################################

    l.process_message('Processing input...\n')
    working_params = additivity_all_phil.phil_parse(
        args=args, log=l)  # use phil to process input
    p = working_params.additivity_all

    ###########################################################################
    #                        Generate ensembles                               #
    ###########################################################################

    ens_list = [
        'rbTrans', 'rbRot', 'rbMix', 'ens', 'rbTransEns', 'rbRotEns',
        'rbMixEns'
    ]
    ens_command_list = [
        [
            True,
            [
                'pdb_in={}'.format(p.input.single_pdb),
                'pdb_out={}.pdb'.format(ens_list[0]), 'translation_only=True'
            ]
        ],
        [
            True,
            [
                'pdb_in={}'.format(p.input.single_pdb),
                'pdb_out={}.pdb'.format(ens_list[1]), 'rotation_only=True'
            ]
        ],
        [
            True,
            [
                'pdb_in={}'.format(p.input.single_pdb),
                'pdb_out={}.pdb'.format(ens_list[2])
            ]
        ],
        [False, [p.input.ensemble_pdb]],  # Only ensemble no rbMotion
        [
            True,
            [
                'pdb_in={}'.format(p.input.ensemble_pdb),
                'pdb_out={}.pdb'.format(ens_list[4]), 'translation_only=True'
            ]
        ],
        [
            True,
            [
                'pdb_in={}'.format(p.input.ensemble_pdb),
                'pdb_out={}.pdb'.format(ens_list[5]), 'rotation_only=True'
            ]
        ],
        [
            True,
            [
                'pdb_in={}'.format(p.input.ensemble_pdb),
                'pdb_out={}.pdb'.format(ens_list[6])
            ]
        ]
    ]

    if p.params.calc_diff:
        batch_diffuse_calc(p=p,
                           ens_list=ens_list,
                           ens_command_list=ens_command_list,
                           l=l)
###########################################################################
#                       Create big slice image                            #
###########################################################################

    if p.params.merge_slices: merge_slices(ens_list=ens_list, l=l)

    ###########################################################################
    #                         Plot all B-Factors                              #
    ###########################################################################

    if p.params.plot_all_B_factors: plot_all_B_factors(ens_list=ens_list, l=l)

    ###########################################################################
    #                   Subtract all scattering stuff                         #
    ###########################################################################

    # All sums, per element [0] - [1] = [2]
    sum_list = [['rbMix', 'rbRot', 'rbTrans'], ['rbMix', 'rbTrans', 'rbRot'],
                ['rbTransEns', 'rbTrans', 'ens'],
                ['rbTransEns', 'ens', 'rbTrans'], ['rbRotEns', 'rbRot', 'ens'],
                ['rbRotEns', 'ens', 'rbRot'], ['rbMixEns', 'rbMix', 'ens'],
                ['rbMixEns', 'ens', 'rbMix']]
    # special sum: [0] - [1] - [2] = [3]
    special = ['rbMixEns', 'rbTrans', 'rbRot', 'ens']

    # List to be appended to ens_list for all R and CC value calculations
    outname_list = []
    # Loop over all summations
    for sum in sum_list:
        # File name
        outname = '{}_{}'.format(sum[0], sum[1])
        outname_list.append(outname)
        # Subtract sum[1] from sum[0]
        a = [
            'mtz_1={}_diffuse.mtz'.format(sum[0]),
            'mtz_2={}_diffuse.mtz'.format(sum[1]),
            'mtz_out={}_diffuse.mtz'.format(outname)
        ]
        additivity.run(args=a, l=l)
        # Create 2D slice and map from new mtz
        slice_and_make_map(nm=outname, l=l)
        # Combine slices to final png file
        os.system(
            'convert {}_slice.eps {}_slice.eps {}_slice.eps {}_slice.eps  +append {}_slice.png'
            .format(sum[0], sum[1], outname, sum[2], outname))


###########################################################################
#                   Calculate all R and CC values                         #
###########################################################################

# use mtz.correlation to calculate values
    l.close_log()