Debian Codegraph @

src/Programs/syd_example.py

raw symbols SCIP
1 # Example python program: as close to ciftbx as we can make it
2
3 from __future__ import print_function
4 from CifFile import CifDic, ValidCifFile, ValidCifError, CifError #import definitions
5 from CifFile import get_number_with_esd
6 import sys #to finish early
7
8 # change the following as required by your installation
9 test_dic = "../dictionaries/cif_core.dic"
10 test_data = "../drel/testing/data/nacltest.cif"
11 # open our dictionary
12 try:
13 my_dict = CifDic(test_dic)
14 except IOError:
15 print("Cannot open " + test_dic)
16 sys.exit()
17
18 # open our CIF
19 try:
20 my_cif = ValidCifFile(datasource=test_data,dic=my_dict)#read our CIF file
21 except IOError:
22 print("Cannot open " + test_data)
23 sys.exit()
24 except ValidCifError as error_message:
25 print(test_data + " failed validity checks:")
26 print(error_message)
27 sys.exit()
28 except CifError as error_message:
29 print("Syntax error in " + test_data +":")
30 print(error_message)
31 sys.exit()
32
33 # get the first blockname
34 my_data_block = my_cif.first_block()
35
36 # get some data
37 cela,siga = get_number_with_esd(my_data_block["_cell_length_a"])#cell dimension
38 name = my_data_block["_symmetry_cell_setting"] #cell setting
39
40 # get a random data name which is not one of the above
41 allnames = my_data_block.keys()
42 allnames.remove("_cell_length_a")
43 allnames.remove("_symmetry_cell_setting")
44 data = my_data_block[allnames[0]]
45
46 # to print, don't need to check type
47 print("%s %s" % (allnames[0],data))
48
49 # loop atom sites
50 names = my_data_block["_atom_site_label"]
51 xsxs = my_data_block["_atom_site_fract_x"]
52 as_numbers = map(get_number_with_esd,xsxs)
53 processed = zip(names,as_numbers)
54 for label, data in processed:
55 print("%s %f " % (label,data[0]))