rename HklPseudoAxisEngine -> HklEngine
[hkl.git] / Documentation / sphinx / source / bindings / python.py
blob9acf0cc2c151edaeeee10042576f56f4b3e9db30
1 #!/bin/env python
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 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))
30 detector.idx = 1
32 config = Hkl.geometry_factory_get_config_from_type(
33 Hkl.GeometryType.KAPPA6C)
34 geometry = Hkl.Geometry.factory_newv(config, [math.radians(50.)])
35 values_w = [0., 30., 0., 0., 0., 60.]
36 geometry.set_axes_values_unit(values_w)
37 axes_names = [axis.parameter.name for axis in geometry.axes()]
38 print config.name, "diffractometer has", geometry.len,\
39 "axes : ", axes_names
40 print values_w
42 sample = Hkl.Sample.new("toto", Hkl.SampleType.MONOCRYSTAL)
43 sample.set_lattice(1.54, 1.54, 1.54,
44 math.radians(90.0),
45 math.radians(90.0),
46 math.radians(90.))
48 # compute all the pseudo axes managed by all engines
49 engines = Hkl.EngineList.factory(config)
50 engines.init(geometry, detector, sample)
51 engines.get()
53 # get the hkl engine and do a computation
54 hkl = engines.get_by_name("hkl")
55 values = hkl.get_values_unit()
56 print "read : ", values
58 # set the hkl engine and get the results
59 for _ in range(100):
60 try:
61 print
62 hkl.set_values_unit(values)
63 print hkl.get_values_unit()
65 print("idx".center(15)),
66 for name in axes_names:
67 print("{}".format(name.center(15))),
68 print
70 for i, item in enumerate(engines.geometries.items()):
71 read = item.geometry.get_axes_values_unit()
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, err:
77 print values, err
78 values[1] += .01