This commit is contained in:
2019-03-20 13:52:00 +01:00
parent 3084fe0510
commit 5db0f78aee
910 changed files with 191152 additions and 322 deletions

View File

View File

@@ -0,0 +1,67 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
from __future__ import absolute_import
import os, sys
from diffcalc.hardware import ScannableHardwareAdapter
import diffcalc.hkl.you.geometry
from diffcalc.ub.persistence import UbCalculationNonPersister, UBCalculationJSONPersister
from diffcalc.ub.calcstate import UBCalcStateEncoder
from diffcalc import settings
import diffcalc.util
try:
__IPYTHON__ # @UndefinedVariable
IPYTHON = True
except NameError:
IPYTHON = False
try:
from gda.device.scannable.scannablegroup import ScannableGroup
from gdascripts.scannable.dummy import SingleInputDummy as Dummy
from diffcmd.diffcmd_utils import alias_commands
GDA = True
except ImportError:
# Not running in gda environment so fall back to minigda emulation
from diffcalc.gdasupport.minigda.scannable import ScannableGroup
from diffcalc.gdasupport.minigda.scannable import SingleFieldDummyScannable as Dummy
GDA = False
HELP_STRING = \
"""Quick: https://github.com/DiamondLightSource/diffcalc/blob/master/README.rst
Manual: http://diffcalc.readthedocs.io/en/latest/youmanual.html
Type: > help ub
> help hkl"""
if GDA:
from gda.configuration.properties import LocalProperties # @UnresolvedImport
var_folder = LocalProperties.get("gda.var")
diffcalc_persistance_path = os.path.join(var_folder, 'diffcalc')
if not os.path.exists(diffcalc_persistance_path):
print "Making diffcalc var folder:'%s'" % diffcalc_persistance_path
os.makedirs(diffcalc_persistance_path)
settings.ubcalc_persister = UBCalculationJSONPersister(diffcalc_persistance_path, UBCalcStateEncoder)
# else: should have been set if outside GDA

View File

@@ -0,0 +1,151 @@
'''
Created on 19 Feb 2017
@author: zrb13439
'''
import diffcmd.ipython
try:
__IPYTHON__ # @UndefinedVariable
IPYTHON = True
except NameError:
IPYTHON = False
GEOMETRIES = ['sixc', 'fivec', 'fourc', 'i16', 'i21']
def echo(cmd):
print "\n>>> " + str(cmd)
def print_heading(s):
print '\n' + '=' * len(s) + '\n' + s + '\n' + '=' * len(s)
class Demo(object):
def __init__(self, namespace, geometry):
self.namespace = namespace
assert geometry in GEOMETRIES
self.geometry = geometry
def all(self):
self.orient()
self.constrain()
self.scan()
def orient(self):
print_heading('Orientation demo')
self.remove_test_ubcalc()
pos_cmd_001 = {
'sixc': 'pos sixc [0 60 0 30 90 0]', # mu, delta, gam, eta, chi, phi
'i16': 'pos sixc [0 90 30 0 60 0]', # phi, chi, eta, mu, delta, gam
'i21': 'pos fourc [60 30 0 0]',
'fivec': 'pos fivec [60 0 30 90 0]',
'fourc': 'pos fourc [60 30 90 0]'
}[self.geometry]
pos_cmd_011 = {
'sixc': 'pos sixc [0 90 0 45 45 90]', # mu, delta, gam, eta, chi, phi
'i16': 'pos sixc [90 45 45 0 90 0]', # phi, chi, eta, mu, delta, gam
'i21': 'pos fourc [90 90 0 0]',
'fivec': 'pos fivec [90 0 45 45 90]',
'fourc': 'pos fourc [90 45 45 90]'
}[self.geometry]
self.echorun_magiccmd_list([
'help ub',
'pos wl 1',
"newub 'test'",
"setlat 'cubic' 1 1 1 90 90 90",
'ub',
'c2th [0 0 1]',
pos_cmd_001,
'addref [0 0 1]',
'c2th [0 1 1]',
pos_cmd_011,
'addref [0 1 1]',
'ub',
'checkub'])
def constrain(self):
print_heading('Constraint demo')
con_qaz_cmd = '' if self.geometry in ('fourc', 'i21') else 'con qaz 90'
con_mu_cmd = 'con mu 0' if self.geometry in ('sixc', 'i16') else ''
setmin_chi = 'setmin chi -180' if self.geometry == 'i21' else 'setmin chi 0'
setmin_phi = 'setmin phi -180' if self.geometry == 'i21' else ''
setmax_phi = 'setmax phi 180' if self.geometry == 'i21' else ''
self.echorun_magiccmd_list([
'help hkl',
con_qaz_cmd,
'con a_eq_b',
con_mu_cmd,
'con',
'setmin delta 0',
setmin_chi,
setmin_phi,
setmax_phi])
def scan(self):
print_heading('Scanning demo')
if self.geometry == 'i16':
diff_name = 'sixc'
elif self.geometry == 'i21':
diff_name = 'fourc'
else:
diff_name = self.geometry
self.echorun_magiccmd_list([
'setnphi [0 0 1]' if self.geometry == 'i21' else '',
'pos hkl [0 0 1]' if self.geometry == 'i21' else 'pos hkl [1 0 0]',
'scan delta 40 90 10 hkl ct 1',
'pos hkl [0 1 0]',
'scan h 0 1 .2 k l %s ct 1' % diff_name,
'con psi',
'scan psi 0 90 10 hkl [1 0 1] eta chi phi ct .1'])
def echorun_magiccmd_list(self, magic_cmd_list):
for cmd in magic_cmd_list:
self.echorun_magiccmd(cmd)
def remove_test_ubcalc(self):
try:
eval("rmub('test')", self.namespace)
except (OSError, KeyError):
pass
def echorun_magiccmd(self, magic_cmd):
if IPYTHON:
from IPython import get_ipython
echo(magic_cmd)
get_ipython().magic(magic_cmd)
else: # Python
# python's help is interactive. Handle specially
if magic_cmd == 'help ub':
echo("help ub")
exec("print ub.__doc__", self.namespace)
return
if magic_cmd == 'help hkl':
echo("help(hkl)")
exec("print hkl.__doc__", self.namespace)
return
# Echo the Python version of the magic command
tokens = diffcmd.ipython.tokenify(magic_cmd)
if not tokens:
return
python_cmd = tokens.pop(0) + '(' + ', '.join(tokens) + ')'
python_cmd = python_cmd.replace('[, ', '[')
python_cmd = python_cmd.replace(',]', ']')
python_cmd = python_cmd.replace(', ]', ']')
echo(python_cmd)
# Run the Python version of the magic command
elements = diffcmd.ipython.parse(magic_cmd, self.namespace)
func = elements.pop(0)
result = func(*elements)
if result:
print result

View File

@@ -0,0 +1,44 @@
from startup._common_imports import *
diffcalc.util.COLOURISE_TERMINAL_OUTPUT = False
### Create dummy scannables ###
print "Dummy scannables: sixc(mu, delta, gam, eta, chi, phi) and en"
mu = Dummy('mu')
delta = Dummy('delta')
gam = Dummy('gam')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
_sixc = ScannableGroup('sixc', (mu, delta, gam, eta, chi, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_sixc, en, ESMTGKeV)
settings.geometry = diffcalc.hkl.you.geometry.SixCircle() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _sixc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
# For manual!
from diffcalc.ub.persistence import UbCalculationNonPersister
settings.ubcalc_persister = UbCalculationNonPersister()
from diffcalc.gdasupport.you import * # @UnusedWildImport
DIFFCALC_ROOT = os.sep.join(
os.path.realpath(diffcalc.__file__).split(os.sep)[:-2])
MANUALS_TO_MAKE = [
os.path.join(
DIFFCALC_ROOT, 'doc', 'source', 'youmanual_template.rst'),
os.path.join(
DIFFCALC_ROOT, 'README_template.rst')]
print 'MANUALS_TO_MAKE: ', MANUALS_TO_MAKE

View File

View File

@@ -0,0 +1,73 @@
from __future__ import absolute_import
from diffcalc import settings
from diffcalc.hkl.you.geometry import SixCircle
from diffcalc.hardware import DummyHardwareAdapter
import diffcalc.util # @UnusedImport
# Disable error handling designed for interactive use
diffcalc.util.DEBUG = True
# Configure and import diffcalc objects
settings.hardware = DummyHardwareAdapter(('mu', 'delta', 'gam', 'eta', 'chi', 'phi'))
settings.geometry = SixCircle() # @UndefinedVariable
# These must be imported AFTER the settings have been configured
from diffcalc.dc import dcyou as dc
from diffcalc.ub import ub
from diffcalc import hardware
from diffcalc.hkl.you import hkl
# Set some limits
hardware.setmin('gam', -179)
hardware.setmax('gam', 179)
# These demos reproduce the outline in the developer guide
def demo_all():
demo_orient()
demo_motion()
def demo_orient():
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], [0, 60, 0, 30, 0, 90], 12.39842)
# check the state
ub.ub()
ub.checkub()
def demo_motion():
dc.angles_to_hkl((0., 60., 0., 30., 0., 0.))
hkl.con('qaz', 90)
hkl.con('a_eq_b')
hkl.con('mu', 0)
hardware.setmin('delta', 0)
dc.hkl_to_angles(1, 0, 0)
demo_all()

