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

@@ -0,0 +1,200 @@
###
# 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 diffcalc.hkl.you.calc import YouUbCalcStrategy
from diffcalc.hkl.you.geometry import SixCircle, YouPosition
from diffcalc.ub.calc import UBCalculation
from diffcalc.ub.persistence import UBCalculationJSONPersister
from diffcalc.ub.calcstate import UBCalcStateEncoder
from math import pi, sqrt, atan2
from mock import Mock
from nose.tools import eq_
from test.tools import matrixeq_
import tempfile
import datetime
from diffcalc.util import TORAD, x_rotation
try:
from numpy import matrix
except ImportError:
from numjy import matrix
def posFromI16sEuler(phi, chi, eta, mu, delta, gamma):
return YouPosition(mu, delta, gamma, eta, chi, phi, unit='DEG')
UB1 = matrix(
((0.9996954135095477, -0.01745240643728364, -0.017449748351250637),
(0.01744974835125045, 0.9998476951563913, -0.0003045864904520898),
(0.017452406437283505, -1.1135499981271473e-16, 0.9998476951563912))
) * (2 * pi)
EN1 = 12.39842
REF1a = posFromI16sEuler(1, 1, 30, 0, 60, 0)
REF1b = posFromI16sEuler(1, 91, 30, 0, 60, 0)
class TestUBCalculationWithYouStrategy():
"""Testing the math only here.
"""
def setup_method(self):
self.tempdir = tempfile.mkdtemp()
geometry = SixCircle() # pass through
hardware = Mock()
names = 'm', 'd', 'n', 'e', 'c', 'p'
hardware.get_axes_names.return_value = names
self.tmpdir = tempfile.mkdtemp()
print self.tmpdir
self.ubcalc = UBCalculation(hardware,
geometry,
UBCalculationJSONPersister(self.tmpdir, UBCalcStateEncoder),
YouUbCalcStrategy())
def testAgainstI16Results(self):
self.ubcalc.start_new('cubcalc')
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', None)
matrixeq_(self.ubcalc.UB, UB1)
def test_save_and_restore_empty_ubcalc_with_one_already_started(self):
NAME = 'test_save_and_restore_empty_ubcalc_with_one_already_started'
self.ubcalc.start_new(NAME)
self.ubcalc.start_new(NAME)
def test_save_and_restore_empty_ubcalc(self):
NAME = 'test_save_and_restore_empty_ubcalc'
self.ubcalc.start_new(NAME)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
eq_(self.ubcalc.name, NAME)
def test_save_and_restore_ubcalc_with_lattice(self):
NAME = 'test_save_and_restore_ubcalc_with_lattice'
self.ubcalc.start_new(NAME)
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
eq_(self.ubcalc._state.crystal.getLattice(), ('latt', 1, 1, 1, 90, 90, 90))
def test_save_and_restore_ubcalc_with_reflections(self):
NAME = 'test_save_and_restore_ubcalc_with_reflections'
self.ubcalc.start_new(NAME)
now = datetime.datetime.now()
self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', now)
self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', now)
self.ubcalc.add_reflection(0, 0, 1.5, REF1b, EN1, '001_5', now)
ref1 = self.ubcalc.get_reflection(1)
ref2 = self.ubcalc.get_reflection(2)
ref3 = self.ubcalc.get_reflection(3)
eq_(self.ubcalc.get_reflection(1), ref1)
eq_(self.ubcalc.get_reflection(2), ref2)
eq_(self.ubcalc.get_reflection(3), ref3)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
eq_(self.ubcalc.get_reflection(1), ref1)
eq_(self.ubcalc.get_reflection(2), ref2)
eq_(self.ubcalc.get_reflection(3), ref3)
def test_save_and_restore_ubcalc_with_UB_from_two_ref(self):
NAME = 'test_save_and_restore_ubcalc_with_UB_from_two_ref'
self.ubcalc.start_new(NAME)
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', None)
matrixeq_(self.ubcalc.UB, UB1)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
matrixeq_(self.ubcalc.UB, UB1)
def test_save_and_restore_ubcalc_with_UB_from_one_ref(self):
NAME = 'test_save_and_restore_ubcalc_with_UB_from_one_ref'
self.ubcalc.start_new(NAME)
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
self.ubcalc.calculate_UB_from_primary_only()
matrixeq_(self.ubcalc.UB, UB1, places=2)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
matrixeq_(self.ubcalc.UB, UB1, places=2)
def test_save_and_restore_ubcalc_with_manual_ub(self):
NAME = 'test_save_and_restore_ubcalc_with_manual_ub'
UB = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
self.ubcalc.start_new(NAME)
self.ubcalc.set_UB_manually(UB)
matrixeq_(self.ubcalc.UB, UB)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
matrixeq_(self.ubcalc.UB, UB)
def test_save_and_restore_ubcalc_with_manual_u(self):
NAME = 'test_save_and_restore_ubcalc_with_manual_u'
U = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
self.ubcalc.start_new(NAME)
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.set_U_manually(U)
matrixeq_(self.ubcalc.UB, U * 2 * pi)
self.ubcalc.start_new(NAME + '2')
self.ubcalc.load(NAME)
matrixeq_(self.ubcalc.UB, U * 2 * pi)
def test_calc_hkl_offset(self):
NAME = 'test_calc_hkl_offset'
self.ubcalc.start_new(NAME)
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.set_U_manually(x_rotation(0))
hkloff_110 = self.ubcalc.calc_hkl_offset(0, 0, sqrt(2), 90. * TORAD, -45 * TORAD)
hkloff_m101 = self.ubcalc.calc_hkl_offset(0, 0, sqrt(2), 45. * TORAD, 90 * TORAD)
alpha = atan2(2,1)
hkloff_102 = self.ubcalc.calc_hkl_offset(sqrt(5), 0, 0, alpha, 90 * TORAD)
matrixeq_(matrix('1 1 0'), matrix(hkloff_110))
matrixeq_(matrix('-1 0 1'), matrix(hkloff_m101))
matrixeq_(matrix('1 0 2'), matrix(hkloff_102))
def test_calc_offset_for_hkl(self):
NAME = 'test_calc_offset_for_hkl'
self.ubcalc.start_new(NAME)
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.set_U_manually(x_rotation(0))
for hklref, hkloff, pol_ref, az_ref, sc_ref in [([0, 0, 1], [1, 1, 0], 90 * TORAD, -45 * TORAD, sqrt(2)),
([0, 0, 1], [-1, 0, 1], 45 * TORAD, 90 * TORAD, sqrt(2)),
([1, 0, 0], [1, 0, 2], atan2(2,1), 90 * TORAD, sqrt(5)),]:
pol, az , sc = self.ubcalc.calc_offset_for_hkl(hkloff, hklref)
matrixeq_(matrix([[pol_ref, az_ref, sc_ref]]),
matrix([[pol, az, sc]]))

View File

