Sample#

This is a Python binding to the C++ class Mantid::API::Sample.

The sample object holds details of the samples in an experiment. While most of the time this will refer to a single sample, it can also describe a collection of samples. Specifically this holds information about a samples:

  • Material properties and chemical composition

  • Shape and dimensions

  • Crystal structure

Working with Sample objects in Python#

Getting the Sample Object from a Workspace#

ws=CreateWorkspace(DataX='1,2',DataY='1')
s=ws.sample()

Sample Properties#

ws = CreateSampleWorkspace("Histogram",NumBanks=1,BankPixelWidth=1)
s = ws.sample()

# Dimensions
s.setHeight(0.1)
s.setWidth(0.2)
s.setThickness(0.3)
print("Height: " + str(s.getHeight()))
print("Width: " + str(s.getWidth()))
print("Thickness: " + str(s.getThickness()))

# Material
SetSampleMaterial(ws,ChemicalFormula="V")
m = s.getMaterial()
print("Material Name " + str(m.name()))
print("Total scattering X-Section: " + str(m.totalScatterXSection()))

# Crystal Structure
SetUB(ws,a=2,b=3,c=4,alpha=90,beta=90,gamma=90,u="1,0,0",v="0,0,1")
ol=s.getOrientedLattice()
print("Data lattice parameters are: {0} {1} {2} {3} {4} {5} ".format(ol.a(),ol.b(),ol.c(),ol.alpha(),ol.beta(),ol.gamma()))

Multiple Samples#

The Sample() method actually returns a collection, however if you do not specify which sample you want you will get the first member of the collection.

ws = CreateSampleWorkspace("Histogram",NumBanks=1,BankPixelWidth=1)

s = ws.sample()
# Is the same as
s = ws.sample()[0]

# You can ask how many samples there are with
size = ws.sample().size()

Reference#

class mantid.api.Sample#
clearCrystalStructure((Sample)self) None :#

Removes the internally stored crystal structure.

clearOrientedLattice((Sample)self) None :#

Clears any attached lattice information

getCrystalStructure((Sample)self) mantid.geometry._geometry.CrystalStructure :#

Get the crystal structure for this sample

getEnvironment((Sample)self) mantid.geometry._geometry.SampleEnvironment :#

Returns the sample environment

getGeometryFlag((Sample)self) int :#

Return the geometry flag.

getHeight((Sample)self) float :#

Return the height in mm

getMaterial((Sample)self) mantid.kernel._kernel.Material :#

The material the sample is composed of

getName((Sample)self) str :#

Returns the string name of the sample

getOrientedLattice((Sample)self) mantid.geometry._geometry.OrientedLattice :#

Get the oriented lattice for this sample

getShape((Sample)arg1) mantid.geometry._geometry.IObject :#

Returns the shape of the Sample

getThickness((Sample)self) float :#

Return the thickness in mm

getWidth((Sample)self) float :#

Return the width in mm

hasCrystalStructure((Sample)self) bool :#

Returns True if this sample has a crystal structure, false otherwise

hasEnvironment((Sample)self) bool :#

Returns True if the sample has an environment defined

hasOrientedLattice((Sample)self) bool :#

Returns True if this sample has an oriented lattice, false otherwise

hasShape((Sample)self) bool :#

Returns True if the sample has a shape defined

setCrystalStructure((Sample)self, (mantid.geometry._geometry.CrystalStructure)newCrystalStructure) None :#

Assign a crystal structure object to the sample.

setEnvironment((Sample)self, (mantid.geometry._geometry.SampleEnvironment)env) None :#

Set the sample environment

setGeometryFlag((Sample)self, (int)geom_id) None :#

Set the geometry flag.

setHeight((Sample)self, (float)height) None :#

Set the height in mm.

setShape((Sample)self, (mantid.geometry._geometry.IObject)shape) None :#

Set shape of Sample object.

setThickness((Sample)self, (float)thick) None :#

Set the thickness in mm.

setWidth((Sample)self, (float)width) None :#

Set the width in mm.

size((Sample)self) int :#

Return the number of samples contained within this sample