def test_double_quotes_and_underscore_data(self): cif_str = """data_test _symmetry_space_group_name_H-M "P -3 m 1" _thing '_annoying_data'""" cb = CifBlock.from_string(cif_str) self.assertEqual(cb["_symmetry_space_group_name_H-M"], "P -3 m 1") self.assertEqual(cb["_thing"], "_annoying_data") self.assertEqual(str(cb), cif_str.replace('"', "'"))
def test_double_quoted_data(self): cif_str = """data_test _thing ' '_annoying_data'' _other " "_more_annoying_data"" _more ' "even more" ' """ cb = CifBlock.from_string(cif_str) self.assertEqual(cb["_thing"], " '_annoying_data'") self.assertEqual(cb["_other"], ' "_more_annoying_data"') self.assertEqual(cb["_more"], ' "even more" ')
def test_nested_fake_multiline_quotes(self): cif_str = """data_test _thing ; long quotes ; still in the quote ; actually going to end now ;""" cb = CifBlock.from_string(cif_str) self.assertEqual(cb["_thing"], " long quotes ; still in the quote" " ; actually going to end now")
def test_to_string(self): with open(os.path.join(test_dir, 'Graphite.cif')) as f: s = f.read() c = CifBlock.from_string(s) cif_str_2 = str(CifBlock.from_string(str(c))) cif_str = """data_28417-ICSD _database_code_ICSD 28417 _audit_creation_date 1980-01-01 _audit_update_record 2003-04-01 _chemical_name_systematic Carbon _chemical_formula_structural C _chemical_formula_sum C1 _chemical_name_mineral 'Graphite, nitrated' _exptl_crystal_density_diffrn 1.36 _publ_section_title 'Order-disorder transformations in graphite nitrates' loop_ _citation_id _citation_journal_full _citation_year _citation_journal_volume _citation_page_first _citation_page_last _citation_journal_id_ASTM primary ; Proceedings of the Royal Society of London, Series A: Mathematical and Physical Sciences (76,1906-) ; 1966 291 324 339 PRLAAZ loop_ _publ_author_name 'Nixon, D.E.' 'Parry, G.S.' 'Ubbelohde, A.R.' _cell_length_a 2.46 _cell_length_b 2.46 _cell_length_c 33.45 _cell_angle_alpha 90. _cell_angle_beta 90. _cell_angle_gamma 120. _cell_volume 175.31 _cell_formula_units_Z 12 _symmetry_space_group_name_H-M 'R -3 m H' _symmetry_Int_Tables_number 166 loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x-y, -y, -z' 2 '-x, -x+y, -z' 3 'y, x, -z' 4 'x-y, x, -z' 5 'y, -x+y, -z' 6 '-x, -y, -z' 7 '-x+y, y, z' 8 'x, x-y, z' 9 '-y, -x, z' 10 '-x+y, -x, z' 11 '-y, x-y, z' 12 'x, y, z' 13 'x-y+2/3, -y+1/3, -z+1/3' 14 '-x+2/3, -x+y+1/3, -z+1/3' 15 'y+2/3, x+1/3, -z+1/3' 16 'x-y+2/3, x+1/3, -z+1/3' 17 'y+2/3, -x+y+1/3, -z+1/3' 18 '-x+2/3, -y+1/3, -z+1/3' 19 '-x+y+2/3, y+1/3, z+1/3' 20 'x+2/3, x-y+1/3, z+1/3' 21 '-y+2/3, -x+1/3, z+1/3' 22 '-x+y+2/3, -x+1/3, z+1/3' 23 '-y+2/3, x-y+1/3, z+1/3' 24 'x+2/3, y+1/3, z+1/3' 25 'x-y+1/3, -y+2/3, -z+2/3' 26 '-x+1/3, -x+y+2/3, -z+2/3' 27 'y+1/3, x+2/3, -z+2/3' 28 'x-y+1/3, x+2/3, -z+2/3' 29 'y+1/3, -x+y+2/3, -z+2/3' 30 '-x+1/3, -y+2/3, -z+2/3' 31 '-x+y+1/3, y+2/3, z+2/3' 32 'x+1/3, x-y+2/3, z+2/3' 33 '-y+1/3, -x+2/3, z+2/3' 34 '-x+y+1/3, -x+2/3, z+2/3' 35 '-y+1/3, x-y+2/3, z+2/3' 36 'x+1/3, y+2/3, z+2/3' loop_ _atom_type_symbol _atom_type_oxidation_number C0+ 0 loop_ _atom_site_label _atom_site_type_symbol _atom_site_symmetry_multiplicity _atom_site_Wyckoff_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_B_iso_or_equiv _atom_site_occupancy _atom_site_attached_hydrogens C1 C0+ 6 c 0 0 0.05 0. 1. 0 C2 C0+ 6 c 0 0 0.283 0. 1. 0""" for l1, l2, l3 in zip(str(c).split("\n"), cif_str.split("\n"), cif_str_2.split("\n")): self.assertEqual(l1.strip(), l2.strip()) self.assertEqual(l2.strip(), l3.strip())
def test_double_quotes(self): cif_str = 'data_test\n_symmetry_space_group_name_H-M "P -3 m 1"' cb = CifBlock.from_string(cif_str) self.assertEqual(cb["_symmetry_space_group_name_H-M"], "P -3 m 1") self.assertEqual(str(cb), cif_str.replace('"', "'") )