View File

@@ -0,0 +1,71 @@
###
# Copyright 2008-2018 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import platform
from diffcalc.util import DiffcalcException
DEBUG = False
try:
from gda.device.scannable import ScannableBase
except ImportError:
from diffcalc.gdasupport.minigda.scannable import ScannableBase
from diffcalc.ub.ub import ubcalc, _to_column_vector_triple
class _DynamicDocstringMetaclass(type):
def _get_doc(self):
return AzihklClass.dynamic_docstring
__doc__ = property(_get_doc) # @ReservedAssignment
class AzihklClass(ScannableBase):
'Azimuthal reference reciprocal lattice vector'
if platform.system() != 'Java':
__metaclass__ = _DynamicDocstringMetaclass # TODO: Removed to fix Jython
dynamic_docstring = 'Azimuthal reference reciprocal lattice vector'
def _get_doc(self):
return AzihklClass.dynamic_docstring
__doc__ = property(_get_doc) # @ReservedAssignment
def __init__(self,name):
self.setName(name)
self.setLevel(3)
self.setInputNames(['azih','azik','azil'])
self.setOutputFormat(['%4.4f', '%4.4f','%4.4f'])
def asynchronousMoveTo(self,new_position):
ref_matrix = _to_column_vector_triple(new_position)
ubcalc.set_n_hkl_configured(ref_matrix)
def isBusy(self):
return 0
def getPosition(self):
try:
ref_matrix = ubcalc.n_hkl
return ref_matrix.T.tolist()[0]
except DiffcalcException, e:
print e

View File

