Metadata-Version: 2.4
Name: pymats
Version: 0.1.4
Summary: A python module for handling materials
Author-email: Sebastian Mau <klixz09@gmail.com>
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: numpy<3,>=1.24
Requires-Dist: scipy<2,>=1.10
Requires-Dist: pandas<4,>=2
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: pydantic-settings<3,>=2
Requires-Dist: pymongo<5,>=4.6
Requires-Dist: requests<3,>=2.31
Requires-Dist: PyYAML<7,>=6
Provides-Extra: api
Requires-Dist: fastapi<1,>=0.115; extra == "api"
Requires-Dist: uvicorn[standard]<1,>=0.30; extra == "api"
Requires-Dist: pydantic[email]<3,>=2.7; extra == "api"
Requires-Dist: aiosmtplib<6,>=3; extra == "api"
Requires-Dist: PyJWT<3,>=2.8; extra == "api"
Requires-Dist: pytz>=2024; extra == "api"
Provides-Extra: ml
Requires-Dist: scikit-learn<2,>=1.4; extra == "ml"
Requires-Dist: skops<1,>=0.10; extra == "ml"
Provides-Extra: pma
Requires-Dist: docxtpl<1,>=0.19; extra == "pma"
Requires-Dist: jinja2<4,>=3.1; extra == "pma"
Requires-Dist: fastapi<1,>=0.115; extra == "pma"
Provides-Extra: excel
Requires-Dist: openpyxl<4,>=3.1; extra == "excel"
Provides-Extra: dev
Requires-Dist: pytest<10,>=8; extra == "dev"
Requires-Dist: httpx<1,>=0.27; extra == "dev"
Requires-Dist: build<2,>=1.2; extra == "dev"
Provides-Extra: gcs
Requires-Dist: google-cloud-storage<4,>=2; extra == "gcs"

# PyMats

PyMats is a Python library for working with engineering materials. It brings material records, temperature- and thickness-dependent properties, design points, and material models into one place, ready to use in Python scripts and Jupyter notebooks.

Whether you are exploring material data, comparing candidates, or preparing inputs for a finite element model, PyMats aims to make that work easier to follow and repeat. The package includes ASME and EN material classes and supports custom material classes for your own workflows.

PyMats is under active development. This preview reflects the source reviewed on 1 November 2026; the notes below distinguish available functionality from areas still being developed.

## What you can do

- Construct local materials or load records through a configured backend.
- Evaluate material properties at a temperature and thickness.
- Work with design points and implemented allowable-stress rules.
- Choose between tabulated data and supported approximation models.
- Build linear-elastic, perfectly plastic, and linear-hardening stress–strain curves.
- Prepare material definitions for Ansys, Abaqus, and LS-DYNA.
- Explore material similarity and create Particular Material Appraisal (PMA) drafts.

The Python package is the heart of the project. A companion FastAPI service and Next.js application provide shared data access and a browser interface. User accounts and user management are outside the scope of PyMats.

## Getting started

Python 3.11 or newer is required. To work from this repository, install the core package:

```sh
python -m pip install pymats
```


You can create a material locally without connecting to a database:

```python
from pymats import Material

material = Material(
    Identifier="LOCAL",
    EO_overwritten=210_000.0,
)

print(material.EO)
```

This example supplies only an overridden Young’s modulus. For calculations that need additional properties, provide those inputs or load a complete material record.

### Loading a material

`MaterialFactory` loads records through your configured backend:

```python
from pymats import MaterialFactory

material = MaterialFactory.from_config({
    "Identifier": "SA-723-2-2",
    "Collection": "asme",
})

print(material.Name)
```

This example requires an accessible backend containing the requested record. Material data is supplied separately from the package.

### Working with design points

A design point groups the conditions used to evaluate a material:

```python
from pymats import DesignPoint, MaterialConstants

point = DesignPoint(
    EnvironmentTemperature=20.0,
    DesignTemperature=100.0,
    ThicknessConstraint=10.0,
    DesignCode=MaterialConstants.DesignCode.AD2000,
)

# Apply this to a material with the required property data.
material(point)

print(material.EO)   # Young’s modulus at design temperature
print(material.SYo)  # Yield strength at design temperature
print(material.STo)  # Tensile strength at design temperature
```

Choose conditions and a design code supported by your material data and the implemented calculation rules.

## Configuration and material data

PyMats supports three backend types: `api`, `mongodb`, and `atlas`. Use an API backend to access a running PyMats service, or a direct MongoDB connection for your own data environment.

Set `PYMATS_CONFIG` to the location of your YAML configuration:

```sh
export PYMATS_CONFIG=/absolute/path/to/config.yaml
```

A minimal API client configuration looks like this:

```yaml
pymats:
  api_url: http://localhost:8001
  database:
    type: api
  logging:
    file: null
```

The library resolves an explicit configuration file argument first, then `PYMATS_CONFIG`, then `~/.pymats/config.yaml`. If the default file is absent, importing the package uses API client defaults without creating a file. To create a minimal default file explicitly, call `pymats.config.create_default_config()`.

Explicit `DB_*` environment variables override database settings. Configuration can also be loaded from `gs://bucket/path` with the `gcs` extra and suitable credentials. File logging is optional.

Built-in material classes include `ASMEMaterial` and `ENMaterial`. You can register custom classes before loading their records. Configured Python plugins run when you explicitly call `pymats.register_custom_materials()`; unknown material class names raise an error.

