pyg4ometry.gdml¶
Subpackages¶
Submodules¶
Classes¶
Read a GDML file. |
|
This class provides an interface to GDML material definitions. |
|
This class provides an interface to GDML material definitions. Because of the different options |
|
This class that handles isotopes as components of composite materials. An element can be |
|
Holds an expression as a string and can use the expression parser |
|
Common bits for a define. Must have a name and a registry. Adding |
|
Base class for all scalars (Constants, Quantity, Variable and 'Expression') |
|
GDML constant define wrapper object |
|
GDML quantity define wrapper object |
|
GDML variable define wrapper object |
|
General expression, does not have an analogue in GDML |
|
GDML position define wrapper object |
|
GDML rotation define wrapper object |
|
GDML scale define wrapper object |
|
GDML matrix define wrapper object |
|
Auxiliary information container object |
Functions¶
|
|
|
|
|
Take a float, str, ScalarBase and return string expression. |
|
|
|
Helper functions that takes a string and returns an expression object or a string |
|
Take a list [x,y,z] and create a vector |
|
Take a list of lists [[rx,ry,rz],[x,y,z]] and create a transformation [Rotation,Position] |
|
|
|
Sin of a ScalarBase object, returns a Constant |
|
Cosine of a ScalarBase object, returns a Constant |
|
Tangent of a ScalarBase object, returns a Constant |
|
ArcSin of a ScalarBase object, returns a Constant |
|
ArcCos of a ScalarBase object, returns a Constant |
|
ArcTan of a ScalarBase object, returns a Constant |
|
Exponential of a ScalarBase object, returns a Constant |
|
Natural logarithm of a ScalarBase object, returns a Constant |
|
Base 10 logarithm of a ScalarBase object, returns a Constant |
|
Square root of a ScalarBase object, returns a Constant |
|
arg raised to power |
|
absolute value of arg |
|
absolute value of arg |
|
absolute value of arg |
|
Creates a GDML Matrix from an energy and a value vector |
Package Contents¶
- pyg4ometry.gdml.isComment(node)¶
- class pyg4ometry.gdml.Reader(fileName, registryOn=True, skipMaterials=False, reduceNISTMaterialsToPredefined=False)¶
Read a GDML file.
- Parameters:
When loading a GDML file that was exported by Geant4, the NIST materials may be fully expanded to include their full element / isotope composition. With the reduceNISTMaterialsToPredefined flag set to True, these will be ignored and the materials that have a name that matches a NIST one will be ‘reduced’ back to a predefined material by name only.
- filename¶
- registryOn¶
- _reduceNISTMaterialsToPredefined¶
- _skipMaterials¶
- _physVolumeNameCount¶
- load()¶
- getRegistry()¶
- parseDefines(xmldoc)¶
- parseVector(node, type='position', addRegistry=True)¶
- parseMaterials(xmldoc)¶
- _makeMaterials(materials, elements, isotopes)¶
Construct the isotopes, elements and materials in that order. These aren’t returned, but simply constructed in and therefore exist in the registry.
- parseUserInfo(xmldoc)¶
- _parseAuxiliary(xmlnode, register=True)¶
- parseSolids(xmldoc)¶
- parseBox(node)¶
- parseTube(node)¶
- parseCutTube(node)¶
- parseCone(node)¶
- parsePara(node)¶
- parseTrd(node)¶
- parseTrap(node)¶
- parseSphere(node)¶
- parseOrb(node)¶
- parseTorus(node)¶
- parsePolycone(node)¶
- parseGenericPolycone(node)¶
- parsePolyhedra(node)¶
- parseGenericPolyhedra(node)¶
- parseEllipticalTube(node)¶
- parseEllipsoid(node)¶
- parseEllipticalCone(node)¶
- parseParaboloid(node)¶
- parseHype(node)¶
- parseTet(node)¶
- parseExtrudedSolid(node)¶
- parseTwistedBox(node)¶
- parseTwistedTrap(node)¶
- parseTwistedTrd(node)¶
- parseTwistedTubs(node)¶
- parseGenericTrap(node)¶
- parseTessellatedSolid(node)¶
- parseUnion(node)¶
- parseSubtraction(node)¶
- parseIntersection(node)¶
- parseMultiUnion(node)¶
- parseOpticalSurface(node)¶
- parseScaledSolid(node)¶
- parseSolidLoop(node)¶
- parseStructure(xmldoc, materialSubstitutionNames=None)¶
- extractStructureNodeData(node, materialSubstitutionNames=None)¶
- parsePhysicalVolumeChildren(node, vol)¶
- pyg4ometry.gdml._StripPointer(name)¶
- class pyg4ometry.gdml._Material(**kwargs)¶
Bases:
MaterialBaseThis class provides an interface to GDML material definitions.
Because of the different options for constructing a material instance the constructor is kwarg only. Proxy methods are provided to instantiate particular types of material. Those proxy methods are:
MaterialSingleElement MaterialCompound MaterialPredefined
It is possible to instantiate a material directly through kwargs. The possible kwargs are (but note some are mutually exclusive): name - string density - float atomic_number - int atomic_weight - float number_of_components - int state - string pressure - float pressure_unit - string temperature - float temperature_unit - string
- density¶
- atomic_number¶
- atomic_weight¶
- number_of_components¶
- components = []¶
- properties¶
- _state_variables¶
- _NIST_compounds¶
- add_element_massfraction(element, massfraction)¶
Add an element as a component to a material as a fraction of the material mass. Can only add elements to materials defined as composite.
- Inputs:
element - pyg4ometry.geant4.Material.Element instance massfraction - float, 0.0 < massfraction <= 1.0
- add_element_natoms(element, natoms)¶
Add an element as a component to a material as a number of atoms in the material molecule. Can only add elements to materials defined as composite.
- Inputs:
element - pyg4ometry.geant4.Material.Element instance natoms - int, number of atoms in the compound molecule
- add_material(material, fractionmass)¶
Add a material as a component to another material (mixture) as a fraction of the mixture mass. Can only add new materials to materials defined as composite.
- Inputs:
material - pyg4ometry.geant4.Material.Material instance massfraction - float, 0.0 < massfraction <= 1.0
- set_pressure(value, unit='pascal')¶
- set_temperature(value, unit='K')¶
- property state_variables¶
- __str__()¶
- addProperty(name, matrix)¶
Add a material property from a matrix.
- addVecProperty(name, e, v, eunit='eV', vunit='')¶
Add a property from an energy and a value vector to this object.
- Parameters:
- class pyg4ometry.gdml._Element(**kwargs)¶
Bases:
MaterialBaseThis class provides an interface to GDML material definitions. Because of the different options for constructing a material instance the constructor is kwarg only. Proxy methods are provided to instantiate particular types of material. Those proxy methods are:
ElementSimple ElementIsotopeMixture
It is possible to instantiate a material directly through kwargs. The possible kwargs are (but note some are mutually exclusive): name - string symbol - string Z - int A - int n_comp - int
- symbol¶
- n_comp¶
- Z¶
- A¶
- components = []¶
- add_isotope(isotope, abundance)¶
Add an isotope as a component to an element as an abundance fraction in the element.
- Inputs:
element - pyg4ometry.geant4.Material.Isotope instance abundance - float, 0.0 < abundance <= 1.0
- class pyg4ometry.gdml._Isotope(name, Z, N, a, registry=None)¶
Bases:
MaterialBaseThis class that handles isotopes as components of composite materials. An element can be defined as a mixture of isotopes.
- Inputs:
name - string Z - int, atomic number N - int, mass number a - float, molar weight in g/mole
- Z¶
- N¶
- a¶
- type = 'isotope'¶
- class pyg4ometry.gdml.Writer(prepend='')¶
- prepend¶
- imp¶
- doc¶
- top¶
- defines¶
- materials¶
- solids¶
- structure¶
- userinfo¶
- setup¶
- materials_written = []¶
- solids_written = []¶
- defineList = []¶
- materialList = []¶
- solidList = []¶
- logicalVolumeList = []¶
- physicalVolumeList = []¶
- addDetector(registry)¶
- write(filename)¶
- writeGMADTesterNoBeamline(gmad, gdml)¶
- writeGmadTester(filenameGmad, filenameGDML, writeDefaultLattice=False, preprocessGDML=True, energy=250)¶
- writeDefaultLattice(filename='lattice.gmad')¶
- checkDefineName(defineName)¶
- checkMaterialName(materialName)¶
- checkSolidName(solidName)¶
- checkLogicalVolumeName(logicalVolumeName)¶
- checkPhysicalVolumeName(physicalVolumeName)¶
- writeVectorVariable(node, vector_var, allow_ref=True, suppress_trivial=True)¶
Writes an XML child node for a vector variable - position, rotation, scale. If allow_ref is enabled, it will write a ref to a registry define where possible. If suppress_trivial is enabled it won’t write vectors with all elements zero.
- writeDefine(define)¶
- writeMaterialProps(material, oe)¶
- writeMaterial(material)¶
- writeLogicalVolume(lv)¶
- writeAuxiliary(aux, parent=None)¶
- writeAssemblyVolume(lv)¶
- writePhysicalVolume(pv)¶
- writeReplicaVolume(instance)¶
- writeDivisionVolume(instance)¶
- writeParametrisedVolume(instance)¶
- writeSkinSurface(instance)¶
- writeBorderSurface(instance)¶
- writeSolid(solid)¶
Dispatch to correct member function based on type string in SolidBase.
- getValueOrExpr(var)¶
- getValueOrExprFromInstance(instance, variable, index=None)¶
- writeBox(instance)¶
- writeCons(instance)¶
- writeCutTubs(instance)¶
- writeEllipsoid(instance)¶
- writeEllipticalCone(instance)¶
- writeEllipticalTube(instance)¶
- createTwoDimVertex(x, y)¶
- createSection(zOrder, zPosition, xOffset, yOffset, scalingFactor)¶
- writeExtrudedSolid(instance)¶
- createrzPoint(r, z)¶
- writeGenericPolycone(instance)¶
- writeGenericPolyhedra(instance)¶
- createTriangularFacet(vertex1, vertex2, vertex3)¶
- createQuadrangularFacet(vertex1, vertex2, vertex3, vertex4)¶
- writeTessellatedSolid(instance)¶
- writeHype(instance)¶
- writeIntersection(instance)¶
- writeOpticalSurface(instance)¶
- writeOrb(instance)¶
- writePara(instance)¶
- writeParaboloid(instance)¶
- createzPlane(rInner, rOuter, zplane)¶
- writePolycone(instance)¶
- writePolyhedra(instance)¶
- writeSphere(instance)¶
- writeGenericTrap(instance)¶
- createPosition(name, x, y, z)¶
- writeTet(instance)¶
- writeTorus(instance)¶
- writeTrap(instance)¶
- writeTrd(instance)¶
- writeTubs(instance)¶
- writeTwistedBox(instance)¶
- writeTwistedTrd(instance)¶
- writeTwistedTrap(instance)¶
- writeTwistedTubs(instance)¶
- writeUnion(instance)¶
- writeSubtraction(instance)¶
- writeMultiUnion(instance)¶
- writeScaled(instance)¶
- class pyg4ometry.gdml.BasicExpression(name, expressionString, registry)¶
Holds an expression as a string and can use the expression parser in the supplied registry to evaluate it. A registry is required.
- Parameters:
name (str) – Name of the expression object
expressionString (str) – Expression itself as a string e.g. “12.0” or “a + 3.0”
registry (pyg4ometry.geant4.Registry.Registry) – The registry object to give context for any variables used.
>>> r = pyg4ometry.geant4.Registry() >>> a = BasicExpression("a", "3.0", r) >>> float(a) >>> str(a)
- name¶
- expressionString¶
- parseTree = None¶
- registry¶
- eval()¶
- variables(allDependents=False)¶
- simp()¶
- __repr__()¶
- __float__()¶
- str()¶
- pyg4ometry.gdml.upgradeToStringExpression(reg, obj)¶
Take a float, str, ScalarBase and return string expression.
- Parameters:
reg (Registry) – Registry for lookup in define dictionary
obj (str,float,ScalarBase) – Object to upgrade
- Returns:
String expression
- Return type:
- pyg4ometry.gdml.evaluateToFloat(reg, obj)¶
- pyg4ometry.gdml.upgradeToExpression(reg, obj)¶
Helper functions that takes a string and returns an expression object or a string
- pyg4ometry.gdml.upgradeToVector(var, reg, type='position', unit='', addRegistry=False)¶
Take a list [x,y,z] and create a vector
- pyg4ometry.gdml.upgradeToTransformation(var, reg, addRegistry=False)¶
Take a list of lists [[rx,ry,rz],[x,y,z]] and create a transformation [Rotation,Position]
- pyg4ometry.gdml.operationReturnType(name, strExpr, v1, v2, type1, type2, reg)¶
- class pyg4ometry.gdml.DefineBase(name='', registry=None)¶
Common bits for a define. Must have a name and a registry. Adding to the registry can’t be done here as it must be done by the derived type.
- name¶
- registry¶
- setRegistry(registry)¶
- class pyg4ometry.gdml.ScalarBase(typeName, name='', registry=None)¶
Bases:
DefineBaseBase class for all scalars (Constants, Quantity, Variable and ‘Expression’)
- expression = None¶
- _typeName¶
- setExpression(expressionString)¶
Take a string and make it into the BasicExpression type for this object.
- Parameters:
expressionString (str) – Expression to store.
- setRegistry(registry)¶
- __repr__()¶
- __float__()¶
- __add__(other)¶
- __sub__(other)¶
- __rsub__(other)¶
- __mul__(other)¶
- __truediv__(other)¶
- __rtruediv__(other)¶
- __neg__()¶
- __abs__()¶
- __pow__(power)¶
- __radd__¶
- __rmul__¶
- pyg4ometry.gdml.sin(arg)¶
Sin of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of sin
- pyg4ometry.gdml.cos(arg)¶
Cosine of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of cos
- pyg4ometry.gdml.tan(arg)¶
Tangent of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of tan
- pyg4ometry.gdml.asin(arg)¶
ArcSin of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of asin
- pyg4ometry.gdml.acos(arg)¶
ArcCos of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of acos
- pyg4ometry.gdml.atan(arg)¶
ArcTan of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of tan
- pyg4ometry.gdml.exp(arg)¶
Exponential of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of exp
- pyg4ometry.gdml.log(arg)¶
Natural logarithm of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of log
- pyg4ometry.gdml.log10(arg)¶
Base 10 logarithm of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of log10
- pyg4ometry.gdml.sqrt(arg)¶
Square root of a ScalarBase object, returns a Constant
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of sin
- pyg4ometry.gdml.pow(arg, power)¶
arg raised to power
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of x**y
power (float) – y
- pyg4ometry.gdml.abs(arg)¶
absolute value of arg
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of abs(arg)
- pyg4ometry.gdml.min(arg1, arg2)¶
absolute value of arg
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of abs(arg)
- pyg4ometry.gdml.max(arg1, arg2)¶
absolute value of arg
- Parameters:
arg (Constant, Quantity, Variable or Expression) – Argument of abs(arg)
- class pyg4ometry.gdml.Constant(name, value, registry, addRegistry=True)¶
Bases:
ScalarBaseGDML constant define wrapper object
- Parameters:
- expression¶
- __eq__(other)¶
- __ne__(other)¶
- __lt__(other)¶
- __gt__(other)¶
- __le__(other)¶
- __ge__(other)¶
- class pyg4ometry.gdml.Quantity(name, value, unit, type, registry, addRegistry=True)¶
Bases:
ScalarBaseGDML quantity define wrapper object
- Parameters:
- unit¶
- type¶
- expression¶
- __repr__()¶
- class pyg4ometry.gdml.Variable(name, value, registry, addRegistry=True)¶
Bases:
ScalarBaseGDML variable define wrapper object
- Parameters:
- expression¶
- class pyg4ometry.gdml.Expression(name, value, registry, addRegistry=False)¶
Bases:
ScalarBaseGeneral expression, does not have an analogue in GDML
- Parameters:
- expression¶
- __int__()¶
- class pyg4ometry.gdml.VectorBase(typeName, name, registry)¶
- _typeName¶
- name¶
- registry¶
- x = None¶
- y = None¶
- z = None¶
- unit = None¶
- __repr__()¶
- __add__(other)¶
- __sub__(other)¶
- __mul__(other)¶
- __rmul__¶
- __truediv__(other)¶
- nonzero()¶
Evaluate vector
- Returns:
Check if the vector is trivial (all elements zero)
- Return type:
- __getitem__(key)¶
- setRegistry(registry)¶
- class pyg4ometry.gdml.Position(name, x, y, z, unit='mm', registry=None, addRegistry=True)¶
Bases:
VectorBaseGDML position define wrapper object
- Parameters:
- x¶
- y¶
- z¶
- class pyg4ometry.gdml.Rotation(name, rx, ry, rz, unit='rad', registry=None, addRegistry=True)¶
Bases:
VectorBaseGDML rotation define wrapper object
- Parameters:
- x¶
- y¶
- z¶
- class pyg4ometry.gdml.Scale(name, sx, sy, sz, unit=None, registry=None, addRegistry=True)¶
Bases:
VectorBaseGDML scale define wrapper object
- Parameters:
- x¶
- y¶
- z¶
- class pyg4ometry.gdml.Matrix(name, coldim, values, registry=None, addRegistry=True)¶
GDML matrix define wrapper object
- Parameters:
- name¶
- coldim¶
- registry¶
- values = []¶
- values_asarray¶
- eval()¶
Evaluate matrix
- Returns:
numerical evaluation of matrix
- Return type:
numpy.array
- __repr__()¶
- __getitem__(key)¶
- pyg4ometry.gdml.MatrixFromVectors(e, v, name, registry, eunit='eV', vunit='')¶
Creates a GDML Matrix from an energy and a value vector
- Parameters:
name (str) – of matrix of registry
e (list or numpy.array - shape (1,)) – energy list/vector in units of eunit
v (list or numpy.array - shape (1,)) – value list/vector in units of vunit
registry (Registry) – for storing define
eunit (str) – unit for the energy vector (default: eV)
vunit (str) – unit for the value vector (default: unitless)
- class pyg4ometry.gdml.Auxiliary(auxtype, auxvalue, registry=None, unit='', addRegistry=True)¶
Auxiliary information container object
- auxtype¶
- auxvalue¶
- auxunit¶
- subaux = []¶
- registry¶
- addSubAuxiliary(aux)¶
Add a sub-auxiliary inside the scope of the current auxiliary
- Parameters:
aux (object, gdml.Defines.Auxiliary) – auxiliary definition