예제 #1
0
def add_r_int_value(cif: CifContainer, rint_p: Paragraph):
    reflns_number_total = cif['_reflns_number_total']
    reflns_av_R_equivalents = cif['_diffrn_reflns_av_R_equivalents']
    reflns_av_unetI = cif['_diffrn_reflns_av_unetI/netI']
    rint_p.add_run(this_or_quest(reflns_number_total) + '\n')
    rint_p.add_run('R').font.italic = True
    rint_p.add_run('int').font.subscript = True
    rint_p.add_run(' = ' + this_or_quest(reflns_av_R_equivalents) + '\n')
    rint_p.add_run('R').font.italic = True
    rint_p.add_run('sigma').font.subscript = True
    rint_p.add_run(' = ' + this_or_quest(reflns_av_unetI))
예제 #2
0
def add_r1sig_and_wr2full(cif, r2sig_p, rfull_p):
    ls_R_factor_gt = cif['_refine_ls_R_factor_gt']
    ls_wR_factor_gt = cif['_refine_ls_wR_factor_gt']
    ls_R_factor_all = cif['_refine_ls_R_factor_all']
    ls_wR_factor_ref = cif['_refine_ls_wR_factor_ref']
    r2sig_p.add_run('R').font.italic = True
    r2sig_p.add_run('1').font.subscript = True
    r2sig_p.add_run(' = ' + this_or_quest(ls_R_factor_gt))
    r2sig_p.add_run('\nw')
    r2sig_p.add_run('R').font.italic = True
    r2sig_p.add_run('2').font.subscript = True
    r2sig_p.add_run(' = ' + this_or_quest(ls_wR_factor_gt))
    rfull_p.add_run('R').font.italic = True
    rfull_p.add_run('1').font.subscript = True
    rfull_p.add_run(' = ' + this_or_quest(ls_R_factor_all))
    rfull_p.add_run('\nw')
    rfull_p.add_run('R').font.italic = True
    rfull_p.add_run('2').font.subscript = True
    rfull_p.add_run(' = ' + ls_wR_factor_ref)
