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:
an explicit
neper_path/env=passed to the builder,the
NEPERenvironment variable (absolute path to theneperbinary),the
neperkey of agraintrace_tools.json(seegraintrace.mcp.tool_paths),
neperonPATH(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 passiveg = 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
activenorpassive.- Parameters:
descriptor (str)
- Return type:
- 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
:passivesuffix 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:
- Raises:
ValueError – for a non-Euler descriptor or an
:activeEuler triplet (the Euler angles ofR^T, which graintrace never uses).
- graintrace.neper_env.find_neper(neper_path=None)[source]#
Resolve the
neperbinary path, orNoneif it cannot be found.Order: explicit
neper_path->NEPERenv var -> tools.jsonneperkey ->shutil.which("neper").
- graintrace.neper_env.build_env(neper_bin=None)[source]#
Copy
os.environand, given aneper_bin, put its dir/libs on the path.Prepends the binary’s directory to
PATHand the siblinglib/lib64of its install prefix toLD_LIBRARY_PATHso a self-built NEPER (e.g. under~/.local/bin) finds its GSL/OpenBLAS shared libraries.
- graintrace.neper_env.neper_version(neper_bin=None)[source]#
The
neper --versionstring (e.g."7.0.0"), orNoneif it cannot run.- Parameters:
neper_bin (str | None) – the binary; resolved with
find_neper()whenNone.- 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 andauto_installis True, builds it from source under~/.local(Linux only); otherwise raisesRuntimeErrorwith install guidance.
- 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 weightwin squared length units (cell = points with|x - s|**2 - wminimal), so a grain of radiusrgetsw = 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.ndarrayof weightsr**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
neperbinary.- Raises:
RuntimeError – if the version cannot be read or its major is not
NEPER_REQUIRED_MAJOR.- Return type:
- graintrace.neper_env.NEPER_AUTO_VERSION = '7.0.0'#
NEPER version built by
auto_install=Trueand the Gmsh SDK it links against.