# Python API¶

OpenMC includes a rich Python API that enables programmatic pre- and post-processing. The easiest way to begin using the API is to take a look at the example Jupyter notebooks provided. However, this assumes that you are already familiar with Python and common third-party packages such as NumPy. If you have never programmed in Python before, there are many good tutorials available online. We recommend going through the modules from Codecademy and/or the Scipy lectures. The full API documentation serves to provide more information on a given module or class.

## openmc – Basic Functionality¶

### Handling nuclear data¶

#### Classes¶

 openmc.XSdata A multi-group cross section data set providing all the multi-group data necessary for a multi-group OpenMC calculation. openmc.MGXSLibrary Multi-Group Cross Sections file used for an OpenMC simulation.

#### Functions¶

 openmc.ace.ascii_to_binary Convert an ACE file in ASCII format (type 1) to binary format (type 2).

### Simulation Settings¶

 openmc.Source Distribution of phase space coordinates for source sites. openmc.ResonanceScattering Specification of the elastic scattering model for resonant isotopes openmc.Settings Settings file used for an OpenMC simulation.

### Material Specification¶

 openmc.Nuclide A nuclide that can be used in a material. openmc.Element A natural element used in a material via . openmc.Macroscopic A Macroscopic object that can be used in a material. openmc.Material A material composed of a collection of nuclides/elements that can be assigned to a region of space. openmc.Materials Collection of Materials used for an OpenMC simulation.