## Material properties and interpolation

The `propertydata` setting selects `exact`, `ml`, or `nn` property sources. For tabulated data, choose an interpolation approach that fits your data and intended use:

| Setting | Approach |
| --- | --- |
| `standard` | Thickness bands with linear interpolation over temperature |
| `smooth` | Two-dimensional Clough–Tocher interpolation |
| `triangular` | Triangulated, piecewise-linear interpolation |

Property tables are checked for matching input/value sizes, finite values, and conflicting duplicate points. The two-dimensional methods need suitable point geometry.

Boundary behavior currently depends on the evaluation path. `MechanicalProperty` clamps temperatures below the table minimum and linearly extrapolates above the maximum using evaluations 10 °C apart. Thickness handling depends on the selected interpolator. The declared `extrapolation` field does not currently switch this behavior to a nearest-value policy.

Approximation models need the `ml` extra. Neural models also need a compatible `ai-edge-litert` or `tflite-runtime` installation. Model and scaler loading uses skops; legacy pickle/joblib fallback is not supported.

## Material models and solver exports

PyMats provides linear-elastic, perfectly plastic, and linear-hardening material models through `pymats.cae`. The package can build stress–strain curves and prepare solver material definitions for Ansys, Abaqus, and LS-DYNA.

Material modulus and strength inputs use MPa, and density uses kg/m³. Elongation at break is stored as a percentage and converted when building curves. Solver exports use m, kg, s, and Pa and validate required inputs, including a positive numeric `Mid`, positive density, and a valid Poisson ratio.

Linear hardening approximates the response using modulus, yield strength, tensile strength, and elongation at break. Unsupported allowable-stress rules raise errors. Material similarity scores help explore candidates, while engineering equivalence and solver suitability still need assessment for the intended application.

## PMA support

The package includes models and a builder for Particular Material Appraisal drafts, including general requirements, property definitions, and documentation metadata. Draft creation is available; document generation and export are still being developed. `PMABuilder.build()` currently raises `NotImplementedError`.

The companion service can serve existing PDF specifications through a manifest that identifies the material revision, file path, and checksum.

## Optional dependencies

Install extras as needed, for example `python -m pip install -e '.[ml,dev]'`.

| Extra | Purpose |
| --- | --- |
| `ml` | scikit-learn and skops model loading |
| `pma` | Document rendering dependencies; generation remains incomplete |
| `excel` | openpyxl support |
| `gcs` | Configuration loading from Google Cloud Storage |
| `dev` | Python tests and package builds |
| `api` | Companion FastAPI service dependencies |

## Companion applications

`pymats-api/` provides HTTP access to material search, properties, collections, solver exports, metadata, and PMA drafts. It requires a direct `mongodb` or `atlas` backend and an `api` section in the runtime configuration. Interactive route documentation is available at `/docs` when the service is running with its default FastAPI documentation settings.

`pymats-app/` provides a browser interface for exploring materials and models. Its development command serves port 3001. `NEXT_PUBLIC_API_URL` is a frontend build-time setting and must be reachable from the browser.

The repository also includes a Docker Compose stack. It publishes the browser application on port 3001 and maps host port 8001 to API container port 8000. It requires deployment-specific environment variables, runtime configuration, database storage, and the external `edge-network` network. Configuration is supplied through bind mounts and environment variables. The Python package version and Git revision metadata are separate values.

## Areas still being developed

A few parts of the current implementation need further work:

- API-backed collection loading: the Python loader and collection endpoint currently expect different response structures and property-data flags. Direct database loading remains a separate path.
- Property boundary handling: interpolation methods have different boundary behavior, and the `extrapolation` option is not yet connected to a consistent policy.
- Shared data definitions: some frontend enums and response interfaces differ from the Python models.
- PMA editing and export: draft models are available, while the complete editing and document workflow is unfinished.

These notes come from source inspection. They are intended to help you choose a suitable workflow; they do not replace running the tests against your checkout and environment.

## Future features

Possible directions for future development include:

- More consistent interpolation and explicit extrapolation policies.
- Broader material property coverage and additional allowable-stress rules.
- Easier import and validation of material datasets, with clear source references and units.
- More examples and notebooks for material evaluation, comparison, and solver preparation.
- A complete PMA draft and document export workflow.
- Shared schemas across the Python package and companion applications.
- Additional solver export validation and examples.

These are ideas for discussion rather than release commitments. User accounts and user management are outside the project scope and are not part of this roadmap.

## Contributing

Questions, bug reports, documentation improvements, and practical examples are welcome. If something behaves unexpectedly, a small reproducible example with the relevant configuration, property data, and package version makes it easier to investigate. Please leave credentials and private material data out of shared examples.

For a code contribution, keep changes focused and run the relevant tests. Examples that show how you use PyMats in an engineering or research workflow are welcome too.

## Development and checks

The repository keeps the reusable package in `pymats/`, Python tests in `tests/`, configuration files in `configs/`, and notebooks and development notes in `jupyter/`. The companion API and browser application have their own directories.

From the repository root, with the `dev` extra installed:

```sh
python -m pytest -q
python -m build
```

For frontend work, run `npm run typecheck` and `npm run build` from `pymats-app/` after installing its dependencies. After changing Compose configuration, run `docker compose config --quiet`.

The CI workflow defines Python regressions, a wheel installation smoke test, frontend checks, and container readiness checks. Their results depend on the checkout and environment; no tests or builds were run as part of preparing this documentation preview.
