예제 #1
0
    def test_crystal_structure_handling(self):
        sample = Sample()

        self.assertEqual(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

        cs = CrystalStructure('5.43 5.43 5.43', 'F d -3 m',
                              'Si 0 0 0 1.0 0.01')

        sample.setCrystalStructure(cs)

        self.assertEqual(sample.hasCrystalStructure(), True)

        cs_from_sample = sample.getCrystalStructure()

        self.assertEqual(cs.getSpaceGroup().getHMSymbol(),
                         cs_from_sample.getSpaceGroup().getHMSymbol())
        self.assertEqual(cs.getUnitCell().a(),
                         cs_from_sample.getUnitCell().a())
        self.assertEqual(len(cs.getScatterers()),
                         len(cs_from_sample.getScatterers()))
        self.assertEqual(cs.getScatterers()[0],
                         cs_from_sample.getScatterers()[0])

        sample.clearCrystalStructure()

        self.assertEqual(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)
예제 #2
0
    def test_setSample(self):
        sample = Sample()
        sample.setThickness(12.5)

        self._expt_ws.setSample(sample)
        held_sample = self._expt_ws.sample()

        self.assertNotEqual(id(held_sample), id(sample))
        self.assertEqual(held_sample.getThickness(), sample.getThickness())
    def _set_sample(self, ws, components, can_as_sample=False):

        # this is to ensure that there is no historic remnant of the sample or container that can affect the attenuation
        # from the other hand this does not allow for sample nor container shape nor material to be already defined
        ws.setSample(Sample())
        set_sample_alg = self.createChildAlgorithm("SetSample",
                                                   enableLogging=False)
        set_sample_alg.setProperty("InputWorkspace", ws)

        if 'Sample' in components:
            sample_geometry = dict()
            sample_geometry['Height'] = self._height

            if self._shape == 'FlatPlate':
                sample_geometry['Shape'] = 'FlatPlate'
                sample_geometry['Width'] = self._sample_width
                sample_geometry['Thick'] = self._sample_thickness
                sample_geometry['Center'] = [0.0, 0.0, self._sample_center]
                sample_geometry['Angle'] = self._sample_angle

            if self._shape == 'Cylinder':
                sample_geometry['Shape'] = 'Cylinder'
                sample_geometry['Radius'] = self._sample_radius
                sample_geometry['Center'] = [0.0, 0.0, 0.0]

            if self._shape == 'Annulus':
                sample_geometry['Shape'] = 'HollowCylinder'
                sample_geometry['InnerRadius'] = self._sample_inner_radius
                sample_geometry['OuterRadius'] = self._sample_outer_radius
                sample_geometry['Center'] = [0.0, 0.0, 0.0]

            set_sample_alg.setProperty("Geometry", sample_geometry)

            sample_material = dict()
            if self._set_sample_method == 'Chemical Formula':
                sample_material[
                    'ChemicalFormula'] = self._sample_chemical_formula
            else:
                sample_material[
                    'CoherentXSection'] = self._sample_coherent_cross_section
                sample_material[
                    'IncoherentXSection'] = self._sample_incoherent_cross_section
                sample_material[
                    'AttenuationXSection'] = self._sample_attenuation_cross_section
                sample_material[
                    'ScatteringXSection'] = self._sample_coherent_cross_section + self._sample_incoherent_cross_section

            if self._sample_density_type == 'Mass Density':
                sample_material['SampleMassDensity'] = self._sample_density
            if self._sample_density_type == 'Number Density':
                sample_material['SampleNumberDensity'] = self._sample_density
                sample_material[
                    'NumberDensityUnit'] = self._sample_number_density_unit
            set_sample_alg.setProperty("Material", sample_material)

        if 'Container' in components:
            container_geometry = dict()
            container_geometry['Height'] = self._height

            if self._shape == 'FlatPlate':
                container_geometry['Shape'] = 'FlatPlateHolder'
                container_geometry['Width'] = self._sample_width
                # we need to know the thickness and the centre of the sample as well,
                # in order to calculate the centre offsets for the container panels
                container_geometry['Thick'] = self._sample_thickness
                container_geometry['Center'] = [0.0, 0.0, self._sample_center]
                container_geometry['Angle'] = self._sample_angle
                container_geometry[
                    'FrontThick'] = self._container_front_thickness
                container_geometry[
                    'BackThick'] = self._container_back_thickness

            if self._shape == 'Cylinder':
                container_geometry['Shape'] = 'HollowCylinder'
                container_geometry['InnerRadius'] = self._sample_radius
                container_geometry['OuterRadius'] = self._container_radius
                container_geometry['Center'] = [0.0, 0.0, 0.0]

            if self._shape == 'Annulus':
                container_geometry['Shape'] = 'HollowCylinderHolder'
                container_geometry[
                    'InnerRadius'] = self._container_inner_radius
                container_geometry[
                    'InnerOuterRadius'] = self._sample_inner_radius
                container_geometry[
                    'OuterInnerRadius'] = self._sample_outer_radius
                container_geometry[
                    'OuterRadius'] = self._container_outer_radius
                container_geometry['Center'] = [0.0, 0.0, 0.0]

            if can_as_sample:
                set_sample_alg.setProperty("Geometry", container_geometry)
            else:
                set_sample_alg.setProperty("ContainerGeometry",
                                           container_geometry)

            container_material = dict()
            if self._set_can_method == 'Chemical Formula':
                container_material[
                    'ChemicalFormula'] = self._container_chemical_formula
            else:
                container_material[
                    'CoherentXSection'] = self._container_coherent_cross_section
                container_material[
                    'IncoherentXSection'] = self._container_incoherent_cross_section
                container_material[
                    'AttenuationXSection'] = self._container_attenuation_cross_section
                container_material[
                    'ScatteringXSection'] = self._container_coherent_cross_section + self._container_incoherent_cross_section

            if self._container_density_type == 'Mass Density':
                container_material[
                    'SampleMassDensity'] = self._container_density
            if self._container_density_type == 'Number Density':
                container_material[
                    'SampleNumberDensity'] = self._container_density
                container_material[
                    'NumberDensityUnit'] = self._container_number_density_unit

            if can_as_sample:
                set_sample_alg.setProperty("Material", container_material)
            else:
                set_sample_alg.setProperty("ContainerMaterial",
                                           container_material)

        set_sample_alg.execute()
예제 #4
0
 def do_test_copyable(self, copy_op):
     original = Sample()
     width = 1.0
     height = 2.0
     thickness = 3.0
     original.setThickness(thickness)
     original.setHeight(height)
     original.setWidth(width)
     # make copy
     cp = copy_op(original)
     # Check identity different
     self.assertNotEqual(id(original), id(cp))
     # Simple tests that cp is equal to original
     self.assertEqual(original.getHeight(), cp.getHeight())
     self.assertEqual(original.getWidth(), cp.getWidth())
     self.assertEqual(original.getThickness(), cp.getThickness())
     # Check really did succeed and is not tied in any way to original
     del original
     self.assertTrue(id(cp) > 0)
     self.assertEqual(height, cp.getHeight())
     self.assertEqual(width, cp.getWidth())
     self.assertEqual(thickness, cp.getThickness())
예제 #5
0
 def test_get_shape_xml(self):
     sample = Sample()
     shape = sample.getShape()
     xml = shape.getShapeXML()
     self.assertEqual(type(xml), str)
예제 #6
0
 def test_get_shape(self):
     sample = Sample()
     self.assertEqual(type(sample.getShape()), CSGObject)
예제 #7
0
 def test_geometry_getters_and_setters(self):
     sample = Sample()
     sample.setThickness(12.5)
     self.assertEqual(sample.getThickness(), 12.5)
     sample.setHeight(10.2)
     self.assertEqual(sample.getHeight(), 10.2)
     sample.setWidth(5.9)
     self.assertEqual(sample.getWidth(), 5.9)
    def _set_sample(self, ws, components):
        ws.setSample(Sample())

        sample_geometry = dict()
        sample_material = dict()
        container_geometry = dict()
        container_material = dict()

        if 'Sample' in components:
            if self._shape == 'Preset':
                ws.sample().setShape(self._sample_shape)
            else:
                sample_geometry['Height'] = self._height

                if self._shape == 'FlatPlate':
                    sample_geometry['Shape'] = 'FlatPlate'
                    sample_geometry['Width'] = self._sample_width
                    sample_geometry['Thick'] = self._sample_thickness
                    sample_geometry['Center'] = [0.0, 0.0, self._sample_center]
                    sample_geometry['Angle'] = self._sample_angle

                if self._shape == 'Cylinder':
                    sample_geometry['Shape'] = 'Cylinder'
                    sample_geometry['Radius'] = self._sample_radius
                    sample_geometry['Center'] = [0.0, 0.0, 0.0]

                if self._shape == 'Annulus':
                    sample_geometry['Shape'] = 'HollowCylinder'
                    sample_geometry['InnerRadius'] = self._sample_inner_radius
                    sample_geometry['OuterRadius'] = self._sample_outer_radius
                    sample_geometry['Center'] = [0.0, 0.0, 0.0]

            # may want to override material even if shape=Preset
            sample_material = self._set_material_dict('sample')

        if 'Container' in components:
            if self._shape == 'Preset':
                ws.sample().setEnvironment(self._sample_env)
            else:
                container_geometry['Height'] = self._height

                if self._shape == 'FlatPlate':
                    container_geometry['Shape'] = 'FlatPlateHolder'
                    container_geometry['Width'] = self._sample_width
                    # we need to know the thickness and the centre of the sample as well,
                    # in order to calculate the centre offsets for the container panels
                    container_geometry['Thick'] = self._sample_thickness
                    container_geometry['Center'] = [
                        0.0, 0.0, self._sample_center
                    ]
                    container_geometry['Angle'] = self._sample_angle
                    container_geometry[
                        'FrontThick'] = self._container_front_thickness
                    container_geometry[
                        'BackThick'] = self._container_back_thickness

                if self._shape == 'Cylinder':
                    container_geometry['Shape'] = 'HollowCylinder'
                    container_geometry['InnerRadius'] = self._sample_radius
                    container_geometry['OuterRadius'] = self._container_radius
                    container_geometry['Center'] = [0.0, 0.0, 0.0]

                if self._shape == 'Annulus':
                    container_geometry['Shape'] = 'HollowCylinderHolder'
                    container_geometry[
                        'InnerRadius'] = self._container_inner_radius
                    container_geometry[
                        'InnerOuterRadius'] = self._sample_inner_radius
                    container_geometry[
                        'OuterInnerRadius'] = self._sample_outer_radius
                    container_geometry[
                        'OuterRadius'] = self._container_outer_radius
                    container_geometry['Center'] = [0.0, 0.0, 0.0]

                container_material = self._set_material_dict('container')

        if sample_geometry or sample_material or container_geometry or container_material:
            set_sample_alg = self.createChildAlgorithm("SetSample",
                                                       enableLogging=False)
            set_sample_alg.setProperty("InputWorkspace", ws)
            set_sample_alg.setProperty("Geometry", sample_geometry)
            set_sample_alg.setProperty("Material", sample_material)
            set_sample_alg.setProperty("ContainerGeometry", container_geometry)
            set_sample_alg.setProperty("ContainerMaterial", container_material)
            set_sample_alg.execute()
예제 #9
0
 def test_equals(self):
     a = Sample()
     b = Sample()
     self.assertEqual(a, b)
     b.setThickness(10)
     self.assertNotEqual(a, b)