@@ -0,0 +1,382 @@
###
# 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/>.
###
import unittest
from datetime import datetime
from math import cos, sin, pi
from mock import Mock
from nose.tools import raises
try:
from numpy import matrix
except ImportError:
from numjy import matrix
from diffcalc.hkl.vlieg.geometry import SixCircleGammaOnArmGeometry
from diffcalc.hkl.vlieg.geometry import VliegPosition as Pos
from test.tools import matrixeq_, mneq_
from diffcalc.ub.calc import UBCalculation
from diffcalc.ub.persistence import UbCalculationNonPersister
from diffcalc.util import DiffcalcException
from diffcalc.hkl.vlieg.calc import VliegUbCalcStrategy
from test.diffcalc import scenarios
I = matrix('1 0 0; 0 1 0; 0 0 1')
TORAD = pi / 180
class TestUBCalculationWithSixCircleGammaOnArm(object):
def setup_method(self):
self.geometry = SixCircleGammaOnArmGeometry()
mock_hardware = Mock()
mock_hardware.energyScannableMultiplierToGetKeV = 1
mock_hardware.get_axes_names.return_value = ('a', 'd', 'g', 'o', 'c', 'p')
self.ubcalc = UBCalculation(
mock_hardware, self.geometry, UbCalculationNonPersister(),
VliegUbCalcStrategy())
self.time = datetime.now()
### State ###
def testNewCalculation(self):
self.ubcalc.start_new('testcalc')
assert self.ubcalc.name, 'testcalc' == "Name not set by newCalcualtion"
@raises(DiffcalcException)
def testNewCalculationHasNoU(self):
self.ubcalc.start_new('testcalc')
print self.ubcalc.U
@raises(DiffcalcException)
def testNewCalculationHasNoUB(self):
self.ubcalc.start_new('testcalc')
print self.ubcalc.UB
### Lattice ###
def testSetLattice(self):
# Not much to test, just make sure no exceptions
self.ubcalc.start_new('testcalc')
self.ubcalc.set_lattice('testlattice', 4.0004, 4.0004, 2.27, 90, 90, 90)
### Calculations ###
def testset_U_manually(self):
# Test the calculations with U=I
U = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
for sess in scenarios.sessions():
self.setup_method()
self.ubcalc.start_new('testcalc')
self.ubcalc.set_lattice(sess.name, *sess.lattice)
self.ubcalc.set_U_manually(U)
# Check the U matrix
mneq_(self.ubcalc.U, matrix(U), 4,
note="wrong U after manually setting U")
# Check the UB matrix
if sess.bmatrix is None:
continue
print "U: ", U
print "actual ub: ", self.ubcalc.UB.tolist()
print " desired b: ", sess.bmatrix
mneq_(self.ubcalc.UB, matrix(sess.bmatrix), 4,
note="wrong UB after manually setting U")
@raises(DiffcalcException)
def testGetUMatrix(self):
self.ubcalc.start_new('testcalc')
print self.ubcalc.U
@raises(DiffcalcException)
def testGetUBMatrix(self):
self.ubcalc.start_new('testcalc')
print self.ubcalc.UB
def testCalculateU(self):
for sess in scenarios.sessions():
self.setup_method()
self.ubcalc.start_new('testcalc')
# Skip this test case unless it contains a umatrix
if sess.umatrix is None:
continue
self.ubcalc.set_lattice(sess.name, *sess.lattice)
ref1 = sess.ref1
ref2 = sess.ref2
t = sess.time
self.ubcalc.add_reflection(
ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t)
self.ubcalc.add_reflection(
ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t)
self.ubcalc.calculate_UB()
returned = self.ubcalc.U.tolist()
print "*Required:"
print sess.umatrix
print "*Returned:"
print returned
mneq_(self.ubcalc.U, matrix(sess.umatrix), 4,
note="wrong U calulated for sess.name=" + sess.name)
def test__str__(self):
sess = scenarios.sessions()[0]
print "***"
print self.ubcalc.__str__()
print "***"
self.ubcalc.start_new('test')
print self.ubcalc.__str__()
print "***"
self.ubcalc.set_lattice(sess.name, *sess.lattice)
print self.ubcalc.__str__()
print "***"
ref1 = sess.ref1
ref2 = sess.ref2
t = sess.time
self.ubcalc.add_reflection(
ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t)
self.ubcalc.add_reflection(
ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t)
print self.ubcalc.__str__()
print "***"
self.ubcalc.calculate_UB()
print self.ubcalc.__str__()
def x_rotation(mu_or_alpha):
mu_or_alpha *= TORAD
return matrix(((1, 0, 0),
(0, cos(mu_or_alpha), -sin(mu_or_alpha)),
(0, sin(mu_or_alpha), cos(mu_or_alpha))))
def y_rotation(chi):
chi *= TORAD
return matrix(((cos(chi), 0, sin(chi)),
(0, 1, 0),
(-sin(chi), 0, cos(chi))))
def z_rotation(th):
eta = -th * TORAD
return matrix(((cos(eta), sin(eta), 0),
(-sin(eta), cos(eta), 0),
(0, 0, 1)))
CUBIC_EN = 12.39842
CUBIC = (1, 1, 1, 90, 90, 90)
ROT = 29
class TestUBCalcWithCubic(object):
def setup_method(self):
print "TestUBCalcWithCubic.setup_method"
mock_hardware = Mock()
mock_hardware.energyScannableMultiplierToGetKeV = 1
mock_hardware.get_axes_names.return_value = \
('a', 'd', 'g', 'o', 'c', 'p')
self.ubcalc = UBCalculation(mock_hardware,
SixCircleGammaOnArmGeometry(),
UbCalculationNonPersister(),
VliegUbCalcStrategy())
self.ubcalc.start_new('xtalubcalc')
self.ubcalc.set_lattice("xtal", *CUBIC)
self.energy = CUBIC_EN
def addref(self, hklref):
hkl, position = hklref
now = datetime.now()
self.ubcalc.add_reflection(
hkl[0], hkl[1], hkl[2], position, self.energy, "ref", now)
class TestUBCalcWithCubicTwoRef(TestUBCalcWithCubic):
def check(self, testname, hklref1, hklref2, expectedUMatrix):
self.addref(hklref1)
self.addref(hklref2)
matrixeq_(expectedUMatrix, self.ubcalc.U)
def test_with_squarely_mounted(self):
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0, phi=0))
lref = ((0, 0, 1),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90, phi=0))
pairs = (("hl", href, lref, I),
("lh", lref, href, I))
for testname, ref1, ref2, u in pairs:
yield self.check, testname, ref1, ref2, u
def test_with_x_mismount(self):
U = x_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0, phi=0))
kref = ((0, 1, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30 - ROT + 90, chi=90,
phi=0))
lref = ((0, 0, 1),
Pos(alpha=0, delta=60, gamma=0, omega=30 - ROT, chi=90, phi=0))
pairs = (("hk", href, kref, U),
("hl", href, lref, U),
("kh", kref, href, U),
("kl", kref, lref, U),
("lk", lref, kref, U),
("lh", lref, href, U))
for testname, ref1, ref2, u in pairs:
yield self.check, testname, ref1, ref2, u
def test_with_y_mismount(self):
U = y_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0 - ROT, phi=0))
lref = ((0, 0, 1),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90 - ROT, phi=0))
pairs = (("hl", href, lref, U),
("lh", lref, href, U))
for testname, ref1, ref2, u in pairs:
yield self.check, testname, ref1, ref2, u
def test_with_z_mismount(self):
U = z_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0, phi=0 + ROT))
lref = ((0, 0, 1), # phi degenerate
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90, phi=67))
pairs = (("hl", href, lref, U),
("lh", lref, href, U))
for testname, ref1, ref2, u in pairs:
yield self.check, testname, ref1, ref2, u
def test_with_zy_mismount(self):
U = z_rotation(ROT) * y_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0 - ROT,
phi=0 + ROT))
lref = ((0, 0, 1),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90 - ROT,
phi=ROT)) # chi degenerate
pairs = (("hl", href, lref, U),
("lh", lref, href, U))
for testname, ref1, ref2, u in pairs:
yield self.check, testname, ref1, ref2, u
class TestUBCalcWithcubicOneRef(TestUBCalcWithCubic):
def check(self, testname, hklref, expectedUMatrix):
print testname
self.addref(hklref)
self.ubcalc.calculate_UB_from_primary_only()
matrixeq_(expectedUMatrix, self.ubcalc.U)
def test_with_squarely_mounted(self):
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0, phi=0))
href_b = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30 + 90, chi=90,
phi=-90))
lref = ((0, 0, 1), # degenerate in phi
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90, phi=67))
pairs = (("h", href, I),
("hb", href_b, I),
("l", lref, I))
for testname, ref, u in pairs:
yield self.check, testname, ref, u
def test_with_x_mismount_h(self):
U = x_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0, phi=0))
self.check("h", href, I)
def test_with_x_mismount_k(self):
U = x_rotation(ROT)
kref = ((0, 1, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30 - ROT + 90, chi=90,
phi=0))
self.check("k", kref, U)
def test_with_x_mismount_l(self):
U = x_rotation(ROT)
lref = ((0, 0, 1),
Pos(alpha=0, delta=60, gamma=0, omega=30 - ROT, chi=90, phi=0))
self.check("l", lref, U)
def test_with_y_mismount_h(self):
U = y_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0 - ROT, phi=0))
self.check("h", href, U)
def test_with_y_mismount_k(self):
U = y_rotation(ROT)
kref = ((0, 1, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30 + 90, chi=90, phi=0))
self.check("k", kref, I) # TODO: can't pass - word instructions
def test_with_y_mismount_l(self):
U = y_rotation(ROT)
lref = ((0, 0, 1),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90 - ROT, phi=0))
self.check("l", lref, U)
def test_with_z_mismount_h(self):
U = z_rotation(ROT)
href = ((1, 0, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0, phi=0 + ROT))
self.check("h", href, U)
def test_with_z_mismount_k(self):
U = z_rotation(ROT)
kref = ((0, 1, 0),
Pos(alpha=0, delta=60, gamma=0, omega=30 + 90, chi=0,
phi=0 + ROT))
self.check("k", kref, U),
def test_with_z_mismount_l(self):
U = z_rotation(ROT)
lref = ((0, 0, 1), # phi degenerate
Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90, phi=67))
self.check("l", lref, I) # TODO: can't pass - word instructions
#Probably lost cause, conclusion is be careful and return the angle and
#direction of resulting u matrix
# def skip_test_with_zy_mismount(self):
# U = z_rotation(ROT) * y_rotation(ROT)
# href = ((1, 0, 0),
# Pos(alpha=0, delta=60, gamma=0, omega=30, chi=0 - ROT,
# phi=0 + ROT))
# kref = ((0, 1, 0),
# Pos(alpha=0, delta=60, gamma=0, omega=30 + 90, chi=90 - ROT,
# phi=0 + ROT))
# lref = ((0, 0, 1),
# Pos(alpha=0, delta=60, gamma=0, omega=30, chi=90 - ROT,
# phi=ROT)) # chi degenerate
# pairs = (("h", href, U),
# ("k", kref, U),
# ("l", lref, U))
# for testname, ref, u in pairs:
# yield self.check, testname, ref, u

