def test_reading(self): doc = gemmi.cif.read(full_path('r5wkdsf.ent')) rblock = gemmi.as_refln_blocks(doc)[0] self.assertEqual(rblock.spacegroup.hm, 'C 1 2 1') size = rblock.get_size_for_hkl() fft_test(self, rblock, 'pdbx_FWT', 'pdbx_PHWT', size)
def test_scaling(self): doc = gemmi.cif.read(full_path('r5wkdsf.ent')) rblock = gemmi.as_refln_blocks(doc)[0] fobs_data = rblock.get_value_sigma('F_meas_au', 'F_meas_sigma_au') if numpy: self.assertEqual(fobs_data.value_array.shape, (367, )) # without mask fc_data = rblock.get_f_phi('F_calc_au', 'phase_calc') scaling = gemmi.Scaling(fc_data.unit_cell, fc_data.spacegroup) scaling.prepare_points(fc_data, fobs_data) scaling.fit_isotropic_b_approximately() scaling.fit_parameters() #print(scaling.k_overall, scaling.b_overall) scaling.scale_data(fc_data)
def gemmi_sf2map(self, sf_mmcif_in, map_out, f_column, phi_column): """ converts input mmCIF file map coefficients to map :param sf_mmcif_in: mmCIF structure factor input file :param map_out: map output file :param f_column: F column :param phi_column: PHI column :return: True if worked, False if failed """ st = gemmi.read_structure(self.coord_path) fbox = st.calculate_fractional_box(margin=5) if sf_mmcif_in: if os.path.exists(sf_mmcif_in): doc = gemmi.cif.read(sf_mmcif_in) rblocks = gemmi.as_refln_blocks(doc) if ( f_column in rblocks[0].column_labels() and phi_column in rblocks[0].column_labels() ): ccp4 = gemmi.Ccp4Map() ccp4.grid = rblocks[0].transform_f_phi_to_map(f_column, phi_column) ccp4.update_ccp4_header(2, True) ccp4.set_extent(fbox) ccp4.write_ccp4_map(map_out) if os.path.exists(map_out): return True else: logging.error("output map file {} missing".format(map_out)) else: logging.error( "{} {} columns not found in mmCIF {}".format( f_column, phi_column, sf_mmcif_in ) ) else: logging.error("cannot find input file {}".format(sf_mmcif_in)) # command = "{} sf2map -f {} -p {} {} {}".format(gemmi_path, f_column, phi_column, mmcif_in, map_out) # return self.run_command(command=command, output_file=map_out) logging.error("converting {} to {} failed".format(sf_mmcif_in, map_out)) return False
import pandas from matplotlib import pyplot MTZ_PATH = 'tests/5wkd_phases.mtz.gz' SFCIF_PATH = 'tests/r5wkdsf.ent' # make DataFrame from MTZ file mtz = gemmi.read_mtz_file(MTZ_PATH) mtz_data = numpy.array(mtz, copy=False) mtz_df = pandas.DataFrame(data=mtz_data, columns=mtz.column_labels()) # (optional) store Miller indices as integers mtz_df = mtz_df.astype({label: 'int32' for label in 'HKL'}) # make DataFrame from mmCIF file cif_doc = gemmi.cif.read(SFCIF_PATH) rblock = gemmi.as_refln_blocks(cif_doc)[0] cif_df = pandas.DataFrame(data=rblock.make_index_array(), columns=['H', 'K', 'L']) cif_df['F_meas_au'] = rblock.make_float_array('F_meas_au') cif_df['d'] = rblock.make_d_array() # merge DataFrames df = pandas.merge(mtz_df, cif_df, on=['H', 'K', 'L']) # plot FP from MTZ as a function of F_meas_au from mmCIF pyplot.rc('font', size=8) pyplot.figure(figsize=(2, 2)) pyplot.scatter(x=df['F_meas_au'], y=df['FP'], marker=',', s=1, linewidths=0) pyplot.xlim(xmin=0) pyplot.ylim(ymin=0) pyplot.show()
#!/usr/bin/env python # Read SF-mmCIF file and plot I/sigma as a function of 1/d^2. import sys from matplotlib import pyplot import gemmi for path in sys.argv[1:]: doc = gemmi.cif.read(path) rblock = gemmi.as_refln_blocks(doc)[0] intensity = rblock.make_float_array('intensity_meas') sigma = rblock.make_float_array('intensity_sigma') x = rblock.make_1_d2_array() y = intensity / sigma pyplot.figure(figsize=(5,5)) pyplot.hexbin(x, y, gridsize=70, bins='log', cmap='gnuplot2') pyplot.show()