예제 #3
0
    def make_templated_report(self, options: Options, file_obj: Path, output_filename: str, picfile: Path,
                              template_path: Path):
        cif = CifContainer(file_obj)
        tpl_doc = DocxTemplate(Path(__file__).parent.parent.joinpath(template_path))
        ba = BondsAndAngles(cif, without_h=options.without_h)
        t = TorsionAngles(cif, without_h=options.without_h)
        h = HydrogenBonds(cif)
        context = {'options'               : options,
                   # {'without_h': True, 'atoms_table': True, 'text': True, 'bonds_table': True},
                   'cif'                   : cif,
                   'space_group'           : self.space_group_subdoc(tpl_doc, cif),
                   'structure_figure'      : self.make_picture(options, picfile, tpl_doc),
                   'crystallization_method': remove_line_endings(retranslate_delimiter(
                       cif['_exptl_crystal_recrystallization_method'])) or '[No crystallization method given!]',
                   'sum_formula'           : self.format_sum_formula(cif['_chemical_formula_sum'].replace(" ", "")),
                   'itnum'                 : cif['_space_group_IT_number'],
                   'crystal_size'          : this_or_quest(cif['_exptl_crystal_size_min']) + timessym +
                                             this_or_quest(cif['_exptl_crystal_size_mid']) + timessym +
                                             this_or_quest(cif['_exptl_crystal_size_max']),
                   'crystal_colour'        : this_or_quest(cif['_exptl_crystal_colour']),
                   'crystal_shape'         : this_or_quest(cif['_exptl_crystal_description']),
                   'radiation'             : self.get_radiation(cif),
                   'wavelength'            : cif['_diffrn_radiation_wavelength'],
                   'theta_range'           : self.get_from_to_theta_range(cif),
                   'diffr_type'            : gstr(cif['_diffrn_measurement_device_type'])
                                             or '[No measurement device type given]',
                   'diffr_device'          : gstr(cif['_diffrn_measurement_device'])
                                             or '[No measurement device given]',
                   'diffr_source'          : gstr(cif['_diffrn_source']).strip('\n\r')
                                             or '[No radiation source given]',
                   'monochromator'         : gstr(cif['_diffrn_radiation_monochromator']) \
                                             or '[No monochromator type given]',
                   'detector'              : gstr(cif['_diffrn_detector_type']) \
                                             or '[No detector type given]',
                   'lowtemp_dev'           : gstr(cif['_olex2_diffrn_ambient_temperature_device']) \
                                             or '',
                   'index_ranges'          : self.hkl_index_limits(cif),
                   'indepentent_refl'      : this_or_quest(cif['_reflns_number_total']),
                   'r_int'                 : this_or_quest(cif['_diffrn_reflns_av_R_equivalents']),
                   'r_sigma'               : this_or_quest(cif['_diffrn_reflns_av_unetI/netI']),
                   'completeness'          : self.get_completeness(cif),
                   'theta_full'            : cif['_diffrn_reflns_theta_full'],
                   'data'                  : this_or_quest(cif['_refine_ls_number_reflns']),
                   'restraints'            : this_or_quest(cif['_refine_ls_number_restraints']),
                   'parameters'            : this_or_quest(cif['_refine_ls_number_parameters']),
                   'goof'                  : this_or_quest(cif['_refine_ls_goodness_of_fit_ref']),
                   'ls_R_factor_gt'        : this_or_quest(cif['_refine_ls_R_factor_gt']),
                   'ls_wR_factor_gt'       : this_or_quest(cif['_refine_ls_wR_factor_gt']),
                   'ls_R_factor_all'       : this_or_quest(cif['_refine_ls_R_factor_all']),
                   'ls_wR_factor_ref'      : this_or_quest(cif['_refine_ls_wR_factor_ref']),
                   'diff_dens_min'         : self.get_diff_density_min(cif).replace('-', minus_sign),
                   'diff_dens_max'         : self.get_diff_density_max(cif).replace('-', minus_sign),
                   'exti'                  : self.get_exti(cif),
                   'flack_x'               : self.get_flackx(cif),
                   'integration_progr'     : self.get_integration_program(cif),
                   'abstype'               : gstr(cif['_exptl_absorpt_correction_type']) or '??',
                   'abs_details'           : self.get_absortion_correction_program(cif),
                   'solution_method'       : self.solution_method(cif),
                   'solution_program'      : self.solution_program(cif),
                   'refinement_prog'       : self.refinement_prog(cif),
                   'atomic_coordinates'    : self.get_atomic_coordinates(cif),
                   'bonds'                 : ba.bonds,
                   'angles'                : ba.angles,
                   'ba_symminfo'           : ba.symminfo,
                   'torsions'              : t.torsion_angles,
                   'torsion_symminfo'      : t.symminfo,
                   'hydrogen_bonds'        : h.hydrogen_bonds,
                   'hydrogen_symminfo'     : h.symminfo,
                   'literature'            : self.literature
                   }

        # Filter definition for {{foobar|filter}} things:
        jinja_env = jinja2.Environment()
        jinja_env.filters['inv_article'] = get_inf_article
        tpl_doc.render(context, jinja_env=jinja_env, autoescape=True)
        tpl_doc.save(output_filename)
예제 #4
0
 def test_this_or_quest_zeropzero(self):
     self.assertEqual(0.0, this_or_quest(0.0))
예제 #5
0
 def test_this_or_quest_emptystring(self):
     self.assertEqual('?', this_or_quest(''))
예제 #6
0
 def test_this_or_quest_stringzero(self):
     self.assertEqual('0', this_or_quest('0'))
예제 #7
0
 def test_this_or_quest_None(self):
     self.assertEqual('?', this_or_quest(None))
예제 #8
0
 def test_this_or_quest_integer(self):
     self.assertEqual(12, this_or_quest(12))