View File

@@ -0,0 +1,83 @@
###
# 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 math import pi
from mock import Mock
try:
from numpy import matrix
except ImportError:
from numjy import matrix
from diffcalc.hkl.you.geometry import SixCircle
from diffcalc.hkl.you.geometry import YouPosition
from diffcalc.hkl.you.calc import YouUbCalcStrategy
from test.tools import matrixeq_
from diffcalc.ub.calc import UBCalculation
from diffcalc.ub.persistence import UbCalculationNonPersister
#newub 'cubic' <--> reffile('cubic)
#setlat 'cubic' 1 1 1 90 90 90 <--> latt([1,1,1,90,90,90])
#pos wl 1 <--> BLi.setWavelength(1)
# <--> c2th([0,0,1]) --> 60
#pos sixc [0 60 0 30 1 1] <--> pos euler [1 1 30 0 60 0]
#addref 1 0 0 <--> saveref('100',[1, 0, 0])
#pos chi 91 <-->
#addref 0 0 1 <--> saveref('100',[1, 0, 0]) ; showref()
# ubm('100','001')
# ubm() ->
#array('d', [0.9996954135095477, -0.01745240643728364, -0.017449748351250637,
#0.01744974835125045, 0.9998476951563913, -0.0003045864904520898,
#0.017452406437283505, -1.1135499981271473e-16, 0.9998476951563912])
def posFromI16sEuler(phi, chi, eta, mu, delta, gamma):
return YouPosition(mu, delta, gamma, eta, chi, phi, unit='DEG')
UB1 = matrix(
((0.9996954135095477, -0.01745240643728364, -0.017449748351250637),
(0.01744974835125045, 0.9998476951563913, -0.0003045864904520898),
(0.017452406437283505, -1.1135499981271473e-16, 0.9998476951563912))
) * (2 * pi)
EN1 = 12.39842
REF1a = posFromI16sEuler(1, 1, 30, 0, 60, 0)
REF1b = posFromI16sEuler(1, 91, 30, 0, 60, 0)
class TestUBCalculationWithYouStrategy():
"""Testing the math only here.
"""
def setup_method(self):
geometry = SixCircle() # pass through
hardware = Mock()
names = 'm', 'd', 'n', 'e', 'c', 'p'
hardware.get_axes_names.return_value = names
self.ubcalc = UBCalculation(hardware,
geometry,
UbCalculationNonPersister(),
YouUbCalcStrategy())
def testAgainstI16Results(self):
self.ubcalc.start_new('cubcalc')
self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', None)
self.ubcalc.calculate_UB()
matrixeq_(self.ubcalc.UB, UB1)

View File

@@ -0,0 +1,62 @@
###
# 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/>.
###
import unittest
try:
from numpy import matrix
except ImportError:
from numjy import matrix
from test.tools import assert_dict_almost_equal, mneq_
from diffcalc.ub.crystal import CrystalUnderTest
from test.diffcalc import scenarios
class TestCrystalUnderTest(object):
def setup_method(self):
self.tclatt = []
self.tcbmat = []
# From the dif_init.mat next to dif_dos.exe on Vlieg's cd
#self.tclatt.append([4.0004, 4.0004, 2.270000, 90, 90, 90])
#self.tcbmat.append([[1.570639, 0, 0] ,[0.0, 1.570639, 0] ,
# [0.0, 0.0, 2.767923]])
# From b16 on 27June2008 (From Chris Nicklin)
# self.tclatt.append([3.8401, 3.8401, 5.43072, 90, 90, 90])
# self.tcbmat.append([[1.636204, 0, 0],[0, 1.636204, 0],
# [0, 0, 1.156971]])
def testGetBMatrix(self):
# Check the calculated B Matrix
for sess in scenarios.sessions():
if sess.bmatrix is None:
continue
cut = CrystalUnderTest('tc', *sess.lattice)
desired = matrix(sess.bmatrix)
print desired.tolist()
answer = cut.B
print answer.tolist()
note = "Incorrect B matrix calculation for scenario " + sess.name
mneq_(answer, desired, 4, note=note)
def test__str__(self):
cut = CrystalUnderTest("HCl", 1, 2, 3, 4, 5, 6)
print cut.__str__()

View File

@@ -0,0 +1,75 @@
###
# Copyright 2008-2019 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 datetime import datetime
from diffcalc.ub.orientations import OrientationList
from diffcalc.util import DiffcalcException
import pytest
class TestOrientationList(object):
def setup_method(self):
self.orientlist = OrientationList()
self.time = datetime.now()
self.orientlist.add_orientation(1, 2, 3, 0.1, 0.2, 0.3, "orient1", self.time)
self.orientlist.add_orientation(1.1, 2.2, 3.3, 0.11, 0.12, 0.13, "orient2", self.time)
def test_add_orientation(self):
assert len(self.orientlist) == 2
self.orientlist.add_orientation(10, 20, 30, 0.1, 0.2, 0.3, "orient1", self.time)
def testGetOrientation(self):
answered = self.orientlist.getOrientation(1)
desired = ([1, 2, 3], [0.1, 0.2, 0.3], "orient1", self.time)
assert answered == desired
answered = self.orientlist.getOrientation("orient1")
assert answered == desired
def testRemoveOrientation(self):
self.orientlist.removeOrientation(1)
answered = self.orientlist.getOrientation(1)
desired = ([1.1, 2.2, 3.3], [0.11, 0.12, 0.13], "orient2", self.time)
assert answered == desired
self.orientlist.removeOrientation("orient2")
assert self.orientlist._orientlist == []
def testedit_orientation(self):
self.orientlist.edit_orientation(1, 10, 20, 30, 1, 2, 3, "new1", self.time)
assert (self.orientlist.getOrientation(1)
== ([10, 20, 30], [1, 2, 3], "new1", self.time))
assert (self.orientlist.getOrientation(2)
== ([1.1, 2.2, 3.3], [0.11, 0.12, 0.13], "orient2", self.time))
self.orientlist.edit_orientation("orient2", 1.1, 2.2, 3.3, 1.11, 1.12, 1.13, "new2", self.time)
assert (self.orientlist.getOrientation("new2")
== ([1.1, 2.2, 3.3], [1.11, 1.12, 1.13], "new2", self.time))
self.orientlist.edit_orientation("new2", 1.1, 2.2, 3.3, 1.11, 1.12, 1.13, "new1", self.time)
assert (self.orientlist.getOrientation("new1")
== ([10, 20, 30], [1, 2, 3], "new1", self.time))
def testSwapOrientation(self):
self.orientlist.swap_orientations(1, 2)
assert (self.orientlist.getOrientation(1)
== ([1.1, 2.2, 3.3], [0.11, 0.12, 0.13], "orient2", self.time))
assert (self.orientlist.getOrientation(2)
== ([1, 2, 3], [0.1, 0.2, 0.3], "orient1", self.time))
self.orientlist.swap_orientations("orient1", "orient2")
assert (self.orientlist.getOrientation(2)
== ([1.1, 2.2, 3.3], [0.11, 0.12, 0.13], "orient2", self.time))
assert (self.orientlist.getOrientation(1)
== ([1, 2, 3], [0.1, 0.2, 0.3], "orient1", self.time))

