PENGEOM

Base classes

Definition of base PENGEOM classes.

class pypenelopetools.pengeom.base.GeometryBase[source]

Bases: object

Base class for geometry objects.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 48
_abc_registry = <_weakrefset.WeakSet object>
_create_expline(keyword, value, termination='')[source]

Creates a exponent line. This type of line is characterised by a keyword, a value express as an exponent (see _toexponent()) and a termination string. The keyword and the total length of the line is checked not to exceed their respective maximum size.

Parameters:
  • keyword (str) – 8-character keyword.
  • value (float) – value of the keyword.
  • termination (str, optional) – comment associated with the line.
_create_line(keyword, text, termination='')[source]

Creates an input line from the specified keyword, text and comment. The white space between the items is automatically adjusted to fit the line size. The keyword and the total length of the line is checked not to exceed their respective maximum size.

Parameters:
  • keyword (str) – 8-character keyword.
  • text (str) – value of the keyword.
  • termination (str, optional) – comment associated with the line.
_parse_expline(line)[source]
_parse_line(line)[source]
_peek_next_line(fileobj)[source]

Returns the next line without advancing the current position.

Parameters:fileobj (file object) – File object opened with read access.
Returns:Next line, stripped of all trailing white spaces.
Return type:str
_read(fileobj, material_lookup, surface_lookup, module_lookup)[source]

Reads file object.

Parameters:
  • fileobj (file object) – File object opened with read access.
  • material_lookup (dict(int, Material)) – A lookup table for the materials used in the geometry. Dictionary where the keys are material indexes in the geometry file and the values, Material instances.
  • surface_lookup (dict(int, Surface)) – A lookup table for surfaces used in the geometry. Dictionary where the keys are surface indexes in the geometry file and the values, Surface instances.
  • module_lookup (dict(int, Module)) – A lookup table for modules used in the geometry. Dictionary where the keys are module indexes in the geometry file and the values, Module instances.
_read_next_line(fileobj)[source]

Returns the next line and advances the current position.

Parameters:fileobj (file object) – File object opened with read access.
Returns:Next line, stripped of all trailing white spaces.
Return type:str
_write(fileobj, index_lookup)[source]

Writes to file object.

Parameters:
  • fileobj (file object) – File object opened with write access.
  • index_lookup (dict(GeometryBase, int)) – A lookup table for the surfaces, modules and materials of the associated geometry. Each component is assigned an index by the method indexify. Dictionary where the keys are surfaces, modules and materials instances, and the values, an integer index.
pypenelopetools.pengeom.base._toexponent(number)[source]

Formats exponent to PENELOPE format (E22.15)

Parameters:number (Float) – Number to format
Returns:number to PENELOPE format (E22.15)
Return type:str

Mixins used to create geometry objects.

class pypenelopetools.pengeom.mixin.DescriptionMixin[source]

Bases: object

Mixin that adds a description property.

description

str – Description of the geometry object.

class pypenelopetools.pengeom.mixin.ModuleMixin[source]

Bases: object

Mixin that adds methods to add, pop and clear modules.

add_module(module)[source]

Adds a module.

Parameters:module (Module) – Module to add.
clear_modules()[source]

Clear all modules.

get_modules()[source]
Returns:All modules.
Return type:tuple
pop_module(module)[source]

Removes a module.

Parameters:module (Module) – Module to remove.

Definition of geometrical transformations.

class pypenelopetools.pengeom.transformation.Rotation(omega_deg=0.0, theta_deg=0.0, phi_deg=0.0)[source]

Bases: pypenelopetools.pengeom.base.GeometryBase

Represents a rotation using 3 Euler angles (YZY).

Parameters:
  • omega_deg (float) – Rotation around the z-axis (deg).
  • theta_deg (float) – Rotation around the y-axis (deg).
  • phi_deg (float) – Rotation around the new z-axis (deg).
omega_deg

float – Rotation around the z-axis (deg). The value must be between 0 and 360.

phi_deg

