def test_table(self): for sg in gemmi.spacegroup_table(): if sg.ccp4 != 0: self.assertEqual(sg.ccp4 % 1000, sg.number) if sg.operations().is_centric(): self.assertEqual(sg.laue_str(), sg.point_group_hm()) else: self.assertNotEqual(sg.laue_str(), sg.point_group_hm()) if sgtbx: hall = sg.hall.encode() cctbx_sg = sgtbx.space_group(hall) cctbx_info = sgtbx.space_group_info(group=cctbx_sg) self.assertEqual(sg.is_reference_setting(), cctbx_info.is_reference_setting()) #to_ref = cctbx_info.change_of_basis_op_to_reference_setting() #from_ref = '%s' % cob_to_ref.inverse().c() c2p_sg = gemmi.Op(cctbx_sg.z2p_op().c().inverse().as_xyz()) self.assertEqual(sg.centred_to_primitive(), c2p_sg) ops = gemmi.get_spacegroup_reference_setting(sg.number).operations() ops.change_basis_forward(sg.basisop) self.assertEqual(ops, sg.operations()) itb = gemmi.spacegroup_table_itb() if sgtbx: for s in sgtbx.space_group_symbol_iterator(): self.assertEqual(s.hall().strip(), next(itb).hall) with self.assertRaises(StopIteration): next(itb)
def wite_xml(): sp = SpaceGroups() txt = '' for s in gemmi.spacegroup_table(): print(s.number, s.short_name()) p = sp.to_mathml(s.xhm()) print(p) txt = txt + '{} {}\n'.format(s.number, s.short_name()) txt = txt + p + '\n' Path('testing_xml.html').write_text(txt)
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}')
def test_table(self): for sg in gemmi.spacegroup_table(): if sg.ccp4 != 0: self.assertEqual(sg.ccp4 % 1000, sg.number) if sg.operations().is_centric(): self.assertEqual(sg.laue_str(), sg.point_group_hm()) else: self.assertNotEqual(sg.laue_str(), sg.point_group_hm()) if sgtbx: hall = sg.hall.encode() cctbx_sg = sgtbx.space_group(hall) cctbx_info = sgtbx.space_group_info(group=cctbx_sg) self.assertEqual(sg.is_reference_setting(), cctbx_info.is_reference_setting())
def test_table(self): for sg in gemmi.spacegroup_table(): if sg.ccp4 != 0: self.assertEqual(sg.ccp4 % 1000, sg.number) if sg.operations().is_centric(): self.assertEqual(sg.laue_str(), sg.point_group_hm()) else: self.assertNotEqual(sg.laue_str(), sg.point_group_hm()) if sgtbx: hall = sg.hall.encode() cctbx_sg = sgtbx.space_group(hall) cctbx_info = sgtbx.space_group_info(group=cctbx_sg) self.assertEqual(sg.is_reference_setting(), cctbx_info.is_reference_setting()) #to_ref = cctbx_info.change_of_basis_op_to_reference_setting() #from_ref = '%s' % cob_to_ref.inverse().c() ops = gemmi.get_spacegroup_reference_setting(sg.number).operations() ops.change_basis(sg.basisop) self.assertEqual(ops, sg.operations())
def write_html(): s = SpaceGroups() txt = '' for sp in gemmi.spacegroup_table(): txt = txt + s.to_html(sp.xhm()) + '<br>\n' Path('testing.html').write_text(txt)
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 s in gemmi.spacegroup_table(): s: gemmi.SpaceGroup html = [] splitted_s = s.xhm().split(' ') if s.short_name() == self._myshort(s): splitted_s = [ x for x in s.xhm().split(':')[0].split(' ') if x != '1' ] else: pass html.append( " '{}' : (\n (('{}', 'italic'),\n".format( s.xhm(), splitted_s.pop(0))) if s.short_name() == 'P21212(a)': # This one is differently formated as the others in gemmi: html.append( "('2', 'regular'),\n ('1' ,'sub'),\n ('2', 'regular'),\n ('1', 'sub'),\n ('2', 'regular')," "\n ('1', 'sub'),\n ('2(a)', 'regular'),\n") else: for num, c in enumerate(splitted_s): if ':' in c: c, append = c.split(':') if c.startswith('-'): html.append( " ({}, 'overline'),\n".format( c[-1])) else: self._italize_chars_format(c, html) self._italize_chars_format(':' + append, html) continue if len(c) == 1: if isnumeric(c): html.append( " ('{}', 'regular'),\n".format(c)) else: html.append( " ('{}', 'italic'),\n".format(c)) if len(c) == 2 and self._get_screw(c): html.append(self._get_screw_format(c)) if len(c) == 2 and not self._get_screw(c): if c.startswith('-'): html.append( " ('{}', 'overline'),\n".format(c[-1])) else: self._italize_chars_format(c, html) if len(c) > 2: txt = [] if self._get_screw(c[:2]): html.append(self._get_screw_format(c[:2])) c = c[:] for char in c: self._make_italic_format(char, txt) html.append("{}".format(''.join(txt))) htxt = htxt + ''.join(html) \ + " ), {{'itnumber': {}, 'crystal_system': '{}', " \ "'short-hm': '{}', 'is_reference': {}}},\n ),\n".format(s.number, s.crystal_system_str(), s.short_name(), s.is_reference_setting(), ) Path('testing2.py').write_text(htxt + '\n}')
def test_with_sgtbx(self): if sgtbx is None: return for s in gemmi.spacegroup_table(): self.compare_hall_symops_with_sgtbx(s.hall.encode()) self.compare_hall_symops_with_sgtbx('C -4 -2b', existing_group=False)
def test_table(self): for sg in gemmi.spacegroup_table(): if sg.ccp4 != 0: self.assertEqual(sg.ccp4 % 1000, sg.number)