### Building geometry¶

 openmc.Plane An arbitrary plane of the form $$Ax + By + Cz = D$$. openmc.XPlane A plane perpendicular to the x axis of the form $$x - x_0 = 0$$ openmc.YPlane A plane perpendicular to the y axis of the form $$y - y_0 = 0$$ openmc.ZPlane A plane perpendicular to the z axis of the form $$z - z_0 = 0$$ openmc.XCylinder An infinite cylinder whose length is parallel to the x-axis of the form $$(y - y_0)^2 + (z - z_0)^2 = R^2$$. openmc.YCylinder An infinite cylinder whose length is parallel to the y-axis of the form $$(x - x_0)^2 + (z - z_0)^2 = R^2$$. openmc.ZCylinder An infinite cylinder whose length is parallel to the z-axis of the form $$(x - x_0)^2 + (y - y_0)^2 = R^2$$. openmc.Sphere A sphere of the form $$(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 = R^2$$. openmc.Cone A conical surface parallel to the x-, y-, or z-axis. openmc.XCone A cone parallel to the x-axis of the form $$(y - y_0)^2 + (z - z_0)^2 = R^2 (x - x_0)^2$$. openmc.YCone A cone parallel to the y-axis of the form $$(x - x_0)^2 + (z - z_0)^2 = R^2 (y - y_0)^2$$. openmc.ZCone A cone parallel to the x-axis of the form $$(x - x_0)^2 + (y - y_0)^2 = R^2 (z - z_0)^2$$. openmc.Quadric A surface of the form $$Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0$$. openmc.Halfspace A positive or negative half-space region. openmc.Intersection Intersection of two or more regions. openmc.Union Union of two or more regions. openmc.Complement Complement of a region. openmc.Cell A region of space defined as the intersection of half-space created by quadric surfaces. openmc.Universe A collection of cells that can be repeated. openmc.RectLattice A lattice consisting of rectangular prisms. openmc.HexLattice A lattice consisting of hexagonal prisms. openmc.Geometry Geometry representing a collection of surfaces, cells, and universes.

Many of the above classes are derived from several abstract classes:

 openmc.Surface An implicit surface with an associated boundary condition. openmc.Region Region of space that can be assigned to a cell. openmc.Lattice A repeating structure wherein each element is a universe.

One function is also available to create a hexagonal region defined by the intersection of six surface half-spaces.

 openmc.make_hexagon_region Create a hexagon region from six surface planes.

### Constructing Tallies¶

 openmc.Filter A filter used to constrain a tally to a specific criterion, e.g. openmc.Mesh A structured Cartesian mesh in two or three dimensions openmc.Trigger A criterion for when to finish a simulation based on tally uncertainties. openmc.Tally A tally defined by a set of scores that are accumulated for a list of nuclides given a set of filters. openmc.Tallies Collection of Tallies used for an OpenMC simulation.

### Coarse Mesh Finite Difference Acceleration¶

 openmc.CMFDMesh A structured Cartesian mesh used for Coarse Mesh Finite Difference (CMFD) acceleration. openmc.CMFD Parameters that control the use of coarse-mesh finite difference acceleration in OpenMC.

### Plotting¶

 openmc.Plot Definition of a finite region of space to be plotted, either as a slice plot in two dimensions or as a voxel plot in three dimensions. openmc.Plots Collection of Plots used for an OpenMC simulation.

### Running OpenMC¶

 openmc.run Run an OpenMC simulation. openmc.plot_geometry Run OpenMC in plotting mode

### Post-processing¶

 openmc.Particle Information used to restart a specific particle that caused a simulation to fail. openmc.StatePoint State information on a simulation at a certain point in time (at the end of a given batch). openmc.Summary Information summarizing the geometry, materials, and tallies used in a simulation.

Various classes may be created when performing tally slicing and/or arithmetic:

 openmc.arithmetic.CrossScore A special-purpose tally score used to encapsulate all combinations of two tally’s scores as an outer product for tally arithmetic. openmc.arithmetic.CrossNuclide A special-purpose nuclide used to encapsulate all combinations of two tally’s nuclides as an outer product for tally arithmetic. openmc.arithmetic.CrossFilter A special-purpose filter used to encapsulate all combinations of two tally’s filter bins as an outer product for tally arithmetic. openmc.arithmetic.AggregateScore A special-purpose tally score used to encapsulate an aggregate of a subset or all of tally’s scores for tally aggregation. openmc.arithmetic.AggregateNuclide A special-purpose tally nuclide used to encapsulate an aggregate of a subset or all of tally’s nuclides for tally aggregation. openmc.arithmetic.AggregateFilter A special-purpose tally filter used to encapsulate an aggregate of a subset or all of a tally filter’s bins for tally aggregation.

## openmc.stats – Statistics¶

### Univariate Probability Distributions¶

 openmc.stats.Univariate Probability distribution of a single random variable. openmc.stats.Discrete Distribution characterized by a probability mass function. openmc.stats.Uniform Distribution with constant probability over a finite interval [a,b] openmc.stats.Maxwell Maxwellian distribution in energy. openmc.stats.Watt Watt fission energy spectrum. openmc.stats.Tabular Piecewise continuous probability distribution.

### Angular Distributions¶

 openmc.stats.UnitSphere Distribution of points on the unit sphere. openmc.stats.PolarAzimuthal Angular distribution represented by polar and azimuthal angles openmc.stats.Isotropic Isotropic angular distribution. openmc.stats.Monodirectional Monodirectional angular distribution.

### Spatial Distributions¶

 openmc.stats.Spatial Distribution of locations in three-dimensional Euclidean space. openmc.stats.CartesianIndependent Spatial distribution with independent x, y, and z distributions. openmc.stats.Box Uniform distribution of coordinates in a rectangular cuboid. openmc.stats.Point Delta function in three dimensions.

## openmc.mgxs – Multi-Group Cross Section Generation¶

### Energy Groups¶

 openmc.mgxs.EnergyGroups An energy groups structure used for multi-group cross-sections.

### Multi-group Cross Sections¶

 openmc.mgxs.MGXS An abstract multi-group cross section for some energy group structure within some spatial domain. openmc.mgxs.AbsorptionXS An absorption multi-group cross section. openmc.mgxs.CaptureXS A capture multi-group cross section. openmc.mgxs.Chi The fission spectrum. openmc.mgxs.FissionXS A fission multi-group cross section. openmc.mgxs.KappaFissionXS A recoverable fission energy production rate multi-group cross section. openmc.mgxs.MultiplicityMatrixXS The scattering multiplicity matrix. openmc.mgxs.NuFissionXS A fission neutron production multi-group cross section. openmc.mgxs.NuFissionMatrixXS A fission production matrix multi-group cross section. openmc.mgxs.NuScatterXS A scattering neutron production multi-group cross section. openmc.mgxs.NuScatterMatrixXS A scattering production matrix multi-group cross section for one or more Legendre moments. openmc.mgxs.ScatterXS A scattering multi-group cross section. openmc.mgxs.ScatterMatrixXS A scattering matrix multi-group cross section for one or more Legendre moments. openmc.mgxs.TotalXS A total multi-group cross section. openmc.mgxs.TransportXS A transport-corrected total multi-group cross section.

### Multi-group Cross Section Libraries¶

 openmc.mgxs.Library A multi-group cross section library for some energy group structure.

## openmc.model – Model Building¶

### TRISO Fuel Modeling¶

#### Classes¶

 openmc.model.TRISO Tristructural-isotopic (TRISO) micro fuel particle

#### Functions¶

 openmc.model.create_triso_lattice Create a lattice containing TRISO particles for optimized tracking.