float – Rotation around the new z-axis (deg). The new z-axis refer to the axis after the omega and theta rotation were applied on the original coordinate system. The value must be between 0 and 360.

theta_deg

float – Rotation around the y-axis (deg). The value must be between 0 and 360.

class pypenelopetools.pengeom.transformation.Scale(x=1.0, y=1.0, z=1.0)[source]

Bases: pypenelopetools.pengeom.base.GeometryBase

Represents scaling.

Parameters:
  • x (float) – Scaling along the x direction.
  • y (float) – Scaling along the y direction.
  • z (float) – Scaling along the z direction.
x

float – Scaling along the x direction. The value cannot be 0.

y

float – Scaling along the y direction. The value cannot be 0.

z

float – Scaling along the z direction. The value cannot be 0.

class pypenelopetools.pengeom.transformation.Shift(x_cm=0.0, y_cm=0.0, z_cm=0.0)[source]

Bases: pypenelopetools.pengeom.base.GeometryBase

Represents a translation in space.

Parameters:
  • x_cm (float) – Translation along the x direction (cm).
  • y_cm (float) – Translation along the y direction (cm).
  • z_cm (float) – Translation along the z direction (cm).
x_cm

float – Translation along the x direction (cm).

y_cm

float – Translation along the y direction (cm).

z_cm

float – Translation along the z direction (cm).

Geometry

Geometry definition for PENGEOM.

class pypenelopetools.pengeom.geometry.Geometry(title='Untitled', tilt_deg=0.0, rotation_deg=0.0)[source]

Bases: pypenelopetools.pengeom.mixin.ModuleMixin, pypenelopetools.pengeom.base.GeometryBase

Creates a new PENELOPE geometry.

Parameters:
  • title (str, optional) – Title of the geometry.
  • tilt_deg (float, optional) – Specimen tilt in degrees along the x-axis.
  • rotation_deg (float, optional) – Specimen rotation in degrees along the z-axis
add_module(module)

Adds a module.

Parameters:module (Module) – Module to add.
clear_modules()

Clear all modules.

get_materials()[source]

Returns all materials in this geometry.

get_modules()
Returns:All modules.
Return type:tuple
get_surfaces()[source]

Returns all surfaces in this geometry.

indexify()[source]

Returns a lookup table which associates the surfaces, modules and materials of this geometry to their index used in the geometry file. The lookup table is a dictionary where the keys are surfaces, modules and materials instances, and the values, an integer index.

pop_module(module)

Removes a module.

Parameters:module (Module) – Module to remove.
read(fileobj, material_lookup)[source]

Reads a geometry file (.geo).

Parameters:
  • fileobj (file object) – File object opened with read access.
  • material_lookup (dict(int, Material)) – A lookup table for the materials used in the geometry. Dictionary where the keys are material indexes in the geometry file and the values, Material instances.
rotation_deg

Specimen rotation in degrees along the z-axis

tilt_deg

Specimen tilt in degrees along the x-axis

title

Title of the geometry. The title must have less than 61 characters.

write(fileobj, index_lookup=None)[source]

Writes the geometry file (.geo) to create this geometry.

Parameters:
  • fileobj (file object) – File object opened with write access.
  • index_lookup (dict(GeometryBase, int), optional) – A lookup table for the surfaces, modules and materials of this geometry. If None, the index lookup is generated by the method indexify.
Returns:

lookup table

Return type:

dict(GeometryBase, int)

Surfaces

Definition of surfaces.

class pypenelopetools.pengeom.surface.SurfaceImplicit(coefficients=None, description='')[source]

Bases: pypenelopetools.pengeom.surface.SurfaceBase

Definition of an implicit surface.

Parameters:
  • coefficients (dict(str, float) or list(float)) – Coefficients for the implicit form of the quadratic equation. If the argument is a dict, the keys are the names of coefficient (e.g. xx) and the values the coefficient values. If the argument is a list, the list must contain 10 values, one for each coefficient.
  • description (str) – Description of the surface
coefficients