@@ -0,0 +1,430 @@
'''
Created on 19 Feb 2017
@author: zrb13439
'''
from diffcalc import settings
try:
from gda.device.scannable.scannablegroup import \
ScannableMotionWithScannableFieldsBase, ScannableBase
except ImportError:
from diffcalc.gdasupport.minigda.scannable import \
ScannableMotionWithScannableFieldsBase, ScannableBase
from math import pi
# TP_HELP="""
# Use the Scannables tplab, tplabx, tplaby, tplabz to move the configured tool point in
# the lab frame. For example to move it to the centre of the diffractomter:
#
# >>> pos tplab [0 0 0] # Move the toolpoint
#
# use 'settp' to change the configured toolpoint in the phi frame:
#
# >>> pos tphi [0 0 1] # will not move anything
#
# or use it with no args to make the location in the phi frame currently in
# the centre of the diffracomtter the tool point. i.e. to make the tblab
# report back [0 0 0]
# """
TP_HELP="""
For help with sa, tp_phi and tp_lab see: http://confluence.diamond.ac.uk/x/CBIAB
"""
from diffcalc.hkl.you.constraints import NUNAME
from diffcalc.hkl.you.geometry import calcETA, calcCHI, calcPHI, YouGeometry,\
YouPosition
try:
from numpy import matrix
except ImportError:
from numjy import matrix
TORAD = pi / 180
TODEG = 180 / pi
DEBUG = False
def calc_tp_lab(tp_phi_tuple, eta, chi, phi, xyz_eta=[0, 0, 0]):
tp_phi = matrix(tp_phi_tuple).T
ETA = calcETA(eta * TORAD)
CHI = calcCHI(chi * TORAD)
PHI = calcPHI(phi * TORAD)
xyz_eta = matrix(xyz_eta).T
tp_lab = ETA * (xyz_eta + (CHI * PHI * tp_phi))
return list(tp_lab.T.tolist()[0])
def calc_tp_eta(tp_phi_tuple, chi, phi):
return calc_tp_lab(tp_phi_tuple, 0, chi, phi, [0, 0, 0])
def move_lab_origin_into_phi(chi, phi, xyz_eta_tuple):
# the inverse of calc_tp_lab with tp_lab=0:
CHI = calcCHI(chi * TORAD)
PHI = calcPHI(phi * TORAD)
xyz_eta = matrix(xyz_eta_tuple).T
try:
#work in IPython with numpy
tp_phi = PHI.I * CHI.I * (-1.0 * xyz_eta)
except:
# work in GDA using jama_matrix_wrapper - definitely not nice
tp_phi = PHI.I * CHI.I * (xyz_eta.__mul__(-1.0))
return list(tp_phi.T.tolist()[0])
def _format_vector(vector, fmt = '%7.4f'):
vals = [fmt % e for e in vector]
return ' '.join(vals)
class FourCircleI21(YouGeometry):
"""For a diffractometer with angles:
delta, eta, chi, phi
"""
def __init__(self, beamline_axes_transform=None, delta_offset=0):
self._delta_offset = delta_offset
YouGeometry.__init__(self, 'fourc', {'eta': 0, 'delta': 0}, beamline_axes_transform)
# Order should match scannable order in _fourc group for mapping to work correctly
self._scn_mapping_to_int = ((NUNAME, lambda x: x + self._delta_offset),
('mu', lambda x: x),
('chi', lambda x: x),
('phi', lambda x: -x))
self._scn_mapping_to_ext = ((NUNAME, lambda x: x - self._delta_offset),
('mu', lambda x: x),
('chi', lambda x: x),
('phi', lambda x: -x))
def map_to_internal_name(self, name):
scn_names = settings.hardware.diffhw.getInputNames()
try:
idx_name = scn_names.index(name)
you_name, _ = self._scn_mapping_to_int[idx_name]
return you_name
except ValueError:
return name
def map_to_external_name(self, name):
scn_names = settings.hardware.diffhw.getInputNames()
for idx, (you_name, _) in enumerate(self._scn_mapping_to_ext):
if you_name == name:
return scn_names[idx]
return name
def map_to_internal_position(self, name, value):
scn_names = settings.hardware.diffhw.getInputNames()
try:
idx_name = scn_names.index(name)
except ValueError:
return name, value
new_name, op = self._scn_mapping_to_int[idx_name]
try:
return new_name, op(value)
except TypeError:
return new_name, None
def map_to_external_position(self, name, value):
try:
(idx, _, op), = tuple((i, nm, o) for i, (nm, o) in enumerate(self._scn_mapping_to_ext) if nm == name)
except ValueError:
return name, value
scn_names = settings.hardware.diffhw.getInputNames()
try:
ext_name = scn_names[idx]
except ValueError:
return name, value
try:
return ext_name, op(value)
except TypeError:
return ext_name, None
def physical_angles_to_internal_position(self, physical_angle_tuple):
you_angles = {}
scn_names = settings.hardware.diffhw.getInputNames()
for scn_name, phys_angle in zip(scn_names, physical_angle_tuple):
name, val = self.map_to_internal_position(scn_name, phys_angle)
you_angles[name] = val
you_angles.update(self.fixed_constraints)
angle_values = tuple(you_angles[name] for name in YouPosition.get_names())
return YouPosition(*angle_values, unit='DEG')
def internal_position_to_physical_angles(self, internal_position):
clone_position = internal_position.clone()
clone_position.changeToDegrees()
you_angles = clone_position.todict()
res = []
for name, _ in self._scn_mapping_to_ext:
_, val = self.map_to_external_position(name, you_angles[name])
res.append(val)
return tuple(res)
class I21SampleStage(ScannableMotionWithScannableFieldsBase):
def __init__(self, name, pol_scn, tilt_scn, az_scn, xyz_eta_scn):
self.setName(name)
self._scn_list = [pol_scn, tilt_scn, az_scn]
self.xyz_eta_scn = xyz_eta_scn
self.setInputNames([pol_scn.getName(), tilt_scn.getName(), az_scn.getName()]) # note, names copied below
self.setOutputFormat(['%7.5f'] * 3)
self.completeInstantiation()
# tp_phi is the TARGET tool point to end up at the diffractometer centre
self.tp_phi = [0, 0, 0]
self.tp_phi_scannable = I21SampleStage.TpPhiScannable('tp_phi', self)
self.centre_toolpoint = True
def asynchronousMoveTo(self, pos_triple):
if len(pos_triple) != 3:
raise ValueError(self.getName() + ' device expects three inputs')
# Move pol, tilt & az (None if not to be moved)
pol, tilt, az = pos_triple
if pol is not None:
self._scn_list[0].asynchronousMoveTo(pol)
if tilt is not None:
self._scn_list[1].asynchronousMoveTo(tilt)
if az is not None:
self._scn_list[2].asynchronousMoveTo(az)
if self.centre_toolpoint:
_, tilt, az = self.completePosition(pos_triple)
chi = tilt
phi = az
tp_offset_eta = calc_tp_eta(self.tp_phi, chi, phi)
if DEBUG:
print ('{Correcting xyz_eta for '
'tilt(chi)=%.2f & az(phi)=%.2f}' % (tilt, az)).rjust(79)
xyz = [-1 * e for e in tp_offset_eta]
self.xyz_eta_scn.asynchronousMoveTo(xyz)
def rawGetPosition(self):
return [scn.getPosition() for scn in self._scn_list]
def getFieldPosition(self, i):
return self._scn_list[i].getPosition()
def isBusy(self):
return (any([scn.isBusy() for scn in self._scn_list])
or self.xyz_eta_scn.isBusy())
def waitWhileBusy(self):
for scn in self._scn_list:
scn.waitWhileBusy()
self.xyz_eta_scn.waitWhileBusy()
def __repr__(self):
# Sample angle columns
pos = self.getPosition()
formatted_values = self.formatPositionFields(pos)
sa_col = []
sa_col.append('%s:' % self.getName())
sa_col.append('%s: %s (eta)' % (self._scn_list[0].getName(),formatted_values[0]))
sa_col.append('%s: %s (chi)' % (self._scn_list[1].getName(),formatted_values[1]))
sa_col.append('%s: %s (phi)' % (self._scn_list[2].getName(),formatted_values[2]))
sa_col_width = len(sa_col[2])
# Toolpoint column
xyz_eta = list(self.xyz_eta_scn.getPosition())
eta, chi, phi = self.getEulerPosition()
tp_lab = calc_tp_lab(self.tp_phi, eta, chi, phi, xyz_eta)
tp_col = []
tp_col.append('')
tp_col.append('tp_phi : %s (set)' % _format_vector(self.tp_phi))
tp_col.append('tp_lab : %s' % _format_vector(tp_lab))
tp_col.append('xyz_eta: %s' % _format_vector(xyz_eta))
# Combine columns
lines = []
while sa_col or tp_col:
sa_row = sa_col.pop(0) if sa_col else ''
tp_row = tp_col.pop(0) if tp_col else ''
lines.append(sa_row.ljust(sa_col_width + 3) + tp_row)
if self.centre_toolpoint:
lines.append("\nToolpoint centring ENABLED (disable with toolpoint_off)")
else:
lines.append("\nToolpoint centring DISABLED (enable with toolpoint_on)")
# Add some help
return '\n'.join(lines) + TP_HELP
def getEulerPosition(self):
pol, tilt, az = self.getPosition()
eta, chi, phi = pol, tilt, az
return eta, chi, phi
class TpPhiScannable(ScannableBase):
def __init__(self, name, i21_sample_stage):
self.name = name
self.i21_sample_stage = i21_sample_stage
self.inputNames = [name + 'x', name +'y', name + 'z']
self.outputFormat = ['% 6.4f'] * 3
self.level = 3
def isBusy(self):
return False
def waitWhileBusy(self):
return
def asynchronousMoveTo(self, new_position):
if len(new_position) != 3:
raise TypeError('Expected 3 element target')
self.i21_sample_stage.tp_phi = list(new_position)
def getPosition(self):
return list(self.i21_sample_stage.tp_phi)
def zerosample(self):
"""Calculate tp_phi from the currently centred sample location."""
_, chi, phi = self.getEulerPosition()
xyz_eta_tuple = list(self.xyz_eta_scn.getPosition())
tp_phi = move_lab_origin_into_phi(chi, phi, xyz_eta_tuple)
self.tp_phi = tp_phi
print "tp_phi set to: %s" % tp_phi
def centresample(self):
"""Centre the sample. Equivilent to moving sa to its current position."""
self.asynchronousMoveTo([None, None, None])
self.waitWhileBusy()
class I21DiffractometerStage(ScannableMotionWithScannableFieldsBase):
def __init__(self, name, delta_scn, sample_stage_scn, delta_offset=0):
"""Create diffractomter stage from 3circle sample axes and a
delta/tth axis.
Both the chi and delta offsets are added to underlying scannable values
when *reading* the position. iu the same offset is subtracted when
*setting* the position.
"""
self.sample_stage_scn = sample_stage_scn
self.delta_scn = delta_scn
self.delta_offset = delta_offset
self.setName(name)
self.setInputNames(['delta', 'eta', 'chi', 'phi']) # note, names copied below
self.setOutputFormat(['%7.4f'] * 4)
self.completeInstantiation()
def asynchronousMoveTo(self, pos_quadruple):
if len(pos_quadruple) != 4:
raise ValueError(self.getName() + ' device expects four inputs')
delta, eta, chi, phi = pos_quadruple
pol = eta
#TODO revert to 'chi - self.chi_offset'once EPICS sign fixed
tilt = chi
az = phi
if delta is not None:
self.delta_scn.asynchronousMoveTo(delta - self.delta_offset)
if (pol is not None) or (tilt is not None) or (az is not None):
self.sample_stage_scn.asynchronousMoveTo([pol, tilt, az])
def rawGetPosition(self):
delta = self.delta_scn.getPosition()
pol, tilt, az = self.sample_stage_scn.getPosition()
eta, chi, phi = pol, tilt, az
return delta + self.delta_offset, eta, chi, phi
def getFieldPosition(self, i):
return self.getPosition()[i]
def isBusy(self):
return self.delta_scn.isBusy() or self.sample_stage_scn.isBusy()
def waitWhileBusy(self):
self.delta_scn.waitWhileBusy()
self.sample_stage_scn.waitWhileBusy()
def __repr__(self):
vals = self.formatPositionFields(self.getPosition())
lines = []
for name, val, hint in zip(self.getInputNames(), vals, self.get_hints()):
lines.append('%-6s : %s%s' % (name, val, hint))
return '\n'.join(lines)
def get_hints(self):
sample_names = self.sample_stage_scn.getInputNames()
hints = []
if self.delta_offset != 0:
sign = '+' if self.delta_offset > 0 else '-'
hints.append(' (%s %s %s)' %
(self.delta_scn.getName(), sign, abs(self.delta_offset))) # delta
else:
hints.append(' (%s)' % self.delta_scn.getName()) # delta
hints.append(' (%s)' % sample_names[0]) # eta
hints.append(' (%s)' % sample_names[1]) # chi
hints.append(' (%s)' % sample_names[2]) # phi
return hints
class I21TPLab(ScannableMotionWithScannableFieldsBase):
def __init__(self, name, sample_stage_scn):
self.name = name
self.sample_stage_scn = sample_stage_scn
self.setInputNames([name + 'x', name + 'y', name + 'z']) # note, names copied below
self.setOutputFormat(['%7.4f'] * 3)
self.completeInstantiation()
self.setAutoCompletePartialMoveToTargets(True)
def rawAsynchronousMoveTo(self, tp_lab_target):
if len(tp_lab_target) != 3:
raise ValueError(self.getName() + ' device expects three inputs')
if None in tp_lab_target:
raise ValueError('unexpected None in tp_lab_target: ', tp_lab_target)
eta, chi, phi = self.sample_stage_scn.getEulerPosition()
ETA = calcETA(eta * TORAD)
# Move tp target from lab frame inwards to eta frame
tp_lab_target = matrix(tp_lab_target).T
tp_eta_target = ETA.T * tp_lab_target # ETA.I == ETA.T
# Move configured tp from phi frame outwards to eta frame
tp_eta = calc_tp_eta(self.sample_stage_scn.tp_phi, chi, phi)
# Calculate offset required to align the two
xyz_eta = tp_eta_target - matrix(tp_eta).T
xyz_eta = xyz_eta.T.tolist()[0]
self.sample_stage_scn.xyz_eta_scn.asynchronousMoveTo(xyz_eta)
def rawGetPosition(self):
tp_phi = list(self.sample_stage_scn.tp_phi)
eta, chi, phi = self.sample_stage_scn.getEulerPosition()
xyz_eta = list(self.sample_stage_scn.xyz_eta_scn.getPosition())
tp_lab = calc_tp_lab(tp_phi, eta, chi, phi, xyz_eta)
return tp_lab
def getFieldPosition(self, i):
return self.getPosition()[i]
def isBusy(self):
return self.sample_stage_scn.xyz_eta_scn.isBusy()
def waitWhileBusy(self):
self.sample_stage_scn.xyz_eta_scn.waitWhileBusy()

View File

