py-materials 2.1.1__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {py_materials-2.1.1 → py_materials-3.2.0}/.gitignore +7 -0
- py_materials-3.2.0/PKG-INFO +621 -0
- py_materials-3.2.0/README.md +587 -0
- py_materials-3.2.0/docs/catalog/README.md +13 -0
- py_materials-3.2.0/docs/catalog/ceramics/README.md +19 -0
- py_materials-3.2.0/docs/catalog/electronics/README.md +17 -0
- py_materials-3.2.0/docs/catalog/gases/README.md +20 -0
- py_materials-3.2.0/docs/catalog/liquids/README.md +12 -0
- py_materials-3.2.0/docs/catalog/metals/README.md +25 -0
- py_materials-3.2.0/docs/catalog/plastics/README.md +30 -0
- py_materials-3.2.0/docs/catalog/scintillators/README.md +19 -0
- py_materials-3.2.0/mat-rs/data/README.md +23 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/pyproject.toml +9 -13
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/__init__.py +6 -8
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/core.py +81 -36
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/ceramics.toml +33 -9
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/electronics.toml +19 -11
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/gases.toml +14 -14
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/liquids.toml +6 -6
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/metals.toml +84 -24
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/plastics.toml +80 -17
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/data/scintillators.toml +12 -7
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/factories.py +20 -20
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/loader.py +66 -8
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/properties.py +3 -32
- py_materials-3.2.0/src/pymat/vis/__init__.py +178 -0
- py_materials-3.2.0/src/pymat/vis/_model.py +549 -0
- py_materials-3.2.0/src/pymat/vis/adapters.py +91 -0
- py_materials-3.2.0/tests/_visual_compare.py +133 -0
- py_materials-3.2.0/tests/baselines/README.md +59 -0
- py_materials-3.2.0/tests/material_preview.html +135 -0
- py_materials-3.2.0/tests/test_adapters.py +159 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_apply_to.py +3 -3
- py_materials-3.2.0/tests/test_catalog.py +78 -0
- py_materials-3.2.0/tests/test_e2e_vis.py +296 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_integration.py +4 -5
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_loader.py +11 -9
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_readme_examples.py +80 -8
- py_materials-3.2.0/tests/test_toml_integrity.py +235 -0
- py_materials-3.2.0/tests/test_uncertainties.py +112 -0
- py_materials-3.2.0/tests/test_vis.py +932 -0
- py_materials-3.2.0/tests/test_visual_compare.py +130 -0
- py_materials-3.2.0/tests/test_visual_regression.py +281 -0
- py_materials-3.2.0/tests/visual_render.html +96 -0
- py_materials-2.1.1/PKG-INFO +0 -469
- py_materials-2.1.1/README.md +0 -428
- {py_materials-2.1.1 → py_materials-3.2.0}/LICENSE +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/docs/decisions/README.md +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/elements.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/enrichers.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/registry.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/src/pymat/units.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/__init__.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/conftest.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_core.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_enrichers.py +0 -0
- {py_materials-2.1.1 → py_materials-3.2.0}/tests/test_properties.py +0 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-materials
|
|
3
|
+
Version: 3.2.0
|
|
4
|
+
Summary: Hierarchical material library for CAD applications with build123d integration
|
|
5
|
+
Project-URL: Homepage, https://github.com/MorePet/py-mat
|
|
6
|
+
Project-URL: Repository, https://github.com/MorePet/py-mat
|
|
7
|
+
Project-URL: Issues, https://github.com/MorePet/py-mat/issues
|
|
8
|
+
Author: Lars Gerchow
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: build123d,cad,engineering,materials,properties
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: mat-vis-client>=0.5.0
|
|
25
|
+
Requires-Dist: periodictable>=1.6.0
|
|
26
|
+
Requires-Dist: pint>=0.20
|
|
27
|
+
Requires-Dist: tomli>=1.0.0; python_version == '3.10'
|
|
28
|
+
Requires-Dist: uncertainties>=3.2
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build123d>=0.7.0; (python_version < '3.13') and extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# pymat
|
|
36
|
+
|
|
37
|
+
A hierarchical material library for CAD applications and Monte Carlo particle transport, with build123d integration.
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Hierarchical Materials**: Chain grades, tempers, treatments, and vendors
|
|
42
|
+
- **Property Inheritance**: Children inherit parent properties unless overridden
|
|
43
|
+
- **Lazy Loading**: Categories load on first access
|
|
44
|
+
- **TOML Data Storage**: Easy-to-edit material definitions
|
|
45
|
+
- **Formula Parsing + Molar Mass**: Computed from the chemical formula via `Material.molar_mass`, with fractional stoichiometry (`Lu1.8Y0.2SiO5`) and dopant suffix stripping (`LYSO:Ce`). Atomic weights mirror the Rust `rs-materials` crate for Python ↔ Rust parity.
|
|
46
|
+
- **build123d Integration**: Apply materials to shapes with automatic mass calculation
|
|
47
|
+
- **PBR Rendering via `material.vis`**: Scalars (roughness, metallic, base_color) and lazy-fetched textures from [mat-vis][mat-vis]
|
|
48
|
+
- **periodictable Integration**: Auto-fill composition from chemical formulas for compounds; auto-fill density for pure elements
|
|
49
|
+
- **Factory Functions**: Temperature/pressure-dependent materials (water, air, saline)
|
|
50
|
+
- **Separation of Concerns**: Optical properties (physics) separate from `vis` (visualization)
|
|
51
|
+
- **Python 3.10 – 3.13 supported**, core library depends only on `pint`
|
|
52
|
+
|
|
53
|
+
[mat-vis]: https://github.com/MorePET/mat-vis
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# From PyPI (recommended)
|
|
59
|
+
pip install py-materials
|
|
60
|
+
# or: uv add py-materials
|
|
61
|
+
|
|
62
|
+
# From the main branch (development)
|
|
63
|
+
pip install git+https://github.com/MorePET/mat.git@main
|
|
64
|
+
|
|
65
|
+
# With optional extras
|
|
66
|
+
pip install "py-materials[periodictable]" # auto-fill from chemical formulas
|
|
67
|
+
pip install "py-materials[build123d]" # build123d Shape integration (Python <= 3.12)
|
|
68
|
+
pip install "py-materials[all]" # everything above
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
## Creating Materials
|
|
74
|
+
|
|
75
|
+
Create materials with convenient parameters:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from pymat import Material
|
|
79
|
+
|
|
80
|
+
# Using convenience parameters
|
|
81
|
+
steel = Material(name="Steel", density=7.85)
|
|
82
|
+
assert steel.density == 7.85
|
|
83
|
+
|
|
84
|
+
# With visualization color
|
|
85
|
+
aluminum = Material(name="Aluminum", density=2.7, color=(0.88, 0.88, 0.88))
|
|
86
|
+
assert aluminum.vis.base_color[:3] == (0.88, 0.88, 0.88)
|
|
87
|
+
|
|
88
|
+
# With formula
|
|
89
|
+
lyso = Material(name="LYSO", formula="Lu1.8Y0.2SiO5", density=7.1)
|
|
90
|
+
assert lyso.formula == "Lu1.8Y0.2SiO5"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Using Property Groups
|
|
94
|
+
|
|
95
|
+
Define multiple properties at once using property group dictionaries:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from pymat import Material
|
|
99
|
+
|
|
100
|
+
# Define steel with multiple property groups
|
|
101
|
+
steel = Material(
|
|
102
|
+
name="Stainless Steel 304",
|
|
103
|
+
mechanical={"density": 8.0, "youngs_modulus": 193, "yield_strength": 170},
|
|
104
|
+
thermal={"melting_point": 1450, "thermal_conductivity": 15.1},
|
|
105
|
+
vis={"base_color": (0.75, 0.75, 0.77, 1.0), "metallic": 1.0},
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
assert steel.properties.mechanical.density == 8.0
|
|
109
|
+
assert steel.properties.mechanical.youngs_modulus == 193
|
|
110
|
+
assert steel.properties.thermal.melting_point == 1450
|
|
111
|
+
assert steel.vis.metallic == 1.0
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Applying Materials to Shapes
|
|
115
|
+
|
|
116
|
+
Apply materials to build123d shapes for visualization and mass calculation:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from build123d import Box
|
|
120
|
+
|
|
121
|
+
from pymat import Material
|
|
122
|
+
|
|
123
|
+
# Create material
|
|
124
|
+
steel = Material(name="Steel", density=7.85, color=(0.7, 0.7, 0.7))
|
|
125
|
+
|
|
126
|
+
# Create shape and apply material
|
|
127
|
+
box = Box(10, 10, 10)
|
|
128
|
+
steel.apply_to(box)
|
|
129
|
+
|
|
130
|
+
assert box.material.name == "Steel"
|
|
131
|
+
assert box.mass > 0
|
|
132
|
+
assert box.color is not None
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Computing Molar Mass
|
|
136
|
+
|
|
137
|
+
`Material.molar_mass` is a computed property that parses the
|
|
138
|
+
chemical formula and looks up each element's atomic weight.
|
|
139
|
+
It supports fractional stoichiometry and strips dopant
|
|
140
|
+
notation like `LYSO:Ce` so doped-crystal aliases work
|
|
141
|
+
unchanged.
|
|
142
|
+
|
|
143
|
+
Nothing is stored — it recomputes on each access. That's
|
|
144
|
+
intentional: molar mass is definitionally derived from
|
|
145
|
+
`formula` and should never drift. Missing or unknown-element
|
|
146
|
+
formulas return `None`. See
|
|
147
|
+
`docs/decisions/0001-derived-chemistry-properties-live-on-material.md`.
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from pymat import Material
|
|
151
|
+
|
|
152
|
+
# Pure element
|
|
153
|
+
iron = Material(name="Iron", formula="Fe")
|
|
154
|
+
assert iron.molar_mass == 55.85
|
|
155
|
+
|
|
156
|
+
# Simple compound
|
|
157
|
+
alumina = Material(name="Alumina", formula="Al2O3")
|
|
158
|
+
assert abs(alumina.molar_mass - 101.96) < 0.01
|
|
159
|
+
|
|
160
|
+
# Fractional stoichiometry (a PET-scanner scintillator)
|
|
161
|
+
lyso = Material(name="LYSO", formula="Lu1.8Y0.2SiO5")
|
|
162
|
+
assert abs(lyso.molar_mass - 440.87) < 0.1
|
|
163
|
+
|
|
164
|
+
# Dopant suffix is stripped
|
|
165
|
+
lyso_ce = Material(name="LYSO:Ce", formula="Lu1.8Y0.2SiO5:Ce")
|
|
166
|
+
assert lyso_ce.molar_mass == lyso.molar_mass
|
|
167
|
+
|
|
168
|
+
# Unit-aware companion accessor (Pint Quantity)
|
|
169
|
+
qty = iron.molar_mass_qty
|
|
170
|
+
assert qty.to("kg/mol").magnitude == pytest.approx(0.05585, abs=1e-4)
|
|
171
|
+
|
|
172
|
+
# Gracefully returns None when no formula is set
|
|
173
|
+
unknown = Material(name="Unknown Alloy")
|
|
174
|
+
assert unknown.molar_mass is None
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Low-level: `pymat.elements`
|
|
178
|
+
|
|
179
|
+
For callers that don't need a full `Material` object —
|
|
180
|
+
e.g. quick stoichiometry calculations inside a Monte Carlo
|
|
181
|
+
transport loop — the low-level `pymat.elements` module
|
|
182
|
+
exposes the same machinery directly.
|
|
183
|
+
|
|
184
|
+
The `ATOMIC_WEIGHT` table is a line-for-line mirror of the
|
|
185
|
+
Rust `rs-materials` crate, so Python and Rust Monte Carlo
|
|
186
|
+
engines get identical molar masses byte-for-byte.
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from pymat.elements import (
|
|
190
|
+
ATOMIC_WEIGHT,
|
|
191
|
+
compute_molar_mass,
|
|
192
|
+
parse_formula,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# Atomic weight lookup
|
|
196
|
+
assert ATOMIC_WEIGHT["Fe"] == 55.85
|
|
197
|
+
assert ATOMIC_WEIGHT["Lu"] == 175.0
|
|
198
|
+
|
|
199
|
+
# Formula parser: fractional stoichiometry + repeat handling
|
|
200
|
+
counts = parse_formula("Lu1.8Y0.2SiO5")
|
|
201
|
+
assert counts == {"Lu": 1.8, "Y": 0.2, "Si": 1.0, "O": 5.0}
|
|
202
|
+
|
|
203
|
+
# Molar mass directly from a formula string
|
|
204
|
+
assert abs(compute_molar_mass("Al2O3") - 101.96) < 0.01
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Chainable Material Hierarchy
|
|
208
|
+
|
|
209
|
+
Build hierarchies with grades, tempers, and treatments:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from pymat import Material
|
|
213
|
+
|
|
214
|
+
# Create base stainless steel
|
|
215
|
+
stainless = Material(name="Stainless Steel", density=8.0, thermal={"melting_point": 1450})
|
|
216
|
+
|
|
217
|
+
# Add grade
|
|
218
|
+
s304 = stainless.grade_("304", name="SS 304", mechanical={"yield_strength": 170})
|
|
219
|
+
assert s304.density == 8.0 # Inherited
|
|
220
|
+
assert s304.properties.mechanical.yield_strength == 170
|
|
221
|
+
|
|
222
|
+
# Add treatment
|
|
223
|
+
passivated = s304.treatment_("passivated", name="SS 304 Passivated")
|
|
224
|
+
assert (
|
|
225
|
+
passivated.path == "stainless_steel.304.passivated"
|
|
226
|
+
) # name -> lowercase with underscores
|
|
227
|
+
assert passivated.density == 8.0 # Inherited through chain
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Direct Material Access
|
|
231
|
+
|
|
232
|
+
Load materials and access them directly from the library:
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from pymat import aluminum, lyso, stainless
|
|
236
|
+
|
|
237
|
+
# Direct access to materials
|
|
238
|
+
s316L = stainless.s316L
|
|
239
|
+
assert s316L.grade == "316L"
|
|
240
|
+
|
|
241
|
+
al6061 = aluminum.a6061
|
|
242
|
+
assert al6061.density == 2.7 # Inherited from aluminum
|
|
243
|
+
|
|
244
|
+
lyso_crystal = lyso
|
|
245
|
+
assert "LYSO" in lyso_crystal.name
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Physics Properties vs Visualization
|
|
249
|
+
|
|
250
|
+
Understand the difference between measured optical properties (physics)
|
|
251
|
+
and rendering properties (visualization):
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from pymat import Material
|
|
255
|
+
|
|
256
|
+
# Create transparent material
|
|
257
|
+
glass = Material(
|
|
258
|
+
name="Optical Glass",
|
|
259
|
+
color=(0.9, 0.9, 0.9, 0.8), # Visual: 80% opaque white
|
|
260
|
+
optical={"transparency": 95, "refractive_index": 1.517}, # Physics: 95% transmission
|
|
261
|
+
vis={"transmission": 0.8}, # Rendering: how transparent it looks
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
# Physics properties (measured)
|
|
265
|
+
assert glass.properties.optical.transparency == 95
|
|
266
|
+
assert glass.properties.optical.refractive_index == 1.517
|
|
267
|
+
|
|
268
|
+
# Visualization properties (rendering)
|
|
269
|
+
assert glass.vis.base_color[3] == 0.8 # Alpha
|
|
270
|
+
assert glass.vis.transmission == 0.8
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Scintillator-Specific Properties
|
|
274
|
+
|
|
275
|
+
Define detector crystals with optical physics properties:
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
from pymat import Material
|
|
279
|
+
|
|
280
|
+
lyso_crystal = Material(
|
|
281
|
+
name="LYSO:Ce Crystal",
|
|
282
|
+
density=7.1,
|
|
283
|
+
optical={
|
|
284
|
+
"refractive_index": 1.82,
|
|
285
|
+
"transparency": 92,
|
|
286
|
+
"light_yield": 32000, # photons/MeV
|
|
287
|
+
"decay_time": 41, # ns
|
|
288
|
+
"emission_peak": 420, # nm
|
|
289
|
+
},
|
|
290
|
+
vis={"base_color": (0.0, 1.0, 1.0, 0.85), "transmission": 0.85},
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
assert lyso_crystal.properties.optical.light_yield == 32000
|
|
294
|
+
assert lyso_crystal.properties.optical.decay_time == 41
|
|
295
|
+
assert lyso_crystal.vis.transmission == 0.85
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Temperature-Dependent Materials
|
|
299
|
+
|
|
300
|
+
Use factory functions for materials with properties that depend on external parameters:
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from pymat.factories import water
|
|
304
|
+
|
|
305
|
+
# Water at different temperatures
|
|
306
|
+
cold_water = water(4) # Max density
|
|
307
|
+
room_water = water(20) # Room temperature
|
|
308
|
+
hot_water = water(80) # Heated
|
|
309
|
+
|
|
310
|
+
assert cold_water.density > room_water.density
|
|
311
|
+
assert room_water.density > hot_water.density
|
|
312
|
+
|
|
313
|
+
# Verify realistic values
|
|
314
|
+
assert 0.99 < cold_water.density < 1.01
|
|
315
|
+
assert 0.95 < hot_water.density < 0.98
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Air at Different Conditions
|
|
319
|
+
|
|
320
|
+
Create air material at specific temperature and pressure:
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
from pymat.factories import air
|
|
324
|
+
|
|
325
|
+
sea_level = air(15, 1.0) # 15°C, 1 atm
|
|
326
|
+
high_altitude = air(15, 0.5) # 15°C, 0.5 atm (5500m)
|
|
327
|
+
|
|
328
|
+
assert sea_level.density > high_altitude.density
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Saline Solutions
|
|
332
|
+
|
|
333
|
+
Create solutions with specific concentration and temperature:
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from pymat.factories import saline, water
|
|
337
|
+
|
|
338
|
+
# Physiological saline at body temperature
|
|
339
|
+
phantom = saline(0.9, temperature_c=37)
|
|
340
|
+
# Saline is slightly denser than pure water at same temperature
|
|
341
|
+
pure_water_37 = water(37)
|
|
342
|
+
assert phantom.density > pure_water_37.density
|
|
343
|
+
|
|
344
|
+
# Seawater (3.5% NaCl) at 20°C
|
|
345
|
+
seawater = saline(3.5, temperature_c=20)
|
|
346
|
+
# Higher concentration = higher density
|
|
347
|
+
assert seawater.density > phantom.density
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Loading Metal Materials
|
|
351
|
+
|
|
352
|
+
Access various metal materials from the metals category:
|
|
353
|
+
|
|
354
|
+
```python
|
|
355
|
+
from pymat import aluminum, copper, stainless
|
|
356
|
+
|
|
357
|
+
# Stainless steel variants
|
|
358
|
+
s304 = stainless.s304
|
|
359
|
+
s316L = stainless.s316L
|
|
360
|
+
assert s304.density == s316L.density # Same base density
|
|
361
|
+
|
|
362
|
+
# Aluminum alloys
|
|
363
|
+
al6061 = aluminum.a6061
|
|
364
|
+
_ = aluminum.a7075
|
|
365
|
+
assert al6061.density == 2.7
|
|
366
|
+
|
|
367
|
+
# Copper
|
|
368
|
+
copper_material = copper
|
|
369
|
+
assert copper_material.density == 8.96
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Plastic Materials
|
|
373
|
+
|
|
374
|
+
Access plastic materials for 3D printing and engineering:
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
from pymat import pc, peek, pla, pmma
|
|
378
|
+
|
|
379
|
+
# Engineering plastics
|
|
380
|
+
assert peek.properties.manufacturing.print_nozzle_temp == 360
|
|
381
|
+
|
|
382
|
+
# 3D printing plastics
|
|
383
|
+
assert pla.properties.manufacturing.printable_fdm is True
|
|
384
|
+
|
|
385
|
+
# Transparent plastics
|
|
386
|
+
assert pmma.properties.optical.transparency == 92
|
|
387
|
+
assert pc.properties.optical.transparency == 89
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Scintillator Crystals
|
|
391
|
+
|
|
392
|
+
Access scintillator materials for radiation detectors:
|
|
393
|
+
|
|
394
|
+
```python
|
|
395
|
+
from pymat import bgo, lyso, nai
|
|
396
|
+
|
|
397
|
+
# LYSO crystal
|
|
398
|
+
assert lyso.properties.optical.light_yield == 32000
|
|
399
|
+
assert lyso.properties.optical.refractive_index == 1.82
|
|
400
|
+
|
|
401
|
+
# BGO crystal
|
|
402
|
+
assert bgo.properties.optical.light_yield == 8500
|
|
403
|
+
|
|
404
|
+
# NaI crystal
|
|
405
|
+
assert nai.properties.optical.light_yield == 38000
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Gas Materials
|
|
409
|
+
|
|
410
|
+
Access gases for simulation and detector design:
|
|
411
|
+
|
|
412
|
+
```python
|
|
413
|
+
from pymat import air, argon, helium, nitrogen, xenon
|
|
414
|
+
|
|
415
|
+
# Common gases at STP
|
|
416
|
+
assert 0.0012 < air.density < 0.0013 # g/cm³
|
|
417
|
+
assert nitrogen.density > helium.density # Helium is lightest
|
|
418
|
+
assert xenon.density > argon.density # Heavier noble gases
|
|
419
|
+
|
|
420
|
+
# Detector gases
|
|
421
|
+
assert argon.properties.compliance.radiation_resistant is True
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
## Property Inheritance
|
|
425
|
+
|
|
426
|
+
Child materials inherit properties from parents unless overridden:
|
|
427
|
+
|
|
428
|
+
```python
|
|
429
|
+
from pymat import Material
|
|
430
|
+
|
|
431
|
+
# Create material hierarchy
|
|
432
|
+
root = Material(
|
|
433
|
+
name="Base", density=7.8, thermal={"melting_point": 1500, "thermal_conductivity": 50}
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
grade1 = root.grade_("G1", mechanical={"yield_strength": 400})
|
|
437
|
+
assert grade1.density == 7.8 # Inherited
|
|
438
|
+
assert grade1.properties.mechanical.yield_strength == 400 # New property
|
|
439
|
+
assert grade1.properties.thermal.melting_point == 1500 # Inherited
|
|
440
|
+
|
|
441
|
+
# Override inherited property
|
|
442
|
+
grade2 = root.grade_("G2", thermal={"melting_point": 1600})
|
|
443
|
+
assert grade2.properties.thermal.melting_point == 1600 # Overridden
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## Automatic Mass Calculation
|
|
447
|
+
|
|
448
|
+
Materials with density automatically calculate shape mass:
|
|
449
|
+
|
|
450
|
+
```python
|
|
451
|
+
from build123d import Box
|
|
452
|
+
|
|
453
|
+
from pymat import aluminum, stainless
|
|
454
|
+
|
|
455
|
+
# 10x10x10 mm³ box = 1000 mm³ = 1 cm³
|
|
456
|
+
steel_box = Box(10, 10, 10)
|
|
457
|
+
stainless.apply_to(steel_box)
|
|
458
|
+
|
|
459
|
+
# Density = 8.0 g/cm³, Volume = 1 cm³ → Mass = 8.0 g
|
|
460
|
+
assert 7.9 < steel_box.mass < 8.1
|
|
461
|
+
|
|
462
|
+
# Aluminum box
|
|
463
|
+
al_box = Box(10, 10, 10)
|
|
464
|
+
aluminum.apply_to(al_box)
|
|
465
|
+
|
|
466
|
+
# Density = 2.7 g/cm³ → Mass = 2.7 g
|
|
467
|
+
assert 2.6 < al_box.mass < 2.8
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
## Material Visualization
|
|
471
|
+
|
|
472
|
+
Materials render with appropriate colors for visualization:
|
|
473
|
+
|
|
474
|
+
```python
|
|
475
|
+
from build123d import Box
|
|
476
|
+
|
|
477
|
+
from pymat import aluminum, lyso, stainless
|
|
478
|
+
|
|
479
|
+
# Create shapes
|
|
480
|
+
steel_part = Box(10, 10, 10)
|
|
481
|
+
al_part = Box(10, 10, 10)
|
|
482
|
+
crystal = Box(10, 10, 10)
|
|
483
|
+
|
|
484
|
+
# Apply materials
|
|
485
|
+
stainless.apply_to(steel_part)
|
|
486
|
+
aluminum.apply_to(al_part)
|
|
487
|
+
lyso.apply_to(crystal)
|
|
488
|
+
|
|
489
|
+
# Verify colors are set
|
|
490
|
+
assert steel_part.color is not None
|
|
491
|
+
assert al_part.color is not None
|
|
492
|
+
assert crystal.color is not None
|
|
493
|
+
|
|
494
|
+
# Colors should differ
|
|
495
|
+
assert steel_part.color != al_part.color
|
|
496
|
+
assert crystal.color != steel_part.color
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
## Material Categories
|
|
500
|
+
|
|
501
|
+
- **Metals**: Stainless steel, aluminum, copper, tungsten, lead, titanium, brass
|
|
502
|
+
- **Scintillators**: LYSO, BGO, NaI, CsI, LaBr3, PWO, plastic scintillators
|
|
503
|
+
- **Plastics**: PEEK, Delrin, Ultem, PTFE, ESR, Nylon, PLA, ABS, PETG, TPU, PMMA, PE, PC
|
|
504
|
+
- **Ceramics**: Alumina, Macor, Zirconia, Glass (borosilicate, fused silica, BK7)
|
|
505
|
+
- **Electronics**: FR4, Rogers, Kapton, copper PCB, solder, ferrite
|
|
506
|
+
- **Liquids**: Water, Heavy Water, Mineral Oil, Glycerol, Silicone Oil
|
|
507
|
+
- **Gases**: Air, Nitrogen, Oxygen, Argon, CO₂, Helium, Hydrogen, Neon, Xenon, Methane, Vacuum
|
|
508
|
+
|
|
509
|
+
## Property Groups
|
|
510
|
+
|
|
511
|
+
Each material can have properties organized in these domains:
|
|
512
|
+
|
|
513
|
+
- **Mechanical**: density, Young's modulus, yield strength, hardness
|
|
514
|
+
- **Thermal**: melting point, thermal conductivity, expansion coefficient
|
|
515
|
+
- **Electrical**: resistivity, conductivity, dielectric constant
|
|
516
|
+
- **Optical**: refractive index, transparency, light yield (PHYSICS - measured values)
|
|
517
|
+
- **Vis** (on `material.vis`): base_color, metallic, roughness, ior, transmission, textures, finishes — visual/rendering layer, fetches PBR textures from mat-vis on demand
|
|
518
|
+
- **Manufacturing**: machinability, printability, weldability
|
|
519
|
+
- **Compliance**: RoHS, REACH, food-safe, biocompatible
|
|
520
|
+
- **Sourcing**: cost, availability, suppliers
|
|
521
|
+
|
|
522
|
+
## Advanced Usage
|
|
523
|
+
|
|
524
|
+
### Custom Materials
|
|
525
|
+
|
|
526
|
+
Create materials using property group dictionaries:
|
|
527
|
+
|
|
528
|
+
```python
|
|
529
|
+
from pymat import Material
|
|
530
|
+
|
|
531
|
+
my_material = Material(
|
|
532
|
+
name="Custom Alloy",
|
|
533
|
+
mechanical={
|
|
534
|
+
"density": 8.1,
|
|
535
|
+
"youngs_modulus": 200,
|
|
536
|
+
"yield_strength": 450
|
|
537
|
+
},
|
|
538
|
+
vis={
|
|
539
|
+
"base_color": (0.7, 0.7, 0.75, 1.0),
|
|
540
|
+
"metallic": 1.0,
|
|
541
|
+
"roughness": 0.4
|
|
542
|
+
}
|
|
543
|
+
)
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Loading from TOML
|
|
547
|
+
|
|
548
|
+
```python
|
|
549
|
+
from pymat import load_toml
|
|
550
|
+
|
|
551
|
+
materials = load_toml("my_materials.toml")
|
|
552
|
+
my_material = materials["my_material"]
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
### Enrichment from Chemical Formulas
|
|
556
|
+
|
|
557
|
+
`enrich_from_periodictable` reads the material's `formula`, populates
|
|
558
|
+
the `composition` dict (element → atom count), and sets the density
|
|
559
|
+
**only for pure elements** — compound density is not derivable from
|
|
560
|
+
`periodictable`'s dataset and requires a crystallographic source like
|
|
561
|
+
Materials Project. Molar mass is always available regardless, via the
|
|
562
|
+
computed `Material.molar_mass` property (see the Quick Start).
|
|
563
|
+
|
|
564
|
+
```python
|
|
565
|
+
from pymat import Material, enrich_from_periodictable
|
|
566
|
+
|
|
567
|
+
# Pure element — density is set
|
|
568
|
+
iron = Material(name="Iron", formula="Fe")
|
|
569
|
+
enrich_from_periodictable(iron)
|
|
570
|
+
assert iron.density == 7.874 # set from periodictable
|
|
571
|
+
assert iron.molar_mass == 55.85 # computed from formula
|
|
572
|
+
|
|
573
|
+
# Compound — composition is set, density is not
|
|
574
|
+
alumina = Material(name="Alumina", formula="Al2O3")
|
|
575
|
+
enrich_from_periodictable(alumina)
|
|
576
|
+
assert alumina.composition == {"Al": 2, "O": 3}
|
|
577
|
+
assert alumina.molar_mass == 101.96 # computed from formula
|
|
578
|
+
assert alumina.density is None # use enrich_from_matproj for compounds
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
## Optical vs Visual Properties
|
|
582
|
+
|
|
583
|
+
**Important**: Understand the distinction between physics and visualization:
|
|
584
|
+
|
|
585
|
+
- **Optical Properties** (`properties.optical.*`): Measured/calculated physical values
|
|
586
|
+
- `transparency`: % light transmission (measured)
|
|
587
|
+
- `refractive_index`: optical property (measured)
|
|
588
|
+
- `light_yield`: scintillator brightness (measured)
|
|
589
|
+
|
|
590
|
+
- **Visual Properties** (`material.vis.*`): Rendering/visualization parameters
|
|
591
|
+
- `base_color`: RGBA values (0-1) for display
|
|
592
|
+
- `transmission`: how transparent it LOOKS in renders
|
|
593
|
+
- `metallic`: surface finish appearance
|
|
594
|
+
- `roughness`: surface roughness appearance
|
|
595
|
+
- `source` + `material_id` + `tier`: mat-vis appearance identity (since 3.1; the three fields match mat-vis-client's positional-arg signature — see [ADR-0002](docs/decisions/0002-vis-owns-identity-client-exposed.md))
|
|
596
|
+
- `textures`: PBR texture maps (lazy-fetched from mat-vis once `source` + `material_id` are set)
|
|
597
|
+
- `finishes`: named alternate looks (e.g. `brushed` / `polished` / `oxidized`) — each entry is an inline `{source, id}` table
|
|
598
|
+
- `mtlx` (property): MaterialX document accessor (`.xml`, `.export(path)`, `.original`)
|
|
599
|
+
- `client` (property): escape hatch to the shared `MatVisClient` singleton — for any operation not material-keyed
|
|
600
|
+
|
|
601
|
+
These can differ intentionally! A material might be physically transparent (95% optical transmission) but rendered opaque (0% vis.transmission) for CAD clarity.
|
|
602
|
+
|
|
603
|
+
## License
|
|
604
|
+
|
|
605
|
+
MIT
|
|
606
|
+
|
|
607
|
+
## Design Decisions (ADRs)
|
|
608
|
+
|
|
609
|
+
Non-trivial architectural decisions live under `docs/decisions/` as
|
|
610
|
+
lightweight ADRs. They explain why the code is shaped the way it is
|
|
611
|
+
and the conditions under which the decision should be revisited.
|
|
612
|
+
|
|
613
|
+
- [ADR-0001 — Derived chemistry properties live on `Material`](docs/decisions/0001-derived-chemistry-properties-live-on-material.md)
|
|
614
|
+
(why `molar_mass` is a computed `@property`, not a stored field)
|
|
615
|
+
|
|
616
|
+
## Links
|
|
617
|
+
|
|
618
|
+
- **GitHub**: https://github.com/MorePET/mat
|
|
619
|
+
- **Issues**: https://github.com/MorePET/mat/issues
|
|
620
|
+
- **PyPI**: https://pypi.org/project/py-materials/
|
|
621
|
+
- **Rust crate** (`rs-materials`): https://crates.io/crates/rs-materials
|