(dict(str, float) or list(float)) – Coefficients for the implicit form of the quadratic equation. If the value is a dict, the keys are the names of coefficient (e.g. xx) and the values the coefficient values. If the argument is a list, the list must contain 10 values, one for each coefficient.

Examples

>>> s = Surface()
>>> s.coefficients = {'xx': 0.0, 'xy': 0.0, 'xz': 0.0, 'yy': 0.0, 'yz': 0.0, 'zz': 0.0, 'x': 0.0, 'y': 0.0, 'z': 0.0, '0': 0.0}
>>> s.coefficients = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
>>> s.coefficients = {'xx': 1.0, 'xy': 1.0}
description

str – Description of the geometry object.

rotation

Rotation – Rotation of the surface.

shift

Shift – Shift/translation of the surface.

class pypenelopetools.pengeom.surface.SurfaceReduced(indices=None, description='')[source]

Bases: pypenelopetools.pengeom.surface.SurfaceBase

Definition of a reduced/explicit surface.

Parameters:
  • indices (tuple(int)) – Indices for the explicit form of the quadratic equation. Indices are 5 integers (-1, 0 or 1) defining the surface.
  • description (str) – Description of the surface
description

str – Description of the geometry object.

indices

(tuple(int)) – Indices for the explicit form of the quadratic equation. Indices are 5 integers (-1, 0 or 1) defining the surface.

rotation

Rotation – Rotation of the surface.

scale

Scale – Scaling of the surface.

shift

Shift – Shift/translation of the surface.

pypenelopetools.pengeom.surface.xplane(x_cm)[source]

Returns a surface for a plane X=x.

Parameters:x_cm (float) – Intercept on the x-axis (in cm).
Returns:SurfaceReduced
pypenelopetools.pengeom.surface.yplane(y_cm)[source]

Returns a surface for a plane Y=y.

Parameters:y_cm (float) – Intercept on the y-axis (in cm).
Returns:SurfaceReduced
pypenelopetools.pengeom.surface.zplane(z_cm)[source]

Returns a surface for a plane Z=z.

Parameters:z_cm (float) – Intercept on the z-axis (in cm).
Returns:SurfaceReduced
pypenelopetools.pengeom.surface.cylinder(radius_cm, axis='x')[source]

Returns a surface for a cylinder along axis with radius.

Parameters:
  • radius_cm (float) – Radius of the cylinder (in cm).
  • axis (str) – Axis of the cylinder, either x, y or z.
Returns:

SurfaceReduced

pypenelopetools.pengeom.surface.sphere(radius_cm)[source]

Returns a surface for a sphere or radius.

Parameters:radius_cm (float) – Radius of the sphere (in cm).
Returns:SurfaceReduced

Module

Definition of module.

class pypenelopetools.pengeom.module.Module(material=None, description='')[source]

Bases: pypenelopetools.pengeom.mixin.DescriptionMixin, pypenelopetools.pengeom.mixin.ModuleMixin, pypenelopetools.pengeom.base.GeometryBase

Definition of a module.

Parameters:
  • material (Material, optional) – Material associated with this module. If None, the material is set to VACUUM.
  • description (str) – Description of the module
add_surface(surface, pointer)[source]

Adds a surface.

Parameters:
clear_surfaces()[source]

Clear all surfaces.

get_surface_pointer(surface)[source]

Returns the surface pointer for the specified surface.

Parameters:surface (SurfaceImplicit or SurfaceReduced) – Surface of interest.
Returns:Side pointer.
Return type:SidePointer
get_surfaces()[source]
Returns:All surfaces.
Return type:tuple
pop_surface(surface)[source]

Removes a surface.

Parameters:surface (SurfaceImplicit or SurfaceReduced) – Surface to remove.
rotation

Rotation – Rotation of the module.

shift

Shift – Shift/translation of the module.

class pypenelopetools.pengeom.module.SidePointer[source]

Bases: enum.IntEnum

Whether the surface is pointing in the positive or negative direction.

NEGATIVE = -1

Negative direction.

POSITIVE = 1

Positive direction.