This commit is contained in:
@@ -16,10 +16,12 @@
|
||||
###################################################################################################
|
||||
|
||||
#1- Create a MontorGroup with the diffractometer motors
|
||||
# e.g named 'sixc', containing mu, delta, gam, eta, chi, phi motors
|
||||
# e.g. 'sixc', containing mu, delta, gam, eta, chi, phi motors
|
||||
# or 'fivec', containing delta, gam, eta, chi, phi motors
|
||||
# or 'fourc', containing delta, eta, chi, phi motors
|
||||
#2- Create positioner to read/set the energy in kEv, e.g. named 'en'
|
||||
#3- Execute: run("diffutils")
|
||||
#4- Execute: setup_sixc(sixc, en)
|
||||
#4- Execute: setup_diff(sixc, en)
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
@@ -29,15 +31,15 @@ import traceback
|
||||
import Jama.Matrix
|
||||
diffcalc_path = os.path.abspath(get_context().setup.expandPath("{script}/Lib/diffcalc"))
|
||||
if not diffcalc_path in sys.path:
|
||||
sys.path.append('/Users/gobbo_a/dev/pshell/config/home/script/Lib/diffcalc')
|
||||
sys.path.append(diffcalc_path)
|
||||
|
||||
import diffcalc
|
||||
from diffcalc import settings
|
||||
from diffcalc.hkl.you.geometry import SixCircle
|
||||
from diffcalc.hkl.you.geometry import SixCircle, FiveCircle, FourCircle
|
||||
from diffcalc.hardware import HardwareAdapter
|
||||
from diffcalc.ub.persistence import UbCalculationNonPersister
|
||||
from diffcalc.gdasupport.minigda.scannable import *
|
||||
from diffcalc.gdasupport.minigda import command
|
||||
from diffcalc.gdasupport.minigda.scannable import ScannableBase, ScannableGroup
|
||||
#from diffcalc.gdasupport.minigda import command
|
||||
from diffcalc.hardware import HardwareAdapter
|
||||
|
||||
|
||||
@@ -54,7 +56,6 @@ import ch.psi.pshell.device.Register as Register
|
||||
# Device mapping to difcalc
|
||||
###################################################################################################
|
||||
class PositionerScannable(ScannableBase):
|
||||
|
||||
def __init__(self, positioner):
|
||||
self.positioner = positioner
|
||||
self.name = positioner.name
|
||||
@@ -79,15 +80,31 @@ class PositionerScannable(ScannableBase):
|
||||
class PositionerScannableGroup(ScannableGroup):
|
||||
def __init__(self, name, motors):
|
||||
self.name = name
|
||||
[mu, delta, gam, eta, chi, phi] = motors
|
||||
self.mu = PositionerScannable(mu)
|
||||
self.delta = PositionerScannable(delta)
|
||||
self.gam = PositionerScannable(gam)
|
||||
self.eta = PositionerScannable(eta)
|
||||
self.chi = PositionerScannable(chi)
|
||||
self.phi = PositionerScannable(phi)
|
||||
ScannableGroup.__init__(self, self.name, [self.mu, self.delta, self.gam, self.eta, self.chi, self.phi])
|
||||
|
||||
if len(motors)==6:
|
||||
[mu, delta, gam, eta, chi, phi] = motors
|
||||
self.mu = PositionerScannable(mu)
|
||||
self.delta = PositionerScannable(delta)
|
||||
self.gam = PositionerScannable(gam)
|
||||
self.eta = PositionerScannable(eta)
|
||||
self.chi = PositionerScannable(chi)
|
||||
self.phi = PositionerScannable(phi)
|
||||
ScannableGroup.__init__(self, self.name, [self.mu, self.delta, self.gam, self.eta, self.chi, self.phi])
|
||||
elif len(motors)==5:
|
||||
[delta, gam, eta, chi, phi] = motors
|
||||
self.delta = PositionerScannable(delta)
|
||||
self.gam = PositionerScannable(gam)
|
||||
self.eta = PositionerScannable(eta)
|
||||
self.chi = PositionerScannable(chi)
|
||||
self.phi = PositionerScannable(phi)
|
||||
ScannableGroup.__init__(self, self.name, [self.delta, self.gam, self.eta, self.chi, self.phi])
|
||||
elif len(motors)==4:
|
||||
[delta, eta, chi, phi] = motors
|
||||
self.delta = PositionerScannable(delta)
|
||||
self.eta = PositionerScannable(eta)
|
||||
self.chi = PositionerScannable(chi)
|
||||
self.phi = PositionerScannable(phi)
|
||||
ScannableGroup.__init__(self, self.name, [self.delta, self.eta, self.chi, self.phi])
|
||||
|
||||
class MotorGroupScannable(PositionerScannableGroup):
|
||||
def __init__(self, motor_group):
|
||||
self.motor_group = motor_group
|
||||
@@ -125,10 +142,10 @@ class ScannableAdapter(HardwareAdapter):
|
||||
|
||||
class MotorGroupAdapter(ScannableAdapter):
|
||||
def __init__(self, diffractometer, energy, energy_multiplier_to_kev=1):
|
||||
self.sixc = MotorGroupScannable(sixc)
|
||||
self.en = PositionerScannable(en)
|
||||
self.en.level = 3
|
||||
ScannableAdapter.__init__(self, self.sixc, self.en, energy_multiplier_to_kev)
|
||||
self.diffractometer = MotorGroupScannable(diffractometer)
|
||||
self.energy = PositionerScannable(energy)
|
||||
self.energy.level = 3
|
||||
ScannableAdapter.__init__(self, self.diffractometer, self.energy, energy_multiplier_to_kev)
|
||||
|
||||
class Wavelength(RegisterBase):
|
||||
def doRead(self):
|
||||
@@ -205,15 +222,30 @@ class HklGroup(RegisterBase, Register.RegisterArray):
|
||||
###################################################################################################
|
||||
you = None
|
||||
dc, ub, hardware, hkl = None, None, None, None
|
||||
#en in kev
|
||||
def setup_sixc(sixc, en):
|
||||
global you, dc, ub, hardware, hkl
|
||||
_motor_group = None
|
||||
def setup_diff(diffractometer, energy):
|
||||
"""
|
||||
diffractometer: Motor group containing:
|
||||
- mu, delta, gam, eta, chi, phi (six circle) or
|
||||
- delta, gam, eta, chi, phi (ficve circle) or
|
||||
- delta, eta, chi, phi (four circle)
|
||||
energy: Positioner having energy in kev
|
||||
"""
|
||||
global you, dc, ub, hardware, hkl, _motor_group
|
||||
_motor_group = diffractometer
|
||||
you =None
|
||||
settings.hardware = MotorGroupAdapter(sixc, en)
|
||||
settings.geometry = SixCircle()
|
||||
if len(diffractometer.motors) == 6:
|
||||
settings.geometry = SixCircle()
|
||||
elif len(diffractometer.motors) == 5:
|
||||
settings.geometry = FiveCircle()
|
||||
elif len(diffractometer.motors) == 4:
|
||||
settings.geometry = FourCircle()
|
||||
else:
|
||||
raise Exception("Invalid motor group")
|
||||
settings.hardware = MotorGroupAdapter(diffractometer, energy)
|
||||
settings.ubcalc_persister = UbCalculationNonPersister()
|
||||
settings.axes_scannable_group = settings.hardware.sixc
|
||||
settings.energy_scannable = settings.hardware.en
|
||||
settings.axes_scannable_group = settings.hardware.diffractometer
|
||||
settings.energy_scannable = settings.hardware.energy
|
||||
settings.ubcalc_strategy = diffcalc.hkl.you.calc.YouUbCalcStrategy()
|
||||
settings.angles_to_hkl_function = diffcalc.hkl.you.calc.youAnglesToHkl
|
||||
from diffcalc.gdasupport import you
|
||||
@@ -242,10 +274,13 @@ def print_axis_setup():
|
||||
# Acceess functions
|
||||
###################################################################################################
|
||||
def get_diff():
|
||||
return settings.hardware.sixc
|
||||
return settings.hardware.diffractometer
|
||||
|
||||
def get_en():
|
||||
return settings.hardware.en
|
||||
return settings.hardware.energy
|
||||
|
||||
def get_motor_group():
|
||||
return _motor_group
|
||||
|
||||
def get_wl():
|
||||
return you.wl
|
||||
@@ -302,7 +337,11 @@ def hklscan(vector, readables,latency = 0.0, passes = 1, **pars):
|
||||
for pos in vector:
|
||||
#print "Writing ", pos
|
||||
hkl_group.write(pos)
|
||||
time.sleep(1.0)
|
||||
time.sleep(0.1) #Make sure is busy
|
||||
get_motor_group().update()
|
||||
get_motor_group().waitReady(-1)
|
||||
time.sleep(latency)
|
||||
hkl_group.update()
|
||||
scan.append ([h.take(), k.take(), l.take()], [h.getPosition(), k.getPosition(), l.getPosition()], [readable.read() for readable in readables ])
|
||||
finally:
|
||||
scan.end()
|
||||
|
||||
86
script/diffcalc/testfivec.py
Normal file
86
script/diffcalc/testfivec.py
Normal file
@@ -0,0 +1,86 @@
|
||||
en.move(20.0)
|
||||
delta.config.maxSpeed = 50.0
|
||||
delta.speed = 50.0
|
||||
delta.move(1.0)
|
||||
|
||||
run("diffcalc/diffutils")
|
||||
###################################################################################################\
|
||||
#Setup
|
||||
###################################################################################################
|
||||
|
||||
setup_diff(fivec, en)
|
||||
# Set some limits
|
||||
setup_axis('gam', 0, 179)
|
||||
setup_axis('delta', 0, 179)
|
||||
setup_axis('delta', min=0)
|
||||
setup_axis('phi', cut=-180.0)
|
||||
|
||||
print_axis_setup()
|
||||
|
||||
###################################################################################################\
|
||||
#Orientation
|
||||
###################################################################################################
|
||||
help(ub.ub)
|
||||
ub.listub()
|
||||
|
||||
# Create a new ub calculation and set lattice parameters
|
||||
ub.newub('test')
|
||||
ub.setlat('cubic', 1, 1, 1, 90, 90, 90)
|
||||
|
||||
# Add 1st reflection (demonstrating the hardware adapter)
|
||||
settings.hardware.wavelength = 1
|
||||
ub.c2th([1, 0, 0]) # energy from hardware
|
||||
settings.hardware.position = 0, 60, 0, 30, 0, 0
|
||||
ub.addref([1, 0, 0])# energy and position from hardware
|
||||
|
||||
# Add 2nd reflection (this time without the harware adapter)
|
||||
ub.c2th([0, 1, 0], 12.39842)
|
||||
ub.addref([0, 1, 0], [60, 0, 30, 0, 90], 12.39842)
|
||||
|
||||
# check the state
|
||||
ub.ub()
|
||||
ub.checkub()
|
||||
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Constraints
|
||||
###################################################################################################
|
||||
help(hkl.con)
|
||||
hkl.con('qaz', 90)
|
||||
hkl.con('a_eq_b')
|
||||
hkl.con()
|
||||
|
||||
###################################################################################################\
|
||||
#Motion
|
||||
###################################################################################################
|
||||
print angles_to_hkl((60., 0., 30., 0., 0.))
|
||||
print hkl_to_angles(1, 0, 0)
|
||||
fivec.write([60, 0, 30, 90, 0])
|
||||
print "fivec=" , fivec.position
|
||||
wl.write(1.0)
|
||||
print "wl = ", wl.read()
|
||||
|
||||
# Load the last ub calculation used
|
||||
ub.lastub()
|
||||
ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
ub.showref()
|
||||
ub.swapref(1,2)
|
||||
|
||||
#print you.hkl
|
||||
#pos(get_hkl())
|
||||
hkl_group.read()
|
||||
#you.hkl.simulateMoveTo([0,1,1])
|
||||
#sim(get_hkl(), [0,1,1])
|
||||
hkl_group.sim([0.0,1.0,1.0])
|
||||
#pos(get_hkl(), [0,1,1])
|
||||
hkl_group.write([0.0,1.0,1.0])
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Scans
|
||||
###################################################################################################
|
||||
lscan(l, [sin], 1.0, 1.5, 0.1)
|
||||
ascan([k,l], [sin], [1.0, 1.0], [1.2, 1.3], [0.1, 0.1], zigzag=True, parallel_positioning = False)
|
||||
vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]]
|
||||
hklscan(vector, [sin, arr], 0.9)
|
||||
84
script/diffcalc/testfourc.py
Normal file
84
script/diffcalc/testfourc.py
Normal file
@@ -0,0 +1,84 @@
|
||||
en.move(20.0)
|
||||
delta.config.maxSpeed = 50.0
|
||||
delta.speed = 50.0
|
||||
delta.move(1.0)
|
||||
|
||||
run("diffcalc/diffutils")
|
||||
###################################################################################################\
|
||||
#Setup
|
||||
###################################################################################################
|
||||
|
||||
setup_diff(fourc, en)
|
||||
# Set some limits
|
||||
setup_axis('delta', 0, 179)
|
||||
setup_axis('delta', min=0)
|
||||
setup_axis('phi', cut=-180.0)
|
||||
|
||||
print_axis_setup()
|
||||
|
||||
###################################################################################################\
|
||||
#Orientation
|
||||
###################################################################################################
|
||||
help(ub.ub)
|
||||
ub.listub()
|
||||
|
||||
# Create a new ub calculation and set lattice parameters
|
||||
ub.newub('test')
|
||||
ub.setlat('cubic', 1, 1, 1, 90, 90, 90)
|
||||
|
||||
# Add 1st reflection (demonstrating the hardware adapter)
|
||||
settings.hardware.wavelength = 1
|
||||
ub.c2th([1, 0, 0]) # energy from hardware
|
||||
settings.hardware.position = 0, 60, 0, 30, 0, 0
|
||||
ub.addref([1, 0, 0])# energy and position from hardware
|
||||
|
||||
# Add 2nd reflection (this time without the harware adapter)
|
||||
ub.c2th([0, 1, 0], 12.39842)
|
||||
ub.addref([0, 1, 0], [60, 30, 0, 90], 12.39842)
|
||||
|
||||
# check the state
|
||||
ub.ub()
|
||||
ub.checkub()
|
||||
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Constraints
|
||||
###################################################################################################
|
||||
help(hkl.con)
|
||||
hkl.con('a_eq_b')
|
||||
hkl.con()
|
||||
|
||||
###################################################################################################\
|
||||
#Motion
|
||||
###################################################################################################
|
||||
print angles_to_hkl((60., 30., 0., 0.))
|
||||
print hkl_to_angles(1, 0, 0)
|
||||
fourc.write([60, 30, 90, 0])
|
||||
print "fourc=" , fourc.position
|
||||
wl.write(1.0)
|
||||
print "wl = ", wl.read()
|
||||
|
||||
# Load the last ub calculation used
|
||||
ub.lastub()
|
||||
ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
ub.showref()
|
||||
ub.swapref(1,2)
|
||||
|
||||
#print you.hkl
|
||||
#pos(get_hkl())
|
||||
hkl_group.read()
|
||||
#you.hkl.simulateMoveTo([0,1,1])
|
||||
#sim(get_hkl(), [0,1,1])
|
||||
hkl_group.sim([0.0,1.0,1.0])
|
||||
#pos(get_hkl(), [0,1,1])
|
||||
hkl_group.write([0.0,1.0,1.0])
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Scans
|
||||
###################################################################################################
|
||||
#lscan(l, [sin], 1.0, 1.5, 0.1)
|
||||
#ascan([k,l], [sin], [1.0, 1.0], [1.2, 1.3], [0.1, 0.1], zigzag=True, parallel_positioning = False)
|
||||
vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]]
|
||||
hklscan(vector, [sin, arr])
|
||||
@@ -8,7 +8,7 @@ run("diffcalc/diffutils")
|
||||
#Setup
|
||||
###################################################################################################
|
||||
|
||||
setup_sixc(sixc, en)
|
||||
setup_diff(sixc, en)
|
||||
# Set some limits
|
||||
setup_axis('gam', 0, 179)
|
||||
setup_axis('delta', 0, 179)
|
||||
Reference in New Issue
Block a user