View File

@@ -0,0 +1,104 @@
###
# 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/>.
###
import os
import shutil
import unittest
import tempfile
import time
from nose.tools import eq_ # @UnresolvedImport
try:
from gda.configuration.properties import LocalProperties
except ImportError:
print "Could not import LocalProperties to configure database locations."
from diffcalc.ub.persistence import UbCalculationNonPersister, UBCalculationJSONPersister
from diffcalc.ub.calcstate import UBCalcStateEncoder
def prepareEmptyGdaVarFolder():
vartest_dir = os.path.join(os.getcwd(), 'var_test')
LocalProperties.set('gda.var', vartest_dir)
if os.path.exists(vartest_dir):
print "Removing existing gda.var: ", vartest_dir
shutil.rmtree(vartest_dir)
print "Creating gda.var: ", vartest_dir
os.mkdir(vartest_dir)
class TestUBCalculationNonPersister(object):
def setup_method(self):
self.persister = UbCalculationNonPersister()
def testSaveAndLoad(self):
self.persister.save('string1', 'ub1')
class TestUBCalculationJSONPersister(object):
def setup_method(self):
self.tmpdir = tempfile.mkdtemp()
print self.tmpdir
self.persister = UBCalculationJSONPersister(self.tmpdir, UBCalcStateEncoder)
f = open(os.path.join(self.tmpdir, 'unexpected_file'), 'w')
f.close()
def test_list_with_empty_dir(self):
eq_(self.persister.list(), [])
def test_save_load(self):
d = {'a' : 1, 'b': 2}
self.persister.save(d, 'first')
eq_(self.persister.load('first'), d)
def test_save_overwites(self):
d1 = {'a' : 1, 'b': 2}
self.persister.save(d1, 'first')
eq_(self.persister.load('first'), d1)
d2 = {'a' : 3, 'b': 4, 'c' : 5}
self.persister.save(d2, 'first')
eq_(self.persister.load('first'), d2)
def test_list(self):
d = {'a' : 1, 'b': 2}
self.persister.save(d, 'first')
eq_(self.persister.list(), ['first'])
def test_multiple_list(self):
d = {'a' : 1, 'b': 2}
self.persister.save(d, 'first_written')
time.sleep(1.)
eq_(self.persister.list(), ['first_written'])
self.persister.save(d, 'second_written')
time.sleep(1.)
eq_(self.persister.list(), ['second_written', 'first_written'])
self.persister.save(d, 'third_written')
time.sleep(1.)
eq_(self.persister.list(), ['third_written', 'second_written', 'first_written'])
def test_remove_list(self):
d = {'a' : 1, 'b': 2}
self.persister.save(d, 'first')
self.persister.remove('first')
eq_(self.persister.list(), [])

View File

@@ -0,0 +1,61 @@
###
# 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 mock import Mock
from diffcalc.ub.reference import YouReference
from test.tools import assert_array_almost_equal, assert_2darray_almost_equal
try:
from numpy import matrix, hstack
from numpy.linalg import norm
except ImportError:
from numjy import matrix, hstack
from numjy.linalg import norm
class TestYouReference():
def setup_method(self):
self.get_UB = Mock()
self.reference = YouReference(self.get_UB)
self.get_UB.return_value = matrix('1 0 0; 0 1 0; 0 0 1')
def test_default_n_phi(self):
assert_2darray_almost_equal(self.reference.n_phi.tolist(), matrix('0; 0; 1').tolist())
def test__str__with_phi_configured(self):
print self.reference
def test__str__with_hkl_configured(self):
self.reference.n_hkl_configured = matrix('0; 1; 1')
print self.reference
def test_n_phi_from_hkl_with_unity_matrix_001(self):
self.get_UB.return_value = matrix('1 0 0; 0 1 0; 0 0 1')
self.reference.n_hkl_configured = matrix('0; 0; 1')
assert_2darray_almost_equal(self.reference.n_phi.tolist(), matrix('0; 0; 1').tolist())
def test_n_phi_from_hkl_with_unity_matrix_010(self):
self.get_UB.return_value = matrix('1 0 0; 0 1 0; 0 0 1')
self.reference.n_hkl_configured = matrix('0; 1; 0')
assert_2darray_almost_equal(self.reference.n_phi.tolist(), matrix('0; 1; 0').tolist())

View File