@@ -0,0 +1,36 @@
from startup._common_imports import *
import startup._demo
### Create dummy scannables ###
print "Diffcalc creating dummy Scannables as _fivec and en were not found"
delta = Dummy('delta')
gam = Dummy('gam')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
_fivec = ScannableGroup('_fivec', (delta, gam, eta, chi, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_fivec, en, ESMTGKeV)
settings.geometry = diffcalc.hkl.you.geometry.FiveCircle() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group = _fivec
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
lastub() # Load the last ub calculation used
# Set some limits
setmin('gam', -179)
setmax('gam', 179)
demo = startup._demo.Demo(globals(), 'fivec')

View File

@@ -0,0 +1,31 @@
from startup._common_imports import *
import startup._demo
### Create dummy scannables ###
delta = Dummy('delta')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
_fourc = ScannableGroup('_fourc', (delta, eta, chi, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_fourc, en, ESMTGKeV)
settings.geometry = diffcalc.hkl.you.geometry.FourCircle() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _fourc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
lastub()
demo = startup._demo.Demo(globals(), 'fourc')

View File

@@ -0,0 +1,78 @@
from startup._common_imports import * # @UnusedWildImport
from diffcalc.gdasupport.minigda.scannable import ScannableMotionWithScannableFieldsBase # @UnusedImport
from diffcalc.hkl.you.geometry import YouGeometry, YouPosition
from diffcalc.hkl.you.constraints import NUNAME
from diffcalc.hardware import setrange
from diffcalc.hkl.you.calc import SMALL
if not GDA:
import startup._demo
else:
# import __main__ # @UnresolvedImport
from __main__ import dd2th,ddth,dummychi,energy # @UnresolvedImport
LOCAL_MANUAL = "http://confluence.diamond.ac.uk/pages/viewpage.action?pageId=31853413"
# Diffcalc i06-1
# ======== ===
# delta dd2th
# eta ddth
# chi dummy
# phi 0
class ThreeCircleI06(YouGeometry):
"""For a diffractometer with theta two-theta geometry:
delta, eta
"""
def __init__(self, beamline_axes_transform=None):
YouGeometry.__init__(self, 'threec', {'mu': 0, NUNAME: 0, 'phi': 0}, beamline_axes_transform)
def physical_angles_to_internal_position(self, physical_angle_tuple):
# mu, delta, nu, eta, chi, phi
delta_phys, eta_phys, chi_phys = physical_angle_tuple
return YouPosition(0, delta_phys, 0, eta_phys, chi_phys, 0, 'DEG')
def internal_position_to_physical_angles(self, internal_position):
clone_position = internal_position.clone()
clone_position.changeToDegrees()
_, delta_phys, _, eta_phys, chi_phys, _ = clone_position.totuple()
return delta_phys, eta_phys, chi_phys
### Create dummy scannables ###
if GDA:
print "!!! Starting LIVE diffcalc with delta(dd2th), eta(ddth), chi(dummy) and denergy."
_threec = ScannableGroup('_threec', (dd2th, ddth, dummychi))
delta = _threec.dd2th
eta = _threec.ddth
en=energy
if float(en.getPosition()) == 0: # no energy value - dummy mode
en(800)
else:
delta = Dummy('delta')
eta = Dummy('eta')
chi = Dummy('chi')
_threec = ScannableGroup('_threec', (delta, eta, chi))
en = Dummy('en')
en(800)
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 0.001
settings.hardware = ScannableHardwareAdapter(_threec, en, ESMTGKeV)
settings.geometry = ThreeCircleI06() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _threec
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
if not GDA:
setrange('chi', 90 - SMALL, 90 + SMALL)
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
lastub()

View File

@@ -0,0 +1,100 @@
from startup._common_imports import * # @UnusedWildImport
from diffcalc.hkl.you.constraints import NUNAME
if GDA:
from __main__ import diff1vdelta, diff1halpha, diff1vgamma, diff1homega, dcm1energy # @UnresolvedImport
from diffcalc.hkl.you.geometry import YouGeometry, YouPosition,\
YouRemappedGeometry
try:
from numpy import matrix
except ImportError:
from numjy import matrix
class FourCircleI07EH1h(YouRemappedGeometry):
"""For a diffractometer with angles:
delta, gam, eta, phi
"""
def __init__(self, beamline_axes_transform=None):
YouRemappedGeometry.__init__(self, 'fourc', {'mu': 0, 'chi': 90}, beamline_axes_transform)
# Order should match scannable order in _fourc group for mapping to work correctly
omega_to_phi = lambda x: 180. - x
self._scn_mapping_to_int = (('delta', lambda x: x),
('gam', lambda x: x),
('eta', lambda x: x),
('phi', omega_to_phi))
phi_to_omega = lambda x: ((180. - x) + 180.) % 360 - 180
self._scn_mapping_to_ext = (('delta', lambda x: x),
('gam', lambda x: x),
('eta', lambda x: x),
('phi', phi_to_omega))
### Create dummy scannables ###
if GDA:
###map GDA scannable to diffcalc axis name###
_fourc = ScannableGroup('_fourc', (diff1vdelta, diff1vgamma, diff1halpha, diff1homega))
delta=_fourc.diff1vdelta
gam=_fourc.diff1vgamma
eta=_fourc.diff1halpha
phi=_fourc.diff1homega
en=dcm1energy
if float(en.getPosition()) == 0: # no energy value - dummy mode
en(800)
else:
#Create dummy axes to run outside GDA in IPython#
delta = Dummy('delta')
gam = Dummy(NUNAME)
eta = Dummy('eta')
phi = Dummy('phi')
_fourc = ScannableGroup('_fourc', (delta, gam, eta, phi))
en = Dummy('en')
en(800)
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_fourc, en, ESMTGKeV)
settings.geometry = FourCircleI07EH1h() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _fourc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
# for aliasing completeness
mu= settings.geometry.fixed_constraints['mu']
chi= settings.geometry.fixed_constraints['chi']
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
lastub()
# Set reference vector direction returning betain and betaout angles as alpha and beta
if ubcalc.name:
setnphi('0; 0; 1')
### Set i07 specific limits
def setLimitsAndCuts():
''' set motor limits for diffcalc, these are within the actual motor limits
'''
setmin(delta, -11.275)
setmax(delta, 100.0)
setmin(gam, -11.0)
setmax(gam, 49.934)
setmin(eta, -5.096)
setmax(eta, 5.115)
setcut(phi, -180.0)
print "Current hardware limits set to:"
hardware()
if not GDA:
setLimitsAndCuts()
# TODO: make demo code for (2+2) diffractometer geometry
#if not GDA:
# demo = startup._demo.Demo(globals(), 'fourc')

View File

@@ -0,0 +1,90 @@
from startup._common_imports import * # @UnusedWildImport
from diffcalc.hkl.you.constraints import NUNAME
if GDA:
from __main__ import diff1vdelta, diff1valpha, diff1vgamma, diff1vomega, dcm1energy # @UnresolvedImport
from diffcalc.hkl.you.geometry import YouGeometry, YouPosition
class FourCircleI07EH1v(YouGeometry):
"""For a diffractometer with angles:
delta, gam, mu, phi
"""
def __init__(self, beamline_axes_transform=None):
YouGeometry.__init__(self, 'fourc', {'eta': 0, 'chi': 0}, beamline_axes_transform)
def physical_angles_to_internal_position(self, physical_angle_tuple):
delta_phys, gam_phys, mu_phys, phi_phys = physical_angle_tuple
return YouPosition(mu_phys, delta_phys, gam_phys, 0, 0, phi_phys, 'DEG')
def internal_position_to_physical_angles(self, internal_position):
clone_position = internal_position.clone()
clone_position.changeToDegrees()
mu_phys, delta_phys, gam_phys, _, _, phi_phys = clone_position.totuple()
return delta_phys, gam_phys, mu_phys, phi_phys
### Create dummy scannables ###
if GDA:
###map GDA scannable to diffcalc axis name###
_fourc = ScannableGroup('_fourc', (diff1vdelta, diff1vgamma, diff1valpha, diff1vomega))
delta=_fourc.diff1vdelta
gam=_fourc.diff1vgamma
mu=_fourc.diff1valpha
phi=_fourc.diff1vomega
en=dcm1energy
else:
#Create dummy axes to run outside GDA in IPython#
delta = Dummy('delta')
gam = Dummy(NUNAME)
mu = Dummy('mu')
phi = Dummy('phi')
_fourc = ScannableGroup('_fourc', (delta, gam, mu, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_fourc, en, ESMTGKeV)
settings.geometry = FourCircleI07EH1v() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _fourc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
# for aliasing completeness
eta= settings.geometry.fixed_constraints['eta']
chi= settings.geometry.fixed_constraints['chi']
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
lastub()
# Set reference vector direction returning betain and betaout angles as alpha and beta
if ubcalc.name:
setnphi('0; 0; 1')
### Set i07 specific limits
def setLimitsAndCuts():
''' set motor limits for diffcalc, these are within the actual motor limits
'''
setmin(delta, -11.275)
setmax(delta, 100.0)
setmin(gam, -11.0)
setmax(gam, 49.934)
setmin(mu, -6.561)
setmax(mu, 29.163)
setcut(phi, -180.0)
print "Current hardware limits set to:"
hardware()
if not GDA:
setLimitsAndCuts()
# TODO: make demo code for (2+2) diffractometer geometry
#if not GDA:
# demo = startup._demo.Demo(globals(), 'fourc')

View File

@@ -0,0 +1,90 @@
from startup._common_imports import * # @UnusedWildImport
from diffcalc.hkl.you.constraints import NUNAME
if GDA:
from __main__ import diff2delta, diff2alpha, diff2gamma, diff2omega, dcm1energy # @UnresolvedImport
from diffcalc.hkl.you.geometry import YouGeometry, YouPosition
class FourCircleI07EH2v(YouGeometry):
"""For a diffractometer with angles:
delta, gam, mu, phi
"""
def __init__(self, beamline_axes_transform=None):
YouGeometry.__init__(self, 'fourc', {'eta': 0, 'chi': 0}, beamline_axes_transform)
def physical_angles_to_internal_position(self, physical_angle_tuple):
delta_phys, gam_phys, mu_phys, phi_phys = physical_angle_tuple
return YouPosition(mu_phys, delta_phys, gam_phys, 0, 0, phi_phys, 'DEG')
def internal_position_to_physical_angles(self, internal_position):
clone_position = internal_position.clone()
clone_position.changeToDegrees()
mu_phys, delta_phys, gam_phys, _, _, phi_phys = clone_position.totuple()
return delta_phys, gam_phys, mu_phys, phi_phys
### Create dummy scannables ###
if GDA:
###map GDA scannable to diffcalc axis name###
_fourc = ScannableGroup('_fourc', (diff2delta, diff2gamma, diff2alpha, diff2omega))
delta=_fourc.diff2delta
gam=_fourc.diff2gamma
mu=_fourc.diff2alpha
phi=_fourc.diff2omega
en=dcm1energy
else:
#Create dummy axes to run outside GDA in IPython#
delta = Dummy('delta')
gam = Dummy(NUNAME)
mu = Dummy('mu')
phi = Dummy('phi')
_fourc = ScannableGroup('_fourc', (delta, gam, mu, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_fourc, en, ESMTGKeV)
settings.geometry = FourCircleI07EH2v() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _fourc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
# for aliasing completeness
eta= settings.geometry.fixed_constraints['eta']
chi= settings.geometry.fixed_constraints['chi']
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
lastub()
# Set reference vector direction returning betain and betaout angles as alpha and beta
if ubcalc.name:
setnphi('0; 0; 1')
### Set i07 specific limits
def setLimitsAndCuts():
''' set motor limits for diffcalc, these are within the actual motor limits
'''
setmin(delta, -0.60755)
setmax(delta, 120.0)
setmin(gam, -1.3913)
setmax(gam, 48.160)
setmin(mu, -2.5124)
setmax(mu, 24.107)
setcut(phi, -180.0)
print "Current hardware limits set to:"
hardware()
if not GDA:
setLimitsAndCuts()
# TODO: make demo code for (2+2) diffractometer geometry
#if not GDA:
# demo = startup._demo.Demo(globals(), 'fourc')

View File

@@ -0,0 +1,137 @@
from startup._common_imports import * # @UnusedWildImport
if not GDA:
import startup._demo
else:
# import __main__ # @UnresolvedImport
from __main__ import tth,th,chi,pgm_energy, simtth,simth,simchi,simalpha # @UnresolvedImport
LOCAL_MANUAL = ""
SIM_MODE=False
### Create dummy scannables ###
if GDA:
###map GDA scannable to diffcalc axis name###
phi = Dummy('phi')
_fourc = ScannableGroup('_fourc', (tth, th, chi, phi))
en=pgm_energy
if float(en.getPosition()) == 0: # no energy value - dummy mode
en(800)
else:
#Create dummy axes to run outside GDA in IPython#
delta = Dummy('delta')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
_fourc = ScannableGroup('_fourc', (delta, eta, chi, phi))
en = Dummy('en')
en(800)
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 0.001
settings.hardware = ScannableHardwareAdapter(_fourc, en, ESMTGKeV)
settings.geometry = diffcalc.hkl.you.geometry.FourCircle() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _fourc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
### Load the last ub calculation used
lastub()
### Set i10 specific limits
def setLimitsAndCuts(delta,eta,chi,phi):
''' set motor limits for diffcalc, these are within the actual motor limits
'''
setmin(delta, -60.0)
setmax(delta, 165.0)
setmin(eta, -94.408)
setmax(eta, 190.591)
setmin(chi, 85.5)
setmax(chi, 94.5)
setmin(phi, 0)
setmax(phi, 360.0)
print "Current hardware limits set to:"
hardware()
if not GDA:
setLimitsAndCuts(delta,eta,chi,phi)
if GDA:
def swithMotors(delta, mu, eta, chi, phi):
import __main__
from diffcalc.dc import dcyou as _dc
### update Wrap i21 names to get diffcalc names
_fourc = ScannableGroup('_fourc', (delta, mu, eta, chi, phi))
#update diffcalc objects
__main__.settings.hardware = ScannableHardwareAdapter(_fourc, __main__.en, ESMTGKeV) # @UndefinedVariable
__main__.settings.geometry = diffcalc.hkl.you.geometry.FourCircle() # @UndefinedVariable
__main__.settings.energy_scannable = __main__.en # @UndefinedVariable
__main__.settings.axes_scannable_group= _fourc
__main__.settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
__main__.fourc=DiffractometerScannableGroup('fourc', _dc, _fourc)
__main__.hkl = Hkl('hkl', _fourc, _dc)
__main__.h, __main__.k, __main__.l = hkl.h, hkl.k, hkl.l
from diffcalc.gdasupport.you import _virtual_angles
from diffcalc.gdasupport.scannable.simulation import SimulatedCrystalCounter
from diffcalc.gdasupport.scannable.wavelength import Wavelength
__main__.hklverbose = Hkl('hklverbose', _fourc, _dc, _virtual_angles)
__main__.wl = Wavelength('wl',__main__.en,ESMTGKeV) # @UndefinedVariable
__main__.ct = SimulatedCrystalCounter('ct', _fourc, __main__.settings.geometry,__main__.wl) # @UndefinedVariable
def stopMotors(delta, eta, chi, phi):
delta.stop()
eta.stop()
chi.stop()
phi.stop()
def simdc():
''' switch to use dummy motors in diffcalc
'''
print "Stop real motors"
stopMotors(tth,th,chi,phi)
global SIM_MODE
SIM_MODE=True
import __main__
__main__.en=Dummy("en")
print "Set energy to 12398.425 eV in simulation mode!"
__main__.en(12398.425) #1 Angstrom wavelength @UndefinedVariable
print "Switch to simulation motors"
swithMotors(simtth,simalpha,simth,simchi,phi)
setLimitsAndCuts(simtth,simalpha,simth,simchi,phi)
def realdc():
''' switch to use real motors in diffcalc
'''
print "Stop simulation motors"
stopMotors(simtth,simalpha,simth,simchi,phi)
global SIM_MODE
SIM_MODE=False
import __main__
print "Set energy to current beamline energy in real mode!"
__main__.en=pgm_energy
print "Switch to real motors"
swithMotors(tth,th,chi,phi)
setLimitsAndCuts(tth,th,chi,phi)
from gda.jython.commands.GeneralCommands import alias # @UnresolvedImport
print "Created commands: 'simdc' and 'realdc' to switch between real and simulated motors."
alias("simdc")
alias("realdc")
### Demo ###
if not GDA:
demo = demo = startup._demo.Demo(globals(), 'fourc')

View File

@@ -0,0 +1,213 @@
from diffcalc.util import x_rotation, y_rotation, z_rotation, TORAD, TODEG
from startup._common_imports import *
from diffcalc.hkl.you.geometry import YouGeometry, YouPosition
try:
from numpy import matrix
except ImportError:
from numjy import matrix
if not GDA:
import startup._demo
class FiveCircleI13(YouGeometry):
"""For a diffractometer with angles:
delta, gamma, eta, chi, phi
"""
def __init__(self, beamline_axes_transform=None):
YouGeometry.__init__(self, 'diffcalc_fivec', {'mu': 0}, beamline_axes_transform)
def physical_angles_to_internal_position(self, physical_angle_tuple):
# mu, delta, nu, eta, chi, phi
delta_phys, gam_phys, eta_phys, chi_phys, phi_phys = physical_angle_tuple
return YouPosition(0, delta_phys, gam_phys, -eta_phys, -chi_phys, -phi_phys, 'DEG')
def internal_position_to_physical_angles(self, internal_position):
clone_position = internal_position.clone()
clone_position.changeToDegrees()
_, delta_phys, gam_phys, eta_phys, chi_phys, phi_phys = clone_position.totuple()
return delta_phys, gam_phys, -eta_phys, -chi_phys, -phi_phys
if '_fivec' in globals() and 'en' in globals():
# Assume we are running in a live GDA deployment with a _fivec ScannableGroup
# with axes named: delta, gam, eta, chi, phi.
# Ensure that these five Scannables exist.
# There must also be Scannable en for moving and reading the energy
print "Diffcalc using predefined _fivec and en Scannables"
else:
### Create dummy scannables ###
print "Diffcalc creating dummy Scannables as _fivec and en were not found"
delta = Dummy('delta')
gam = Dummy('gam')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
_fivec = ScannableGroup('_fivec', (delta, gam, eta, chi, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_fivec, en, ESMTGKeV)
beamline_axes_transform = matrix([[0, 0, 1],[1, 0, 0], [0, 1, 0,]])
settings.geometry = FiveCircleI13(beamline_axes_transform=beamline_axes_transform)
settings.energy_scannable = en
settings.axes_scannable_group = _fivec
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
# lastub()
#
# setmax(delta, 28)
# setmin(delta, -1)
# setmin(gam, 0)
# setmax(gam, 16)
# setmin(eta, -10)
# setmax(eta, 10)
# setmin(chi, 90 - 12)
# setmax(chi, 90 + 12)
# setmin(phi, -88)
# setmax(phi, 88)
# setcut(phi, -90)
# hardware()
if not GDA:
setmax(delta, 90)
setmin(delta, -1)
setmin(gam, 0)
setmax(gam, 90)
setmin(eta, -90)
setmax(eta, 90)
setmin(chi, -10)
setmax(chi, 100)
setmin(phi, -88)
setmax(phi, 88)
setcut(phi, -90)
hardware()
#def X(th_deg):
# return x_rotation(th_deg * TORAD)
#
#
#def Y(th_deg):
# return y_rotation(th_deg * TORAD)
#
#
#def Z(th_deg):
# return z_rotation(th_deg * TORAD)
#
#
#WEDGE = X(15)
if not GDA:
demo = startup._demo.Demo(globals(), 'fivec')
"""
Fivec, no real limits, working out U matrix
===========================================
U = xyz_rotation([-0.70711, 0.70711, 0.00000], 54.73561 * TORAD)
setu U
pos en 20
con qaz 90
con a_eq_b
UBCALC
name: 2017-03-07-i13
n_phi: -0.00000 -0.00000 1.00000
n_hkl: 0.57735 0.57735 0.57735 <- set
miscut:
angle: 0.00003
axis: 0.70711 -0.70711 0.00000
CRYSTAL
name: Si111
a, b, c: 5.43000 5.43000 5.43000
90.00000 90.00000 90.00000
B matrix: 1.15712 0.00000 0.00000
0.00000 1.15712 0.00000
0.00000 0.00000 1.15712
UB MATRIX
U matrix: 0.78868 -0.21133 -0.57735
-0.21132 0.78867 -0.57735
0.57735 0.57735 0.57735
angle: 54.73564
axis: 0.70711 -0.70711 0.00000
UB matrix: 0.91260 -0.24453 -0.66807
-0.24453 0.91259 -0.66807
0.66807 0.66807 0.66807
REFLECTIONS
ENERGY H K L DELTA GAM ETA CHI PHI TAG
1 20.000 1.00 1.00 1.00 11.3483 0.0000 5.6741 90.0000 45.0000
2 20.000 4.00 0.00 0.00 26.3978 0.0000 13.1989 35.2644 -15.0000
In [80]: listub
UB calculations in: /Users/zrb13439/.diffcalc/i13
0) 2017-03-07-i13 14 Mar 2017 (14:35)
1) test 07 Mar 2017 (11:38)
In [81]: hardware
-1.0 <= delta <= 90.0 (cut: -180.0)
0.0 <= gam <= 90.0 (cut: -180.0)
-90.0 <= eta <= 90.0 (cut: -180.0)
-10.0 <= chi <= 100.0 (cut: -180.0)
-180.0 <= phi <= 180.0 (cut: -90.0)
Note: When auto sector/transforms are used,
cuts are applied before checking limits.
Add in delta and gamma constraintss:
In [85]: atan(28/16)*TODEG
Out[85]: 45.0
In [86]: atan(28/16.)*TODEG
Out[86]: 60.25511870305777
In [87]: con qaz 60
qaz : 60.0000
a_eq_b
mu : 0.0000
In [88]: sim hkl [4 0 0]
_fivec would move to:
delta : 22.6459
gam : 13.9379
eta : 59.2132
chi : 8.8270
phi : -63.0717
alpha : 7.5752
beta : 7.5752
naz : 4.5446
psi : 90.0000
qaz : 60.0000
tau : 54.7356
theta : 13.1989
"""

View File

@@ -0,0 +1,79 @@
from startup._common_imports import *
from diffcalc.hkl.you.geometry import YouPosition
import diffcalc.hkl.you.geometry
if not GDA:
import startup._demo
LOCAL_MANUAL = 'http://confluence.diamond.ac.uk/display/I16/Diffcalc%20(i16)'
class SixCircleI16(diffcalc.hkl.you.geometry.YouGeometry):
def __init__(self):
diffcalc.hkl.you.geometry.YouGeometry.__init__(self, 'sixc', {})
def physical_angles_to_internal_position(self, physical_angle_tuple):
# i16: phi, chi, eta, mu, delta, gam
# H. You: mu, delta, nu, eta, chi, phi
phi_phys, chi_phys, eta_phys, mu_phys, delta_phys, gam_phys = physical_angle_tuple
return YouPosition(mu_phys, delta_phys, gam_phys, eta_phys, chi_phys, phi_phys, unit='DEG')
def internal_position_to_physical_angles(self, internal_position):
clone_position = internal_position.clone()
clone_position.changeToDegrees()
mu_phys, delta_phys, nu_phys, eta_phys, chi_phys, phi_phys = clone_position.totuple()
return phi_phys, chi_phys, eta_phys, mu_phys, delta_phys, nu_phys
if GDA:
from scannable.extraNameHider import ExtraNameHider
dummy_energy = Dummy('dummy_energy')
simple_energy = ExtraNameHider('energy', dummy_energy) # @UndefinedVariable
if 'euler' not in locals():
raise Exception('Expecting a device called euler')
else: # Assume running in dummy mode outside GDA
mu = Dummy('mu')
delta = Dummy('delta')
gam = Dummy('gam')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
euler = ScannableGroup('euler', (phi, chi, eta, mu, delta, gam))
en = simple_energy = Dummy('energy')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(euler, simple_energy, ESMTGKeV)
settings.geometry = SixCircleI16()
settings.energy_scannable = simple_energy
settings.axes_scannable_group= euler
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.hkl.you.persistence import YouStateEncoder
settings.ubcalc_persister = UBCalculationJSONPersister(diffcalc.settings.ubcalc_persister.directory,
YouStateEncoder)
from diffcalc.gdasupport.you import * # @UnusedWildImport
hkl.setLevel(6)
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
lastub() # Load the last ub calculation used
from startup.beamlinespecific.azihkl import AzihklClass
azihkl=AzihklClass('aziref')
azihkl()
# iPython removes the actual command from namespace
if not GDA:
diffcalc.hardware.setrange(chi, -2, 100)
diffcalc.hardware.setrange(eta, -2, 92)
diffcalc.hardware.setrange(delta, -2, 145)
diffcalc.hardware.setrange(gam, -2, 145)
setcut(phi, -180)
demo = startup._demo.Demo(globals(), 'i16')

View File

@@ -0,0 +1,495 @@
from startup._common_imports import * # @UnusedWildImport
from diffcalc.gdasupport.minigda.scannable import ScannableMotionWithScannableFieldsBase # @UnusedImport
from startup.beamlinespecific.i21 import FourCircleI21, I21SampleStage, I21TPLab
from diffcalc.gdasupport.scannable.diffractometer import DiffractometerScannableGroup
try:
from numpy import matrix
except ImportError:
from numjy import matrix
if not GDA:
import startup._demo
else:
# import __main__ # @UnresolvedImport
from __main__ import x,y,z,th,chi,phi,difftth,m5tth, energy, simx,simy,simz,simth,simchi,simphi,simdelta,simm5tth # @UnresolvedImport
LOCAL_MANUAL = "http://confluence.diamond.ac.uk/x/UoIQAw"
# Diffcalc i21
# ======== ===
# delta difftth or m5tth
# eta th
# chi chi
# phi -phi
SIM_MODE=False
### Create dummy scannables ###
if GDA:
xyz_eta = ScannableGroup('xyz_eta', [x, y, z]) # @UndefinedVariable
else:
delta = Dummy('delta')
m5tth = Dummy('m5tth')
th = Dummy('th')
chi = Dummy('chi')
phi = Dummy('phi')
x = Dummy('x')
y = Dummy('y')
z = Dummy('z')
xyz_eta = ScannableGroup('xyz_eta', [x, y, z])
#support i21 non-concentric rotation motions
sa = I21SampleStage('sa', th, chi, phi, xyz_eta)
#th = sa.th
#chi = sa.chi
#phi = sa.phi
tp_phi = sa.tp_phi_scannable
tp_lab = I21TPLab('tp_lab', sa)
tp_labx = tp_lab.tp_labx
tp_laby = tp_lab.tp_laby
tp_labz = tp_lab.tp_labz
### Wrap i21 names to get diffcalc names - sample chamber
if GDA:
en=energy
if float(en.getPosition()) == 0: # no energy value - dummy?
en(800)
simenergy = Dummy('en')
simenergy(800)
else:
en = simenergy = Dummy('en')
en(800)
en.level = 3
simenergy.level = 3
### Configure and import diffcalc objects ###
beamline_axes_transform = matrix('0 0 -1; 0 1 0; 1 0 0')
_lowq_geometry = FourCircleI21(beamline_axes_transform=beamline_axes_transform, delta_offset=-4.)
_highq_geometry = FourCircleI21(beamline_axes_transform=beamline_axes_transform, delta_offset=4.)
_tth_geometry = FourCircleI21(beamline_axes_transform=beamline_axes_transform)
if GDA:
_sc_difftth = ScannableGroup('_fourc', (difftth, th, chi, phi))
_sc_m5tth = ScannableGroup('_fourc', (m5tth, th, chi, phi))
_sc_sim = ScannableGroup('_fourc', (simdelta, simth, simchi, simphi))
else:
_sc_difftth = _sc_m5tth = _sc_sim = ScannableGroup('_fourc', (delta, th, chi, phi))
ESMTGKeV = 0.001
_hw_difftth = ScannableHardwareAdapter(_sc_difftth, en, ESMTGKeV)
_hw_m5tth = ScannableHardwareAdapter(_sc_m5tth, en, ESMTGKeV)
_hw_sim = ScannableHardwareAdapter(_sc_sim, simenergy, ESMTGKeV)
settings.hardware = _hw_difftth
settings.geometry = _tth_geometry
settings.energy_scannable = en
settings.axes_scannable_group = _sc_difftth
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
### Load the last ub calculation used
from diffcalc.ub.ub import lastub
lastub()
### Set i21 specific limits
print "INFO: diffcalc limits set in $diffcalc/startup/i21.py taken from http://confluence.diamond.ac.uk/pages/viewpage.action?pageId=51413586"
def setLimitsAndCuts(delta_angle, eta_angle, chi_angle, phi_angle):
''' set motor limits for diffcalc, these are within the actual motor limits
'''
if not GDA:
setmin(delta_angle, 0.0)
setmax(delta_angle, 180.0) #default to diode delta limits
setmin(chi_angle, -41.0)
setmax(chi_angle, 36.0)
setmin(eta_angle, 0.0)
setmax(eta_angle, 150.0)
setmin(phi_angle, -100.0)
setmax(phi_angle, 100.0)
#http://jira.diamond.ac.uk/browse/I21-361
setcut(eta_angle, 0.0)
setcut(phi_angle, -180.0)
print "Current hardware limits set to:"
hardware()
if GDA:
setLimitsAndCuts(difftth, th, chi, phi)
else:
setLimitsAndCuts(delta, th, chi, phi)
### Create i21 bespoke secondary hkl devices
# Warning: this breaks the encapsulation provided by the diffcalc.dc.you public
# interface, and may be prone to breakage in future.
print 'Creating i21 bespoke scannables:'
hkl_m5tth = Hkl('hkl_m5tth', _sc_m5tth, DiffractometerYouCalculator(_hw_m5tth, _tth_geometry))
hkl_lowq = Hkl('hkl_lowq', _sc_m5tth, DiffractometerYouCalculator(_hw_m5tth, _lowq_geometry))
hkl_highq = Hkl('hkl_highq', _sc_m5tth, DiffractometerYouCalculator(_hw_m5tth, _highq_geometry))
hkl_difftth = Hkl('hkl_difftth', _sc_difftth, DiffractometerYouCalculator(_hw_difftth, _tth_geometry))
hkl_sim = Hkl('hkl_sim', _sc_sim, DiffractometerYouCalculator(_hw_sim, _tth_geometry))
def usem5tth():
print '- setting hkl ---> hkl_m5tth'
global settings
settings.hardware = _hw_m5tth
settings.geometry = _tth_geometry
settings.axes_scannable_group = _sc_m5tth
# Create diffractometer scannable
_diff_scn_name = _tth_geometry.name
_diff_scn = DiffractometerScannableGroup(_diff_scn_name, _dc, _sc_m5tth)
setLimitsAndCuts(m5tth, th, chi, phi)
import __main__
__main__.hkl = hkl_m5tth
__main__.fourc = _diff_scn
if GDA:
__main__.en = energy
def uselowq():
print '- setting hkl ---> hkl_lowq'
global settings
settings.hardware = _hw_m5tth
settings.geometry = _lowq_geometry
settings.axes_scannable_group = _sc_m5tth
# Create diffractometer scannable
_diff_scn_name = _lowq_geometry.name
_diff_scn = DiffractometerScannableGroup(_diff_scn_name, _dc, _sc_m5tth)
setLimitsAndCuts(m5tth, th, chi, phi)
import __main__
__main__.hkl = hkl_lowq
__main__.fourc = _diff_scn
if GDA:
__main__.en = energy
def usehighq():
print '- setting hkl ---> hkl_highq'
global settings
settings.hardware = _hw_m5tth
settings.geometry = _highq_geometry
settings.axes_scannable_group = _sc_m5tth
setLimitsAndCuts(m5tth, th, chi, phi)
# Create diffractometer scannable
_diff_scn_name = _highq_geometry.name
_diff_scn = DiffractometerScannableGroup(_diff_scn_name, _dc, _sc_m5tth)
import __main__
__main__.hkl = hkl_highq
__main__.fourc = _diff_scn
if GDA:
__main__.en = energy
def usedifftth():
# sample chamber
print '- setting hkl ---> hkl_difftth'
global settings
settings.hardware = _hw_difftth
settings.geometry = _tth_geometry
settings.axes_scannable_group = _sc_difftth
# Create diffractometer scannable
_diff_scn_name = _tth_geometry.name
_diff_scn = DiffractometerScannableGroup(_diff_scn_name, _dc, _sc_difftth)
setLimitsAndCuts(difftth, th, chi, phi)
import __main__
__main__.hkl = hkl_difftth
__main__.fourc = _diff_scn
if GDA:
__main__.en = energy
def usesim():
# sample chamber
print '- setting hkl ---> hkl_sim'
print '- en ---> simenergy'
global settings
settings.hardware = _hw_sim
settings.geometry = _tth_geometry
settings.axes_scannable_group = _sc_sim
setLimitsAndCuts(simdelta, simth, simchi, simphi)
# Create diffractometer scannable
_diff_scn_name = _tth_geometry.name
_diff_scn = DiffractometerScannableGroup(_diff_scn_name, _dc, _sc_sim)
import __main__
__main__.hkl = hkl_sim
__main__.fourc = _diff_scn
if GDA:
__main__.en = simenergy
def centresample():
sa.centresample()
def zerosample():
'''zero on the currently centred sample location
'''
sa.zerosample()
def toolpoint_on():
'''Switch on tool point
'''
sa.centre_toolpoint = True
def toolpoint_off():
'''Switch off tool point
'''
sa.centre_toolpoint = False
print "Created i21 bespoke commands: usem5tth, uselowq, usehighq, usedifftth, usesim, centresample, zerosample, toolpoint_on, toolpoint_off"
if GDA:
def switchMotors(sax, say, saz, sath, sachi, saphi, diodedelta, specm5tth):
import __main__
__main__.xyz_eta = ScannableGroup('xyz_eta', [sax, say, saz]) # @UndefinedVariable
#update support for i21 non-concentric rotation motions
__main__.sa = I21SampleStage('sa', sath, sachi, saphi,__main__.xyz_eta) # @UndefinedVariable
__main__.tp_phi = sa.tp_phi_scannable
__main__.tp_lab = I21TPLab('tp_lab', __main__.sa) # @UndefinedVariable
__main__.tp_labx = __main__.tp_lab.tp_labx # @UndefinedVariable
__main__.tp_laby = __main__.tp_lab.tp_laby # @UndefinedVariable
__main__.tp_labz = __main__.tp_lab.tp_labz # @UndefinedVariable
### update Wrap i21 names to get diffcalc names
_fourc = ScannableGroup('_fourc', (diodedelta, sath, sachi, saphi)) # I21DiffractometerStage('_fourc', diodedelta, __main__.sa) # @UndefinedVariable
#update diffcalc objects
__main__.settings.hardware = ScannableHardwareAdapter(_fourc, __main__.en, ESMTGKeV) # @UndefinedVariable
__main__.settings.geometry = FourCircleI21(beamline_axes_transform=beamline_axes_transform) # @UndefinedVariable
__main__.settings.energy_scannable = __main__.en # @UndefinedVariable
__main__.settings.axes_scannable_group= _fourc
__main__.settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
__main__.fourc=DiffractometerScannableGroup('fourc', _dc, _fourc)
__main__.hkl = Hkl('hkl', _fourc, _dc)
__main__.h, __main__.k, __main__.l = hkl.h, hkl.k, hkl.l
from diffcalc.gdasupport.you import _virtual_angles
from diffcalc.gdasupport.scannable.simulation import SimulatedCrystalCounter
from diffcalc.gdasupport.scannable.wavelength import Wavelength
__main__.hklverbose = Hkl('hklverbose', _fourc, _dc, _virtual_angles)
__main__.wl = Wavelength('wl',__main__.en,ESMTGKeV) # @UndefinedVariable
__main__.ct = SimulatedCrystalCounter('ct', _fourc, __main__.settings.geometry,__main__.wl) # @UndefinedVariable
#update scannales: fourc_vessel & hkl_vessel'
_fourc_vessel = ScannableGroup('_fourc', (specm5tth, sath, sachi, saphi)) # I21DiffractometerStage('_fourc_vessel', m5tth, sa)
__main__.fourc_vessel = DiffractometerScannableGroup('fourc_vessel', _dc, _fourc_vessel)
__main__.hkl_vessel = Hkl('hkl_vessel', _fourc_vessel, _dc)
__main__.h_vessel, __main__.k_vessel, __main__.l_vessel = hkl_vessel.h, hkl_vessel.k, hkl_vessel.l
#Update scannables: fourc_lowq & hkl_lowq'
_fourc_lowq = ScannableGroup('_fourc', (specm5tth, sath, sachi, saphi)) #I21DiffractometerStage('_fourc_lowq', m5tth, sa,delta_offset=LOWQ_OFFSET_ADDED_TO_DELTA_WHEN_READING)
__main__.fourc_lowq = DiffractometerScannableGroup('fourc_lowq', _dc, _fourc_lowq)
__main__.hkl_lowq = Hkl('hkl_lowq', _fourc_lowq, _dc)
__main__.h_lowq, __main__.k_lowq, __main__.l_lowq = hkl_lowq.h, hkl_lowq.k, hkl_lowq.l
#Update scannables: fourc_highq & hkl_highq'
_fourc_highq = ScannableGroup('_fourc', (specm5tth, sath, sachi, saphi)) #I21DiffractometerStage('_fourc_highq', m5tth, sa,delta_offset=highq_OFFSET_ADDED_TO_DELTA_WHEN_READING)
__main__.fourc_highq = DiffractometerScannableGroup('fourc_highq', _dc, _fourc_highq)
__main__.hkl_highq = Hkl('hkl_highq', _fourc_highq, _dc)
__main__.h_highq, __main__.k_highq, __main__.l_highq = hkl_highq.h, hkl_highq.k, hkl_highq.l
#Update scannables: fourc_diode & hkl_diode'
_fourc_diode = ScannableGroup('_fourc', (diodedelta, sath, sachi, saphi)) #I21DiffractometerStage('_fourc_diode', delta, sa)
__main__.fourc_diode = DiffractometerScannableGroup('fourc_diode', _dc, _fourc_diode)
__main__.hkl_diode = Hkl('hkl_diode', _fourc_diode, _dc)
__main__.h_diode, __main__.k_diode, __main__.l_diode = hkl_diode.h, hkl_diode.k, hkl_diode.l
def stopMotors(sax, say, saz, sath, sachi, saphi, diodedelta, specm5tth):
sax.stop()
say.stop()
saz.stop()
sath.stop()
sachi.stop()
saphi.stop()
diodedelta.stop()
specm5tth.stop()
def simdc():
''' switch to use dummy motors in diffcalc
'''
print "Stop real motors"
if GDA:
stopMotors(x, y, z, th, chi, phi, difftth, m5tth)
else:
stopMotors(x, y, z, th, chi, phi, delta, m5tth)
global SIM_MODE
SIM_MODE=True
import __main__
__main__.en=Dummy("en")
print "Set energy to 12398.425 eV in simulation mode!"
__main__.en(12398.425) #1 Angstrom wavelength @UndefinedVariable
print "Switch to simulation motors"
switchMotors(simx,simy,simz,simth,simchi,simphi,simdelta,simm5tth)
# __main__.th = __main__.sa.simth # @UndefinedVariable
# __main__.chi = __main__.sa.simchi # @UndefinedVariable
# __main__.phi = __main__.sa.simphi # @UndefinedVariable
setLimitsAndCuts(simdelta,simth,simchi,simphi)
def realdc():
''' switch to use real motors in diffcalc
'''
print "Stop simulation motors"
stopMotors(simx,simy,simz,simth,simchi,simphi,simdelta,simm5tth)
global SIM_MODE
SIM_MODE=False
import __main__
print "Set energy to current beamline energy in real mode!"
__main__.en=energy
print "Switch to real motors"
if GDA:
switchMotors(x,y,z,th,chi,phi,difftth,m5tth)
setLimitsAndCuts(difftth,th,chi,phi)
else:
switchMotors(x,y,z,th,chi,phi,delta,m5tth)
setLimitsAndCuts(delta,th,chi,phi)
from gda.jython.commands.GeneralCommands import alias # @UnresolvedImport
alias("usem5tth")
alias("uselowq")
alias("usehighq")
alias("usedifftth")
alias("usesim")
alias("centresample")
alias("zerosample")
alias("toolpoint_on")
alias("toolpoint_off")
print "Created i21 bespoke commands: simdc, realdc"
alias("simdc")
alias("realdc")
else:
from IPython.core.magic import register_line_magic # @UnresolvedImport
from diffcmd.ipython import parse_line
if IPYTHON:
from IPython import get_ipython # @UnresolvedImport @UnusedImport
register_line_magic(parse_line(usem5tth, globals()))
del usem5tth
register_line_magic(parse_line(uselowq, globals()))
del uselowq
register_line_magic(parse_line(usehighq, globals()))
del usehighq
register_line_magic(parse_line(usedifftth, globals()))
del usedifftth
register_line_magic(parse_line(usesim, globals()))
del usesim
register_line_magic(parse_line(centresample, globals()))
del centresample
register_line_magic(parse_line(zerosample, globals()))
del zerosample
register_line_magic(parse_line(toolpoint_on, globals()))
del toolpoint_on
register_line_magic(parse_line(toolpoint_off, globals()))
del toolpoint_off
### Demo ###
if not GDA:
class I21Demo(startup._demo.Demo):
def __init__(self, namespace):
startup._demo.Demo.__init__(self, namespace, 'i21')
def i21(self):
startup._demo.print_heading('i21 scannables demo')
self.echorun_magiccmd_list([
'sa',
'pos th 1',
'pos chi 2',
'pos phi 3',
'pos m5tth 4',
'usem5tth',
'fourc'])
demo = I21Demo(globals())
else:
print "DIFFCALC demo:"
class I21Demo(object):
def __init__(self, namespace):
self.namespace = namespace
def all(self):
self.orient()
self.constrain()
self.scan()
def remove_test_ubcalc(self):
try:
eval("rmub('test')", self.namespace)
except (OSError, KeyError):
pass
def executeCommand(self, cmd_list):
for cmd in cmd_list:
if cmd == 'help ub':
print("help ub")
exec("print ub.__doc__", self.namespace)
elif cmd == 'help hkl':
print("help(hkl)")
exec("print hkl.__doc__", self.namespace)
else:
exec(cmd, self.namespace)
def orient(self):
print
print "-"*100
print 'Orientation demo'
print
self.remove_test_ubcalc()
cmd_list=[
'help ub',
"from gda.jython.commands.ScannableCommands import pos; pos(wl, 10)",
"newub('test')",
"setlat('cubic', 1,1, 1, 90, 90, 90)",
'ub',
'c2th([0, 0, .1])',
'from gda.jython.commands.ScannableCommands import pos; pos(fourc, [60, 30, 0, 0])',
'addref([0, 0, .1])',
'c2th([0, .1, .1])',
'from gda.jython.commands.ScannableCommands import pos; pos(fourc, [90, 90, 0, 0])',
'addref([0, .1, .1])',
'ub',
'checkub']
self.executeCommand(cmd_list)
def constrain(self):
print
print "-"*100
print 'Constraint demo'
print
cmd_list=[
'help hkl',
'con(a_eq_b)',
'con']
self.executeCommand(cmd_list)
def scan(self):
print
print "-"*100
print 'Scanning demo'
print
cmd_list=[
'setnphi([0, 0, 1])',
'pos hkl([0, 0, .1])',
'scan(difftth, 40, 90, 10, hkl, ct, 1)',
'pos(hkl, [0, .1, 0])',
'scan(h, 0, .1, .02, k, l, fourc, ct, 1)',
'con(psi)',
'scan(psi, 0, 90, 10, hkl, [.1, 0, .1], th, chi, phi, ct, .1)']
self.executeCommand(cmd_list)

View File

@@ -0,0 +1,37 @@
from startup._common_imports import *
import startup._demo
### Create dummy scannables ###
mu = Dummy('mu')
delta = Dummy('delta')
gam = Dummy('gam')
eta = Dummy('eta')
chi = Dummy('chi')
phi = Dummy('phi')
_sixc = ScannableGroup('_sixc', (mu, delta, gam, eta, chi, phi))
en = Dummy('en')
en.level = 3
### Configure and import diffcalc objects ###
ESMTGKeV = 1
settings.hardware = ScannableHardwareAdapter(_sixc, en, ESMTGKeV)
settings.geometry = diffcalc.hkl.you.geometry.SixCircle() # @UndefinedVariable
settings.energy_scannable = en
settings.axes_scannable_group= _sixc
settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
from diffcalc.gdasupport.you import * # @UnusedWildImport
if GDA:
print "Running in GDA --- aliasing commands"
alias_commands(globals())
# Load the last ub calculation used
lastub()
# Set some limits
setmin('gam', -179)
setmax('gam', 179)
demo = startup._demo.Demo(globals(), 'sixc')