API Reference#

Run#

class postopus.octopus_run.Run(basedir: Path = PosixPath('.'))#

Starting point for users of Postopus.

Root object for Postopus, initializing the module and providing access to all data and functions.

System and Calculation modes#

class postopus.datacontainers.system.System(systemname: str, rootpath: Path, mode_field_info: OutputCollectorSystem, parent: Run)#

The System class provides a dict with all found calculation modes written for the system.

Parameters:
  • systemname – Name of this system

  • rootpath – Path to the Octopus output (not system folder)

  • mode_field_info – Calculation modes including the outputs of each calculation mode.

class postopus.datacontainers.calculationmodes.CalculationModes(mode: str, outputs_in_mode: CalcModeFiles, parent: System, systemdir: Path, systemname: str)#

Class that build a dict of all outputs present in a system for a given CalculationMode output.

Parameters:
  • mode – Name of the calculation mode in the output. Naming like in Octopus’ output (e. g. ‘td’, ‘scf’, …)

  • outputs_in_mode – outputs contained in the given calculation mode for this system

  • systemdir – directory in the filesystem which contains the output (folder ‘output_iter’) for one of the simulated systems in a run with Octopus

  • systemname – Name of the system, as found in OutputCollector.

Output proxy#

class postopus.datacontainers.output_proxy.OutputProxy(parent: CalculationModes, output_field: OutputField)#

Base class to wrap outputs of Octopus.

To access the data of an output the output proxy has to be called:

>>> from pospotus import Run
>>> run = Run("path/to/octopusdata")
>>> convergence_data = run.default.scf.convergence()

As the data provided by Octopus is very diverse the interface of the output proxy depends on the accessed output. E.g. for “density” (or any other output in the output_iter/ folder) calling the proxy requires the source as an additional parameter (run.default.scf.density('.vtk')) returning an instance of xarray.DataArray. An additional attribute available_sources (run.default.scf.density.available_sources) is provided in this case. Other outputs like “convergence” is callable without any additional parameters and provides a pandas.Dataframe.

It is possible to define the interface for an output by subclassing the OutputProxy. One way is to define the interface for one specific output by defining the attribute __output__. E.g. to define an own interface for the output ‘convergence’:

>>> class ConvergenceProxy(OutputProxy):
...     __output__ = "convergence"
...     def __call__(self):
...         with open(self._available_files[0]) as f:
...             return f.readlines()

To register a more generalized class, one has to define a _match method. This method should return true if for a given field the class is suitable and false if not. E.g. the _match method of the class which handles scalar and vector fields returnes True for ‘density’ but False for ‘info’ or ‘convergence’.

>>> class MyOutput(OutputProxy):
...     @classmethod
...     def _match(cls, output) -> bool:
...         return MyOwnIndexVariant() in output.other_index.keys():
...     def __call__(self):
...         ...

Finding the correct class for an given output follows the rules:

  1. If a class with the __output__ attribute is defined and the value matches the name of the output that class is used. Defining a new class with the same value in __output__ overwrites the previous class (the latest defined class is used).

  2. If no class with a matching __output__ attribute is found the classes defining the _match method are considered. If this method returnes True for one class this class is used. Here, the classes defined first will be checked first.

  3. If no suitable class is found, DefaultOutputProxy will be used.

class postopus.datacontainers.output_proxy.field.FieldOutput(parent: CalculationModes, output_field: OutputField)#

Proxy for Scalar and vector fields. Calling the object returns a xarray DataArray (for scalars) or a Dataset (for vectors).

The given array provides all dimsions given by the files (e.g. all iteration steps). The values of the array are accessed lazy to avoid any performance issues.

To get the data the proxy has to be called with the desired source, like data = run.default.td.density(“.ncdf”). For a vector the vector compenents are vx, vy and vz (as x/y/z refers to the spatial coordinats).

property available_sources: list[str]#

List the available sources usable to load the data.

class postopus.datacontainers.output_proxy.static.StaticOutput(parent: CalculationModes, output_field: OutputField)#

Proxy for outputs in run/static like info, convergence, etc.

class postopus.datacontainers.output_proxy.static.Info(parent: CalculationModes, output_field: OutputField)#

Proxy class specific for the info file

class postopus.datacontainers.output_proxy.tdgeneral.TDGeneralVectorField(parent: CalculationModes, output_field: OutputField)#

Proxy for files in run/td.general