@@ -0,0 +1,111 @@
###
# 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 datetime import datetime
from diffcalc.hkl.vlieg.geometry import SixCircleGammaOnArmGeometry
from diffcalc.ub.reflections import ReflectionList
from diffcalc.hkl.vlieg.geometry import VliegPosition as Pos
from diffcalc.util import DiffcalcException
import pytest
class TestReflectionList(object):
def setup_method(self):
self._geometry = SixCircleGammaOnArmGeometry()
self.reflist = ReflectionList(self._geometry,
['a', 'd', 'g', 'o', 'c', 'p'])
self.time = datetime.now()
pos = Pos(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
self.reflist.add_reflection(1, 2, 3, pos, 1000, "ref1", self.time)
pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66)
self.reflist.add_reflection(1.1, 2.2, 3.3, pos, 1100, "ref2", self.time)
def test_add_reflection(self):
assert len(self.reflist) == 2
pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66)
self.reflist.add_reflection(11.1, 12.2, 13.3, pos, 1100, "ref2", self.time)
def testGetReflection(self):
answered = self.reflist.getReflection(1)
pos = Pos(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
desired = ([1, 2, 3], pos, 1000, "ref1", self.time)
assert answered == desired
answered = self.reflist.getReflection('ref1')
assert answered == desired
def testRemoveReflection(self):
self.reflist.removeReflection(1)
answered = self.reflist.getReflection(1)
pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66)
desired = ([1.1, 2.2, 3.3], pos, 1100, "ref2", self.time)
assert answered == desired
self.reflist.removeReflection("ref2")
assert self.reflist._reflist == []
def testedit_reflection(self):
ps = Pos(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
self.reflist.edit_reflection(1, 10, 20, 30, ps, 1000, "new1", self.time)
assert (self.reflist.getReflection(1)
== ([10, 20, 30], ps, 1000, "new1", self.time))
pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66)
assert (self.reflist.getReflection(2)
== ([1.1, 2.2, 3.3], pos, 1100, "ref2", self.time))
self.reflist.edit_reflection("ref2", 1.1, 2.2, 3.3, pos, 1100, "new2", self.time)
assert (self.reflist.getReflection("new2")
== ([1.1, 2.2, 3.3], pos, 1100, "new2", self.time))
self.reflist.edit_reflection("new2", 10, 20, 30, pos, 1100, "new1", self.time)
assert (self.reflist.getReflection("new1")
== ([10, 20, 30], ps, 1000, "new1", self.time))
def testSwapReflection(self):
self.reflist.swap_reflections(1, 2)
pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66)
assert (self.reflist.getReflection(1)
== ([1.1, 2.2, 3.3], pos, 1100, "ref2", self.time))
pos = Pos(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
assert (self.reflist.getReflection(2)
== ([1, 2, 3], pos, 1000, "ref1", self.time))
self.reflist.swap_reflections("ref1", "ref2")
pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66)
assert (self.reflist.getReflection(2)
== ([1.1, 2.2, 3.3], pos, 1100, "ref2", self.time))
pos = Pos(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
assert (self.reflist.getReflection(1)
== ([1, 2, 3], pos, 1000, "ref1", self.time))
def createRefStateDicts(self):
ref_0 = {
'h': 1,
'k': 2,
'l': 3,
'position': (0.1, 0.2, 0.3, 0.4, 0.5, 0.6),
'energy': 1000,
'tag': "ref1",
'time': repr(self.time)
}
ref_1 = {
'h': 1.1,
'k': 2.2,
'l': 3.3,
'position': (0.11, 0.22, 0.33, 0.44, 0.55, 0.66),
'energy': 1100,
'tag': "ref2",
'time': repr(self.time)
}
return ref_0, ref_1

View File

@@ -0,0 +1,763 @@
###
# 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 nose.tools import eq_ # @UnresolvedImport
import tempfile
import os.path
import pytest
from math import atan, sqrt
from nose import SkipTest
try:
from numpy import matrix
except ImportError:
from numjy import matrix
import diffcalc.util # @UnusedImport
from diffcalc.hkl.vlieg.geometry import SixCircleGammaOnArmGeometry,\
VliegPosition
from diffcalc.hkl.you.geometry import SixCircle
from diffcalc.hardware import DummyHardwareAdapter
from test.tools import assert_iterable_almost_equal, mneq_, arrayeq_
from diffcalc.ub.persistence import UbCalculationNonPersister,\
UBCalculationJSONPersister
from diffcalc.ub.calcstate import UBCalcStateEncoder
from diffcalc.util import DiffcalcException, MockRawInput, xyz_rotation,\
TODEG, TORAD, CoordinateConverter
from diffcalc.hkl.vlieg.calc import VliegUbCalcStrategy, vliegAnglesToHkl
from diffcalc.hkl.you.calc import youAnglesToHkl, YouUbCalcStrategy
from test.diffcalc import scenarios
from test.diffcalc.scenarios import YouPositionScenario
diffcalc.util.DEBUG = True
def prepareRawInput(listOfStrings):
diffcalc.util.raw_input = MockRawInput(listOfStrings)
prepareRawInput([])
from diffcalc import settings
class _UBCommandsBase():
def setup_method(self):
names = 'alpha', 'delta', 'gamma', 'omega', 'chi', 'phi'
self.hardware = DummyHardwareAdapter(names)
settings.hardware = self.hardware
self.conv = CoordinateConverter(transform=self.t_matrix)
self._refineub_matrix = matrix('0.70711 0.70711 0.00000; -0.70711 0.70711 0.00000; 0.00000 0.00000 1.00000')
from diffcalc.ub import ub
reload(ub)
self.ub = ub
#self.ub.ubcalc = ub.ubcalc
prepareRawInput([])
diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS = True
def testNewUb(self):
self.ub.newub('test1')
eq_(self.ub.ubcalc._state.name, 'test1')
with pytest.raises(TypeError):
self.ub.newub(1)
def testNewUbInteractively(self):
prepareRawInput(['ubcalcname', 'xtal', '1', '2', '3', '91', '92',
'93'])
self.ub.newub()
def testLoadub(self):
with pytest.raises(TypeError):
self.ub.loadub((1, 2))
def testSaveubcalcas(self):
with pytest.raises(TypeError):
self.ub.saveubas(1)
with pytest.raises(TypeError):
self.ub.saveubas((1, 2))
self.ub.saveubas('blarghh')
def testUb(self):
with pytest.raises(TypeError):
self.ub.showref((1))
self.ub.ub()
self.ub.newub('testubcalc')
self.ub.ub()
def testSetlat(self):
# "Exception should result if no UBCalculation started")
with pytest.raises(DiffcalcException):
self.ub.setlat('HCl', 2)
self.ub.newub('testing_setlat')
with pytest.raises(TypeError):
self.ub.setlat(1)
with pytest.raises(TypeError):
self.ub.setlat(1, 2)
with pytest.raises(TypeError):
self.ub.setlat('HCl')
self.ub.setlat('NaCl', 1.1)
ubcalc = self.ub.ubcalc
eq_(('NaCl', 1.1, 1.1, 1.1, 90, 90, 90), ubcalc._state.crystal.getLattice())
self.ub.setlat('NaCl', 1.1, 2.2)
eq_(('NaCl', 1.1, 1.1, 2.2, 90, 90, 90), ubcalc._state.crystal.getLattice())
self.ub.setlat('NaCl', 1.1, 2.2, 3.3)
eq_(('NaCl', 1.1, 2.2, 3.3, 90, 90, 90), ubcalc._state.crystal.getLattice())
self.ub.setlat('NaCl', 1.1, 2.2, 3.3, 91)
eq_(('NaCl', 1.1, 2.2, 3.3, 90, 90, 91), ubcalc._state.crystal.getLattice())
with pytest.raises(TypeError):
self.ub.setlat(('NaCl', 1.1, 2.2, 3.3, 91, 92))
self.ub.setlat('NaCl', 1.1, 2.2, 3.3, 91, 92, 93)
assert_iterable_almost_equal(
('NaCl', 1.1, 2.2, 3.3, 91, 92, 92.99999999999999),
ubcalc._state.crystal.getLattice())
def testSetlatInteractive(self):
self.ub.newub('testing_setlatinteractive')
prepareRawInput(['xtal', '1', '2', '3', '91', '92', '93'])
self.ub.setlat()
getLattice = self.ub.ubcalc._state.crystal.getLattice
assert_iterable_almost_equal(getLattice(),
('xtal', 1., 2., 3., 91, 92, 92.999999999999986))
#Defaults:
prepareRawInput(['xtal', '', '', '', '', '', ''])
self.ub.setlat()
getLattice = self.ub.ubcalc._state.crystal.getLattice
eq_(getLattice(), ('xtal', 1., 1., 1., 90, 90, 90))
def testShowref(self):
with pytest.raises(TypeError):
self.ub.showref((1))
eq_(self.ub.showref(), None) # No UBCalculation loaded
# will be tested, for exceptions at least, implicitly below
self.ub.newub('testing_showref')
eq_(self.ub.showref(), None) # No UBCalculation loaded"
def testAddref(self):
with pytest.raises(TypeError):
self.ub.addref(1)
with pytest.raises(TypeError):
self.ub.addref(1, 2)
with pytest.raises(TypeError):
self.ub.addref(1, 2, 'blarghh')
# start new ubcalc
self.ub.newub('testing_addref')
reflist = self.ub.ubcalc._state.reflist # for convenience
pos1 = (1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
pos2 = (2.1, 2.2, 2.3, 2.4, 2.5, 2.6)
pos3 = (3.1, 3.2, 3.3, 3.4, 3.5, 3.6)
pos4 = (4.1, 4.2, 4.3, 4.4, 4.5, 4.6)
#
self.hardware.energy = 1.10
self.hardware.position = pos1
self.ub.addref([1.1, 1.2, 1.3])
result = reflist.get_reflection_in_external_angles(1)
eq_(result[:-1], ([1.1, 1.2, 1.3], pos1, 1.10, None))
self.hardware.energy = 2.10
self.hardware.position = pos2
self.ub.addref([2.1, 2.2, 2.3], 'atag')
result = reflist.get_reflection_in_external_angles(2)
eq_(result[:-1], ([2.1, 2.2, 2.3], pos2, 2.10, 'atag'))
self.ub.addref([3.1, 3.2, 3.3], pos3, 3.10)
result = reflist.get_reflection_in_external_angles(3)
eq_(result[:-1], ([3.1, 3.2, 3.3], pos3, 3.10, None))
self.ub.addref([4.1, 4.2, 4.3], pos4, 4.10, 'tag2')
result = reflist.get_reflection_in_external_angles(4)
eq_(result[:-1], ([4.1, 4.2, 4.3], pos4, 4.10, 'tag2'))
def testAddrefInteractively(self):
prepareRawInput([])
# start new ubcalc
self.ub.newub('testing_addref')
reflist = self.ub.ubcalc._state.reflist # for convenience
pos1 = (1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
pos2 = (2.1, 2.2, 2.3, 2.4, 2.5, 2.6)
pos3 = (3.1, 3.2, 3.3, 3.4, 3.5, 3.6)
pos3s = ['3.1', '3.2', '3.3', '3.4', '3.5', '3.6']
pos4 = (4.1, 4.2, 4.3, 4.4, 4.5, 4.6)
pos4s = ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6']
#
self.hardware.energy = 1.10
self.hardware.position = pos1
prepareRawInput(['1.1', '1.2', '1.3', '', ''])
self.ub.addref()
result = reflist.get_reflection_in_external_angles(1)
eq_(result[:-1], ([1.1, 1.2, 1.3], pos1, 1.10, None))
self.hardware.energy = 2.10
self.hardware.position = pos2
prepareRawInput(['2.1', '2.2', '2.3', '', 'atag'])
self.ub.addref()
result = reflist.get_reflection_in_external_angles(2)
eq_(result[:-1], ([2.1, 2.2, 2.3], pos2, 2.10, 'atag'))
prepareRawInput(['3.1', '3.2', '3.3', 'n'] + pos3s + ['3.10', ''])
self.ub.addref()
result = reflist.get_reflection_in_external_angles(3)
eq_(result[:-1], ([3.1, 3.2, 3.3], pos3, 3.10, None))
prepareRawInput(['4.1', '4.2', '4.3', 'n'] + pos4s + ['4.10', 'tag2'])
self.ub.addref()
result = reflist.get_reflection_in_external_angles(4)
eq_(result[:-1], ([4.1, 4.2, 4.3], pos4, 4.10, 'tag2'))
def testEditRefInteractivelyWithCurrentPosition(self):
pos1 = (1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
pos2 = (2.1, 2.2, 2.3, 2.4, 2.5, 2.6)
self.ub.newub('testing_editref')
self.ub.addref([1, 2, 3], pos1, 10, 'tag1')
self.hardware.energy = 11
self.hardware.position = pos2
prepareRawInput(['1.1', '', '3.1', 'y', ''])
self.ub.editref(1)
reflist = self.ub.ubcalc._state.reflist # for convenience
result = reflist.get_reflection_in_external_angles(1)
eq_(result[:-1], ([1.1, 2, 3.1], pos2, 11, 'tag1'))
def testEditRefInteractivelyWithEditedPosition(self):
pos1 = (1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
pos2 = (2.1, 2.2, 2.3, 2.4, 2.5, 2.6)
pos2s = ['2.1', '2.2', '2.3', '2.4', '2.5', '2.6']
self.ub.newub('testing_editref')
self.ub.addref([1, 2, 3], pos1, 10, 'tag1')
prepareRawInput(['1.1', '', '3.1', 'n'] + pos2s + ['12', 'newtag'])
self.ub.editref(1)
reflist = self.ub.ubcalc._state.reflist
result = reflist.get_reflection_in_external_angles(1)
eq_(result[:-1], ([1.1, 2, 3.1], pos2, 12, 'newtag'))
def testSwapref(self):
with pytest.raises(TypeError):
self.ub.swapref(1)
with pytest.raises(TypeError):
self.ub.swapref(1, 2, 3)
with pytest.raises(IndexError):
self.ub.swapref(1, 1.1)
self.ub.newub('testing_swapref')
pos = (1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
self.ub.addref([1, 2, 3], pos, 10, 'tag1')
self.ub.addref([1, 2, 3], pos, 10, 'tag2')
self.ub.addref([1, 2, 3], pos, 10, 'tag3')
self.ub.swapref(1, 3)
self.ub.swapref(1, 3)
self.ub.swapref(3, 1) # end flipped
reflist = self.ub.ubcalc._state.reflist
tag1 = reflist.get_reflection_in_external_angles(1)[3]
tag2 = reflist.get_reflection_in_external_angles(2)[3]
tag3 = reflist.get_reflection_in_external_angles(3)[3]
eq_(tag1, 'tag3')
eq_(tag2, 'tag2')
eq_(tag3, 'tag1')
self.ub.swapref()
tag1 = reflist.get_reflection_in_external_angles(1)[3]
tag2 = reflist.get_reflection_in_external_angles(2)[3]
eq_(tag1, 'tag2')
eq_(tag2, 'tag3')
def testDelref(self):
self.ub.newub('testing_swapref')
pos = (1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
self.ub.addref([1, 2, 3], pos, 10, 'tag1')
reflist = self.ub.ubcalc._state.reflist
reflist.get_reflection_in_external_angles(1)
self.ub.delref(1)
with pytest.raises(IndexError):
reflist.get_reflection_in_external_angles(1)
def testShoworient(self):
with pytest.raises(TypeError):
self.ub.showorient((1))
eq_(self.ub.showorient(), None) # No UBCalculation loaded
# will be tested, for exceptions at least, implicitly below
self.ub.newub('testing_showorient')
eq_(self.ub.showorient(), None) # No UBCalculation loaded"
def testAddorient(self):
with pytest.raises(TypeError):
self.ub.addorient(1)
with pytest.raises(TypeError):
self.ub.addorient(1, 2)
with pytest.raises(TypeError):
self.ub.addorient(1, 2, 'blarghh')
# start new ubcalc
self.ub.newub('testing_addorient')
orientlist = self.ub.ubcalc._state.orientlist # for convenience
hkl1 = [1.1, 1.2, 1.3]
hkl2 = [2.1, 2.2, 2.3]
orient1 = [1.4, 1.5, 1.6]
orient2 = [2.4, 2.5, 2.6]
#
self.ub.addorient(hkl1, orient1)
result = orientlist.getOrientation(1)
trans_orient1 = self.conv.transform(matrix([orient1]).T)
eq_(result[0], hkl1)
mneq_(matrix([result[1]]), trans_orient1.T)
eq_(result[2], None)
self.ub.addorient(hkl2, orient2, 'atag')
result = orientlist.getOrientation(2)
trans_orient2 = self.conv.transform(matrix([orient2]).T)
eq_(result[0], hkl2)
mneq_(matrix([result[1]]), trans_orient2.T)
eq_(result[2], 'atag')
def testAddorientInteractively(self):
prepareRawInput([])
# start new ubcalc
self.ub.newub('testing_addorient')
orientlist = self.ub.ubcalc._state.orientlist # for convenience
hkl1 = [1.1, 1.2, 1.3]
hkl2 = [2.1, 2.2, 2.3]
orient1 = [1.4, 1.5, 1.6]
orient2 = [2.4, 2.5, 2.6]
#
prepareRawInput(['1.1', '1.2', '1.3', '1.4', '1.5', '1.6', ''])
self.ub.addorient()
result = orientlist.getOrientation(1)
trans_orient1 = self.conv.transform(matrix([orient1]).T)
eq_(result[0], hkl1)
mneq_(matrix([result[1]]), trans_orient1.T)
eq_(result[2], None)
prepareRawInput(['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', 'atag'])
self.ub.addorient()
result = orientlist.getOrientation(2)
trans_orient2 = self.conv.transform(matrix([orient2]).T)
eq_(result[0], hkl2)
mneq_(matrix([result[1]]), trans_orient2.T)
eq_(result[2], 'atag')
def testEditOrientInteractively(self):
hkl1 = [1.1, 1.2, 1.3]
hkl2 = [1.1, 1.2, 3.1]
orient1 = [1.4, 1.5, 1.6]
orient2 = [2.4, 1.5, 2.6]
orient2s = ['2.4', '', '2.6']
self.ub.newub('testing_editorient')
self.ub.addorient(hkl1, orient1, 'tag1')
prepareRawInput(['1.1', '', '3.1'] + orient2s + ['newtag',])
self.ub.editorient(1)
orientlist = self.ub.ubcalc._state.orientlist
result = orientlist.getOrientation(1)
trans_orient2 = self.conv.transform(matrix([orient2]).T)
eq_(result[0], hkl2)
mneq_(matrix([result[1]]), trans_orient2.T)
eq_(result[2], 'newtag')
def testSwaporient(self):
with pytest.raises(TypeError):
self.ub.swaporient(1)
with pytest.raises(TypeError):
self.ub.swaporient(1, 2, 3)
with pytest.raises(IndexError):
self.ub.swaporient(1, 1.1)
self.ub.newub('testing_swaporient')
hkl = [1.1, 1.2, 1.3]
orient = [1.4, 1.5, 1.6]
self.ub.addorient(hkl, orient, 'tag1')
self.ub.addorient(hkl, orient, 'tag2')
self.ub.addorient(hkl, orient, 'tag3')
self.ub.swaporient(1, 3)
self.ub.swaporient(1, 3)
self.ub.swaporient(3, 1) # end flipped
orientlist = self.ub.ubcalc._state.orientlist
tag1 = orientlist.getOrientation(1)[2]
tag2 = orientlist.getOrientation(2)[2]
tag3 = orientlist.getOrientation(3)[2]
eq_(tag1, 'tag3')
eq_(tag2, 'tag2')
eq_(tag3, 'tag1')
self.ub.swaporient()
tag1 = orientlist.getOrientation(1)[2]
tag2 = orientlist.getOrientation(2)[2]
eq_(tag1, 'tag2')
eq_(tag2, 'tag3')
def testDelorient(self):
self.ub.newub('testing_delorient')
hkl = [1.1, 1.2, 1.3]
pos = [1.4, 1.5, 1.6]
self.ub.addorient(hkl, pos, 'tag1')
orientlist = self.ub.ubcalc._state.orientlist
orientlist.getOrientation(1)
self.ub.delorient(1)
with pytest.raises(IndexError):
orientlist.getOrientation(1)
def testSetu(self):
# just test calling this method
#self.ub.setu([[1,2,3],[1,2,3],[1,2,3]])
self.ub.newub('testsetu')
setu = self.ub.setu
with pytest.raises(TypeError):
setu(1, 2)
with pytest.raises(TypeError):
setu(1)
with pytest.raises(TypeError):
setu('a')
with pytest.raises(TypeError):
setu([1, 2, 3])
with pytest.raises(TypeError):
setu([[1, 2, 3], [1, 2, 3], [1, 2]])
# diffCalcException expected if no lattice set yet
with pytest.raises(DiffcalcException):
setu([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
self.ub.setlat('NaCl', 1.1)
setu([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) # check no exceptions only
setu(((1, 2, 3), (1, 2, 3), (1, 2, 3))) # check no exceptions only
def testSetuInteractive(self):
self.ub.newub('testsetu')
self.ub.setlat('NaCl', 1.1)
prepareRawInput(['1 2 3', '4 5 6', '7 8 9'])
self.ub.setu()
a = self.ub.ubcalc.U.tolist()
eq_([list(a[0]), list(a[1]), list(a[2])],
[[1, 2, 3], [4, 5, 6], [7, 8, 9]])
prepareRawInput(['', ' 9 9.9 99', ''])
self.ub.setu()
a = self.ub.ubcalc.U.tolist()
eq_([list(a[0]), list(a[1]), list(a[2])],
[[1, 0, 0], [9, 9.9, 99], [0, 0, 1]])
def testSetub(self):
# just test calling this method
self.ub.newub('testsetub')
setub = self.ub.setub
with pytest.raises(TypeError):
setub(1, 2)
with pytest.raises(TypeError):
setub(1)
with pytest.raises(TypeError):
setub('a')
with pytest.raises(TypeError):
setub([1, 2, 3])
with pytest.raises(TypeError):
setub([[1, 2, 3], [1, 2, 3], [1, 2]])
setub([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) # check no exceptions only
setub(((1, 2, 3), (1, 2, 3), (1, 2, 3))) # check no exceptions only
def testSetUbInteractive(self):
self.ub.newub('testsetu')
self.ub.setlat('NaCl', 1.1)
prepareRawInput(['1 2 3', '4 5 6', '7 8 9'])
self.ub.setub()
a = self.ub.ubcalc.UB.tolist()
eq_([list(a[0]), list(a[1]), list(a[2])],
[[1, 2, 3], [4, 5, 6], [7, 8, 9]])
prepareRawInput(['', ' 9 9.9 99', ''])
self.ub.setub()
a = self.ub.ubcalc.UB.tolist()
eq_([list(a[0]), list(a[1]), list(a[2])],
[[1, 0, 0], [9, 9.9, 99], [0, 0, 1]])
def testCalcub(self):
with pytest.raises(DiffcalcException):
self.ub.calcub(1) # wrong input
# no ubcalc started:
with pytest.raises(DiffcalcException):
self.ub.calcub()
self.ub.newub('testcalcub')
# not enough reflections:
with pytest.raises(DiffcalcException):
self.ub.calcub()
for s in scenarios.sessions(settings.Pos):
self.ub.setlat(s.name, *s.lattice)
self.ub.clearref()
r = s.ref1
self.ub.addref(
[r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
r = s.ref2
self.ub.addref(
[r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
self.ub.calcub(s.ref1.tag, s.ref2.tag)
mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
4, note="wrong UB matrix after calculating U")
def testOrientub(self):
with pytest.raises(DiffcalcException):
self.ub.orientub(1) # wrong input
# no ubcalc started:
with pytest.raises(DiffcalcException):
self.ub.orientub()
self.ub.newub('testorientub')
# not enough orientations:
with pytest.raises(DiffcalcException):
self.ub.orientub()
s = scenarios.sessions(settings.Pos)[1]
self.ub.setlat(s.name, *s.lattice)
r1 = s.ref1
orient1 = self.conv.transform(matrix('1; 0; 0'), True)
tag1 = 'or'+r1.tag
self.ub.addorient(
(r1.h, r1.k, r1.l), orient1.T.tolist()[0], tag1)
r2 = s.ref2
orient2 = self.conv.transform(matrix('0; -1; 0'), True)
tag2 = 'or'+r2.tag
self.ub.addorient(
(r2.h, r2.k, r2.l), orient2.T.tolist()[0], tag2)
self.ub.orientub()
mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
4, note="wrong UB matrix after calculating U")
self.ub.orientub(tag1, tag2)
mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
4, note="wrong UB matrix after calculating U")
self.ub.addref(
[r1.h, r1.k, r1.l], r1.pos.totuple(), r1.energy, r1.tag)
self.ub.orientub(r1.tag, tag2)
mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
4, note="wrong UB matrix after calculating U")
self.ub.addref(
[r2.h, r2.k, r2.l], r2.pos.totuple(), r2.energy, r2.tag)
self.ub.orientub(tag1, r2.tag)
mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
4, note="wrong UB matrix after calculating U")
def testRefineubInteractively(self):
self.ub.newub('testing_refineubinteractive')
self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
self.ub.setmiscut(0)
prepareRawInput(['1', '1', '', 'n', '0', '60', '0', '30', '0', '0', 'y', 'y'])
self.ub.refineub()
getLattice = self.ub.ubcalc._state.crystal.getLattice
eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
mneq_(self.ub.ubcalc.U, self._refineub_matrix,
4, note="wrong U matrix after refinement")
def testRefineubInteractivelyWithPosition(self):
self.ub.newub('testing_refineubinteractivepos')
self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
self.ub.setmiscut(0)
self.hardware.position = [0, 60, 0, 30, 0, 0]
prepareRawInput(['1', '1', '', 'y', 'y', 'y'])
self.ub.refineub()
getLattice = self.ub.ubcalc._state.crystal.getLattice
eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
mneq_(self.ub.ubcalc.U, self._refineub_matrix,
4, note="wrong U matrix after refinement")
def testRefineubInteractivelyWithHKL(self):
self.ub.newub('testing_refineubinteractivehkl')
self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
self.ub.setmiscut(0)
self.hardware.position = [0, 60, 0, 30, 0, 0]
prepareRawInput(['y', 'y', 'y'])
self.ub.refineub([1, 1, 0])
getLattice = self.ub.ubcalc._state.crystal.getLattice
eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
mneq_(self.ub.ubcalc.U, self._refineub_matrix,
4, note="wrong U matrix after refinement")
def testRefineub(self):
self.ub.newub('testing_refineub')
self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
self.ub.setmiscut(0)
prepareRawInput(['y', 'y'])
self.ub.refineub([1, 1, 0], [0, 60, 0, 30, 0, 0])
getLattice = self.ub.ubcalc._state.crystal.getLattice
eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
mneq_(self.ub.ubcalc.U, self._refineub_matrix,
4, note="wrong U matrix after refinement")
def testC2th(self):
self.ub.newub('testc2th')
self.ub.setlat('cube', 1, 1, 1, 90, 90, 90)
assert self.ub.c2th((0, 0, 1)) == pytest.approx(60)
def testHKLangle(self):
self.ub.newub('testhklangle')
self.ub.setlat('cube', 1, 1, 1, 90, 90, 90)
assert self.ub.hklangle((0, 0, 1), (0, 0, 2)) == pytest.approx(0)
assert self.ub.hklangle((0, 1, 0), (0, 0, 2)) == pytest.approx(90)
assert self.ub.hklangle((1, 0, 0), (0, 0, 2)) == pytest.approx(90)
assert self.ub.hklangle((1, 1, 0), (0, 0, 2)) == pytest.approx(90)
assert self.ub.hklangle((0, 1, 1), (0, 0, 2)) == pytest.approx(45)
assert self.ub.hklangle((1, 0, 1), (0, 0, 2)) == pytest.approx(45)
assert self.ub.hklangle((1, 1, 1), (0, 0, 2)) == pytest.approx(atan(sqrt(2))*TODEG)
def testSigtau(self):
# sigtau [sig tau]
with pytest.raises(TypeError):
self.ub.sigtau(1)
with pytest.raises(ValueError):
self.ub.sigtau(1, 'a')
self.ub.sigtau(1, 2)
self.ub.sigtau(1, 2.0)
eq_(self.ub.ubcalc.sigma, 1)
eq_(self.ub.ubcalc.tau, 2.0)
def testSigtauInteractive(self):
prepareRawInput(['1', '2.'])
self.ub.sigtau()
eq_(self.ub.ubcalc.sigma, 1)
eq_(self.ub.ubcalc.tau, 2.0)
#Defaults:
prepareRawInput(['', ''])
self.hardware.position = [None, None, None, None, 3, 4.]
self.ub.sigtau()
eq_(self.ub.ubcalc.sigma, -3.)
eq_(self.ub.ubcalc.tau, -4.)
def testSetWithString(self):
with pytest.raises(TypeError):
self.ub.setlat('alpha', 'a')
with pytest.raises(TypeError):
self.ub.setlat('alpha', 1, 'a')
def test_setnphihkl_at_various_phases(self):
self.ub.setnphi([1, 0, 1])
self.ub.setnhkl([1, 0, 1])
self.ub.newub('test')
self.ub.setnphi([1, 0, 1])
self.ub.setnhkl([1, 0, 1])
self.ub.setlat('cube', 1, 1, 1, 90, 90, 90)
self.ub.setnphi([1, 0, 1])
self.ub.setnhkl([1, 0, 1])
self.ub.setu([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
self.ub.setnphi([1, 0, 1])
self.ub.setnhkl([1, 0, 1])
def testMiscut(self):
self.ub.newub('testsetmiscut')
self.ub.setlat('cube', 1, 1, 1, 90, 90, 90)
beam_axis = self.conv.transform(matrix('0; 1; 0'), True).T.tolist()[0]
beam_maxis = self.conv.transform(matrix('0; -1; 0'), True).T.tolist()[0]
self.ub.setmiscut(self.t_hand * 30, beam_axis)
mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('-0.5000000; 0.00000; 0.8660254'))
self.ub.addmiscut(self.t_hand * 15, beam_axis)
mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('-0.7071068; 0.00000; 0.7071068'))
self.ub.addmiscut(self.t_hand * 45, beam_maxis)
mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('0.0; 0.0; 1.0'))
class TestUbCommandsVlieg(_UBCommandsBase):
def setup_method(self):
settings.ubcalc_persister = UbCalculationNonPersister()
settings.geometry = SixCircleGammaOnArmGeometry()
settings.ubcalc_strategy = VliegUbCalcStrategy()
settings.angles_to_hkl_function = vliegAnglesToHkl
settings.Pos = VliegPosition
self.t_matrix = matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
self.t_hand = 1
_UBCommandsBase.setup_method(self)
class TestUBCommandsYou(_UBCommandsBase):
def setup_method(self):
settings.ubcalc_persister = UbCalculationNonPersister()
settings.geometry = SixCircle()
settings.ubcalc_strategy = YouUbCalcStrategy()
settings.angles_to_hkl_function = youAnglesToHkl
settings.Pos = YouPositionScenario
self.t_matrix = matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
self.t_hand = 1
_UBCommandsBase.setup_method(self)
class TestUBCommandsCustomGeom(TestUBCommandsYou):
def setup_method(self):
settings.ubcalc_persister = UbCalculationNonPersister()
inv = matrix([[0, 0, -1], [0, 1, 0], [1, 0, 0]])
self.zrot = xyz_rotation([0, 0 ,1], 30. * TORAD)
self.t_matrix = inv * self.zrot
self.t_hand = 1
settings.geometry = SixCircle(beamline_axes_transform=self.t_matrix)
settings.ubcalc_strategy = YouUbCalcStrategy()
settings.angles_to_hkl_function = youAnglesToHkl
settings.Pos = YouPositionScenario
_UBCommandsBase.setup_method(self)
def testSetu(self):
self.ub.newub('testsetu_custom')
self.ub.setlat('NaCl', 1.1)
zrot = xyz_rotation([0, 0 , 1], 30. * TORAD)
self.ub.setu(zrot.tolist())
mneq_(self.ub.ubcalc.U, self.conv.transform(self.zrot))
def testSetuInteractive(self):
# Interactive functionality already tested
raise SkipTest()
def testSetub(self):
self.ub.newub('testsetub_custom')
self.ub.setlat('NaCl', 1.1)
zrot = xyz_rotation([0, 0 , 1], 30. * TORAD)
self.ub.setu(zrot.tolist())
mneq_(self.ub.ubcalc.UB, self.conv.transform(self.zrot) * self.ub.ubcalc._state.crystal.B)
def testSetUbInteractive(self):
# Interactive functionality already tested
raise SkipTest()
class TestUbCommandsJsonPersistence(TestUBCommandsYou):
def setup_method(self):
settings.ubcalc_persister = self._createPersister()
settings.geometry = SixCircle()
settings.ubcalc_strategy = YouUbCalcStrategy()
settings.angles_to_hkl_function = youAnglesToHkl
settings.Pos = YouPositionScenario
self.t_matrix = matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
self.t_hand = 1
_UBCommandsBase.setup_method(self)
def _createPersister(self):
self.tmpdir = tempfile.mkdtemp()
print self.tmpdir
self.persister = UBCalculationJSONPersister(self.tmpdir, UBCalcStateEncoder)
f = open(os.path.join(self.tmpdir, 'unexpected_file'), 'w')
f.close()
return self.persister
def testNewUb(self):
self.ub.newub('test1')
self.ub.loadub('test1')
self.ub.ub()
def test_n_phi_persistance(self):
self.ub.newub('test1')
self.ub.setnphi([0, 1, 0])
arrayeq_(self.ub.ubcalc.n_phi.T.tolist()[0], [0, 1, 0])
self.ub.loadub('test1')
arrayeq_(self.ub.ubcalc.n_phi.T.tolist()[0], [0, 1, 0])