graintrace.neper_env#

Locate a user-provided NEPER binary and build a subprocess environment for it.

graintrace drives NEPER as an external tool; like CUBIT/SCULPT it is not a pip package and must be installed by the user. Install NEPER once (see https://neper.info/doc/introduction.html#installing-neper) and graintrace will find it, in this order:

  1. an explicit neper_path / env= passed to the builder,

  2. the NEPER environment variable (absolute path to the neper binary),

  3. the neper key of a graintrace_tools.json (see graintrace.mcp.tool_paths),

  4. neper on PATH (shutil.which).

gmsh, by contrast, is a pip package (declared in pyproject.toml and installed with graintrace), so it needs no discovery here.

For the convenience of a from-source build on Linux, pass auto_install=True (opt-in): it builds NEPER 7.0.0 into ~/.local against the Gmsh 4.15.2 SDK (unpacked into ~/.local/opt, linked via RPATH) with NEPER’s builtin GSL and the system gcc (see _neper7_build_plan()). The default path never downloads or compiles anything. graintrace requires NEPER 7.x (NEPER_REQUIRED_MAJOR; checked by resolve_neper_env()): the -morphooptialgo choices are subplex (graintrace’s default) and lloyd, Laguerre weights are power weights (r**2), and -transform cut(hspace(...)) uses the 7.x half-space sense.

graintrace.neper_env.ROTMAT_DESCRIPTOR = 'rotmat:active'#

the active R (crystal -> sample, = graintrace / MIDAS / neml2). NEPER’s own default (no suffix) is the passive g = R^T.

Type:

Descriptor graintrace asks NEPER to write orientation matrices in

graintrace.neper_env.NEPER_REQUIRED_MAJOR = 7#

NEPER major version graintrace is written against (hspace sense, weight units, optimizer names and empty cut cells all differ in 4.x).

graintrace.neper_env.split_descriptor(descriptor)[source]#

Split a NEPER orientation descriptor into (base, sense).

"rotmat:active" -> ("rotmat", "active"); no suffix means NEPER’s default, "passive".

Raises:

ValueError – if the suffix is neither active nor passive.

Parameters:

descriptor (str)

Return type:

Tuple[str, str]

graintrace.neper_env.euler_descriptor(descriptor='euler-bunge')[source]#

The explicit NEPER descriptor for graintrace Euler angles: <euler-*>:passive.

graintrace Euler angles are the standard (passive) triplet, so they are always handed to NEPER with an explicit :passive suffix rather than relying on NEPER’s default.

Parameters:

descriptor (str) – "euler-bunge", "euler-kocks" or "euler-roe", with or without ":passive".

Returns:

e.g. "euler-bunge:passive".

Return type:

str

Raises:

ValueError – for a non-Euler descriptor or an :active Euler triplet (the Euler angles of R^T, which graintrace never uses).

graintrace.neper_env.find_neper(neper_path=None)[source]#

Resolve the neper binary path, or None if it cannot be found.

Order: explicit neper_path -> NEPER env var -> tools.json neper key -> shutil.which("neper").

Parameters:

neper_path (str | None)

Return type:

str | None

graintrace.neper_env.build_env(neper_bin=None)[source]#

Copy os.environ and, given a neper_bin, put its dir/libs on the path.

Prepends the binary’s directory to PATH and the sibling lib/lib64 of its install prefix to LD_LIBRARY_PATH so a self-built NEPER (e.g. under ~/.local/bin) finds its GSL/OpenBLAS shared libraries.

Parameters:

neper_bin (str | None)

Return type:

dict

graintrace.neper_env.neper_version(neper_bin=None)[source]#

The neper --version string (e.g. "7.0.0"), or None if it cannot run.

Parameters:

neper_bin (str | None) – the binary; resolved with find_neper() when None.

Return type:

str | None

graintrace.neper_env.resolve_neper_env(neper_path=None, auto_install=False)[source]#

Return (neper_bin, env) for driving NEPER, or raise a clear error.

Looks NEPER up via find_neper(). If not found and auto_install is True, builds it from source under ~/.local (Linux only); otherwise raises RuntimeError with install guidance.

Parameters:
  • neper_path (str | None)

  • auto_install (bool)

Return type:

Tuple[str, dict]

graintrace.neper_env.laguerre_weights(radius)[source]#

NEPER 7 Laguerre seed weights for grains of equivalent radius radius.

NEPER 7 reads -morphooptiini weight:file(...) as the power-diagram weight w in squared length units (cell = points with |x - s|**2 - w minimal), so a grain of radius r gets w = r**2, in the same length unit as the coordinates and NOT normalised (normalising makes the weights negligible). NaN or negative radii become 0.

Parameters:

radius – array-like of equivalent grain radii (coordinate length units).

Returns:

numpy.ndarray of weights r**2.

Return type:

np.ndarray

graintrace.neper_env.require_neper_version(neper_bin)[source]#

Return the NEPER version string, raising unless it is NEPER 7.x.

graintrace builds NEPER command lines for 7.x semantics (see the module docstring); a 4.x binary would silently produce wrong cuts and weights.

Parameters:

neper_bin (str) – path to the neper binary.

Raises:

RuntimeError – if the version cannot be read or its major is not NEPER_REQUIRED_MAJOR.

Return type:

str

graintrace.neper_env.NEPER_AUTO_VERSION = '7.0.0'#

NEPER version built by auto_install=True and the Gmsh SDK it links against.