[binoculars-ng] added q_scannumber and tth_scannumber projections
[hkl.git] / Documentation / sphinx / source / bindings / python.py
blobfd7b2cb6b407ed334cc0f5a515e6ab7ba3243630
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """
4 This file is part of the hkl library.
6 The hkl library is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 The hkl library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
19 Copyright (C) 2003-2012, 2019 Synchrotron SOLEIL
20 L'Orme des Merisiers Saint-Aubin
21 BP 48 91192 GIF-sur-YVETTE CEDEX
22 Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
23 """
25 import math
26 from gi.repository import GLib
27 from gi.repository import Hkl
29 detector = Hkl.Detector.factory_new(Hkl.DetectorType(0))
31 factory = Hkl.factories()['K6C']
32 geometry = factory.create_new_geometry()
33 values_w = [0., 30., 0., 0., 0., 60.]
34 geometry.axis_values_set(values_w, Hkl.UnitEnum.USER)
35 axis_names = geometry.axis_names_get()
36 print(geometry.name_get(), "diffractometer has", len(axis_names),\
37 "axes : ", axis_names)
38 print(values_w)
40 sample = Hkl.Sample.new("toto")
41 lattice = Hkl.Lattice.new(1.54, 1.54, 1.54,
42 math.radians(90.0),
43 math.radians(90.0),
44 math.radians(90.))
45 sample.lattice_set(lattice)
47 # compute all the pseudo axes managed by all engines
48 engines = factory.create_new_engine_list()
49 engines.init(geometry, detector, sample)
50 engines.get()
52 # get the hkl engine and do a computation
53 hkl = engines.engine_get_by_name("hkl")
54 values = hkl.pseudo_axis_values_get(Hkl.UnitEnum.USER)
55 print("read : ", values)
57 # set the hkl engine and get the results
58 for _ in range(100):
59 try:
60 print()
61 solutions = hkl.pseudo_axis_values_set(values,
62 Hkl.UnitEnum.USER)
63 print(hkl.pseudo_axis_values_get(Hkl.UnitEnum.USER))
65 print("idx".center(15)),
66 for name in axis_names:
67 print("{}".format(name.center(15))),
68 print()
70 for i, item in enumerate(solutions.items()):
71 read = item.geometry_get().axis_values_get(Hkl.UnitEnum.USER)
72 print("{}".format(repr(i).center(15))),
73 for value in read:
74 print("{}".format(repr(value)[:15].center(15))),
75 print()
76 except GLib.GError as err:
77 print(values, err)
78 values[1] += .01