예제 #9
0
def populate_main_table_values(main_table: Table, cif: CifContainer):
    """
    Fills the main table with residuals. Column, by column.
    """
    main_table.cell(0, 1).paragraphs[0].add_run(
        cif['_database_code_depnum_ccdc_archive'])
    # Set text for all usual cif keywords by a lookup table:
    add_regular_key_value_pairs(cif, main_table)
    # Now the special handling:
    formula_paragraph = main_table.cell(1, 1).paragraphs[0]
    sum_formula = cif['_chemical_formula_sum'].replace(" ", "")
    add_sum_formula(formula_paragraph, sum_formula)
    spgr_paragraph = main_table.cell(5, 1).paragraphs[0]
    space_group = cif.space_group
    try:
        it_number = str(cif.spgr_number)
    except AttributeError:
        it_number = ''
    format_space_group(spgr_paragraph, space_group, it_number)
    radiation_type = cif['_diffrn_radiation_type']
    radiation_wavelength = cif['_diffrn_radiation_wavelength']
    crystal_size_min = cif['_exptl_crystal_size_min']
    crystal_size_mid = cif['_exptl_crystal_size_mid']
    crystal_size_max = cif['_exptl_crystal_size_max']
    theta_min = cif['_diffrn_reflns_theta_min']
    theta_max = cif['_diffrn_reflns_theta_max']
    limit_h_min = cif['_diffrn_reflns_limit_h_min']
    limit_h_max = cif['_diffrn_reflns_limit_h_max']
    limit_k_min = cif['_diffrn_reflns_limit_k_min']
    limit_k_max = cif['_diffrn_reflns_limit_k_max']
    limit_l_min = cif['_diffrn_reflns_limit_l_min']
    limit_l_max = cif['_diffrn_reflns_limit_l_max']
    ls_number_reflns = cif['_refine_ls_number_reflns']
    ls_number_restraints = cif['_refine_ls_number_restraints']
    ls_number_parameters = cif['_refine_ls_number_parameters']
    goof = cif['_refine_ls_goodness_of_fit_ref']
    try:
        completeness = "{0:.1f} %".format(
            round(float(cif['_diffrn_measured_fraction_theta_full']) * 100, 1))
    except ValueError:
        completeness = '?'
    try:
        diff_density_min = "{0:.2f}".format(
            round(float(cif['_refine_diff_density_min']), 2))
    except ValueError:
        diff_density_min = '?'
    try:
        diff_density_max = "{0:.2f}".format(
            round(float(cif['_refine_diff_density_max']), 2))
    except ValueError:
        diff_density_max = '?'

    # now prepare & write all the concatenated & derived cell contents:
    main_table.cell(17, 1).text = this_or_quest(crystal_size_max) + timessym + \
                                  this_or_quest(crystal_size_mid) + timessym + \
                                  this_or_quest(crystal_size_min)
    wavelength = str(' ({} ='.format(lambdasym) +
                     this_or_quest(radiation_wavelength) +
                     '{}{})'.format(protected_space, angstrom)).replace(
                         ' ', '')
    # radtype: ('Mo', 'K', '\\a')
    radtype = format_radiation(radiation_type)
    radrun = main_table.cell(20, 1).paragraphs[0]
    # radiation type e.g. Mo:
    radrun.add_run(radtype[0])
    # K line:
    radrunita = radrun.add_run(radtype[1])
    radrunita.font.italic = True
    alpha = radrun.add_run(radtype[2])
    alpha.font.italic = True
    alpha.font.subscript = True
    # wavelength lambda:
    radrun.add_run(' ' + wavelength)
    try:
        d_max = ' ({:.2f}{}{})'.format(
            float(radiation_wavelength) / (2 * sin(radians(float(theta_max)))),
            protected_space, angstrom)
        # 2theta range:
        main_table.cell(21, 1).text = "{:.2f} to {:.2f}{}".format(
            2 * float(theta_min), 2 * float(theta_max), d_max)
    except ValueError:
        main_table.cell(21, 1).text = '? to ?'
    main_table.cell(22, 1).text = limit_h_min + ' {} h {} '.format(less_or_equal, less_or_equal) + limit_h_max + '\n' \
                                  + limit_k_min + ' {} k {} '.format(less_or_equal, less_or_equal) + limit_k_max + '\n' \
                                  + limit_l_min + ' {} l {} '.format(less_or_equal, less_or_equal) + limit_l_max
    rint_p = main_table.cell(24, 1).paragraphs[0]
    add_r_int_value(cif, rint_p)
    main_table.cell(25, 1).paragraphs[0].add_run(completeness)
    main_table.cell(26, 1).text = this_or_quest(ls_number_reflns) + '/' \
                                  + this_or_quest(ls_number_restraints) + '/' \
                                  + this_or_quest(ls_number_parameters)
    main_table.cell(27, 1).paragraphs[0].add_run(goof)
    r1sig_p = main_table.cell(28, 1).paragraphs[0]
    rfull_p = main_table.cell(29, 1).paragraphs[0]
    add_r1sig_and_wr2full(cif, r1sig_p, rfull_p)
    main_table.cell(30, 1).text = diff_density_max + '/' + diff_density_min
    if not cif.is_centrosymm:
        main_table.cell(31,
                        1).text = cif['_refine_ls_abs_structure_Flack'] or '?'
    exti = cif['_refine_ls_extinction_coef']
    if exti not in ['.', "'.'", '?', '']:
        num = len(main_table.columns[0].cells)
        main_table.columns[1].cells[num - 1].text = exti