Esempio n. 1
0
 def spgr_number(self) -> int:
     if self['_space_group_IT_number'] and isnumeric(
             self['_space_group_IT_number']):
         return int(self['_space_group_IT_number'])
     elif self['_symmetry_Int_Tables_number'] and isnumeric(
             self['_symmetry_Int_Tables_number']):
         return int(self['_symmetry_Int_Tables_number'])
     else:
         return self.spgr_number_from_symmops
Esempio n. 2
0
 def _general_format_out(self):
     """
     Writes out a python file with a dictionary of a general format definition of all space groups.
     """
     Path('testing2.py').unlink(missing_ok=True)
     htxt = 'spgrps = {\n'
     for space_group_obj in gemmi.spacegroup_table():
         space_group_obj: gemmi.SpaceGroup
         html = []
         splitted_spgr = space_group_obj.xhm().split(' ')
         if space_group_obj.short_name() == self._myshort(space_group_obj):
             splitted_spgr = self.remove_setting(space_group_obj)
         html.append("    '{}'         : (\n        (('{}', 'italic'),\n".format(space_group_obj.xhm(),
                                                                                 splitted_spgr.pop(0)))
         if space_group_obj.short_name() == 'P21212(a)':
             self.handle_p21212a_specially(html)
         else:
             for num, chars in enumerate(splitted_spgr):
                 if ':' in chars:
                     chars, append = chars.split(':')
                     if chars.startswith('-'):
                         html.append("            ({}, 'overline'),\n".format(chars[-1]))
                     else:
                         self._italize_chars_format(chars, html)
                     self._italize_chars_format(':' + append, html)
                     continue
                 if len(chars) == 1:
                     if isnumeric(chars):
                         html.append("         ('{}', 'regular'),\n".format(chars))
                     else:
                         html.append("         ('{}', 'italic'),\n".format(chars))
                 if len(chars) == 2 and self._get_screw(chars):
                     html.append(self._get_screw_format(chars))
                 if len(chars) == 2 and not self._get_screw(chars):
                     if chars.startswith('-'):
                         html.append("         ('{}', 'overline'),\n".format(chars[-1]))
                     else:
                         self._italize_chars_format(chars, html)
                 if len(chars) > 2:
                     txt = []
                     if self._get_screw(chars[:2]):
                         html.append(self._get_screw_format(chars[:2]))
                         chars = chars[:]
                     for chars in chars:
                         self._make_italic_format(chars, txt)
                     html.append("{}".format(''.join(txt)))
         htxt = htxt + ''.join(html) \
                + "         ), {{'itnumber': {}, 'crystal_system': '{}', " \
                  "'short-hm': '{}', 'is_reference': {}}},\n    ),\n".format(space_group_obj.number,
                                                                             space_group_obj.crystal_system_str(),
                                                                             space_group_obj.short_name(),
                                                                             space_group_obj.is_reference_setting(),
                                                                             )
     Path('testing2.py').write_text(htxt + '\n}')
Esempio n. 3
0
 def format_sum_formula(self, sum_formula: str) -> RichText:
     sum_formula_group = [''.join(x[1]) for x in itertools.groupby(sum_formula, lambda x: x.isalpha())]
     richtext = RichText('')
     if sum_formula_group:
         for _, word in enumerate(sum_formula_group):
             if isnumeric(word):
                 richtext.add(word, subscript=True)
             else:
                 richtext.add(word)
         return richtext
     else:
         return RichText('No sum formula')
Esempio n. 4
0
def add_sum_formula(formula_paragraph, sum_formula):
    if sum_formula:
        sum_formula_group = [
            ''.join(x[1])
            for x in it.groupby(sum_formula, lambda x: x.isalpha())
        ]
        for _, word in enumerate(sum_formula_group):
            formrunsub = formula_paragraph.add_run(word)
            if isnumeric(word):
                formrunsub.font.subscript = True
    else:
        formula_paragraph.add_run('no sum formula')
Esempio n. 5
0
 def milliamps(self) -> float:
     tmp = self.header['SOURCEM']
     if isnumeric(tmp):
         return round(float(tmp), 2)
     else:
         return 0.0
Esempio n. 6
0
 def kilovolts(self) -> float:
     tmp = self.header['SOURCEK']
     if isnumeric(tmp):
         return round(float(tmp), 2)
     else:
         return 0.0
Esempio n. 7
0
 def test_isnumeric_false(self):
     self.assertEqual(False, isnumeric('foo'))
     self.assertEqual(False, isnumeric('!0'))
Esempio n. 8
0
 def test_isnumeric_true(self):
     self.assertEqual(True, isnumeric('1.234'))
     self.assertEqual(True, isnumeric('234'))
     self.assertEqual(True, isnumeric('0'))
     self.assertEqual(True, isnumeric('0.234(12)'))
     self.assertEqual(True, isnumeric('0.234(?)'))