py-materials 2.0.5__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.
@@ -0,0 +1,142 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+ cover/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+ local_settings.py
59
+ db.sqlite3
60
+ db.sqlite3-journal
61
+
62
+ # Flask stuff:
63
+ instance/
64
+ .webassets-cache
65
+
66
+ # Scrapy stuff:
67
+ .scrapy
68
+
69
+ # Sphinx documentation
70
+ docs/_build/
71
+
72
+ # PyBuilder
73
+ .pybuilder/
74
+ target/
75
+
76
+ # Jupyter Notebook
77
+ .ipynb_checkpoints
78
+
79
+ # IPython
80
+ profile_default/
81
+ ipython_config.py
82
+
83
+ # pyenv
84
+ .python-version
85
+
86
+ # pipenv
87
+ Pipfile.lock
88
+
89
+ # PEP 582
90
+ __pypackages__/
91
+
92
+ # Celery stuff
93
+ celerybeat-schedule
94
+ celerybeat.pid
95
+
96
+ # SageMath parsed files
97
+ *.sage.py
98
+
99
+ # Environments
100
+ .env
101
+ .venv
102
+ env/
103
+ venv/
104
+ ENV/
105
+ env.bak/
106
+ venv.bak/
107
+
108
+ # Spyder project settings
109
+ .spyderproject
110
+ .spyproject
111
+
112
+ # Rope project settings
113
+ .ropeproject
114
+
115
+ # mkdocs documentation
116
+ /site
117
+
118
+ # mypy
119
+ .mypy_cache/
120
+ .dmypy.json
121
+ dmypy.json
122
+
123
+ # Pyre type checker
124
+ .pyre/
125
+
126
+ # pytype static type analyzer
127
+ .pytype/
128
+
129
+ # Cython debug symbols
130
+ cython_debug/
131
+
132
+ # IDEs
133
+ .idea/
134
+ .vscode/
135
+ *.swp
136
+ *.swo
137
+ *~
138
+
139
+ # OS
140
+ .DS_Store
141
+ Thumbs.db
142
+
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lars Gerchow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,443 @@
1
+ Metadata-Version: 2.4
2
+ Name: py-materials
3
+ Version: 2.0.5
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.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Physics
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: pint>=0.20
23
+ Provides-Extra: all
24
+ Requires-Dist: build123d>=0.7.0; extra == 'all'
25
+ Requires-Dist: periodictable>=1.6.0; extra == 'all'
26
+ Requires-Dist: pymatgen>=2024.0.0; extra == 'all'
27
+ Provides-Extra: build123d
28
+ Requires-Dist: build123d>=0.7.0; extra == 'build123d'
29
+ Provides-Extra: dev
30
+ Requires-Dist: build123d>=0.7.0; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
32
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
33
+ Provides-Extra: matproj
34
+ Requires-Dist: pymatgen>=2024.0.0; extra == 'matproj'
35
+ Provides-Extra: periodictable
36
+ Requires-Dist: periodictable>=1.6.0; extra == 'periodictable'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # pymat
40
+
41
+ A hierarchical material library for CAD applications with build123d integration.
42
+
43
+ ## Features
44
+
45
+ - **Hierarchical Materials**: Chain grades, tempers, treatments, and vendors
46
+ - **Property Inheritance**: Children inherit parent properties unless overridden
47
+ - **Lazy Loading**: Categories load on first access
48
+ - **TOML Data Storage**: Easy-to-edit material definitions
49
+ - **build123d Integration**: Apply materials to shapes with automatic mass calculation
50
+ - **PBR Rendering**: Physically-based rendering properties for visualization
51
+ - **periodictable Integration**: Auto-fill density from chemical formulas
52
+ - **Factory Functions**: Temperature/pressure-dependent materials (water, air, saline)
53
+ - **Separation of Concerns**: Optical properties (physics) separate from PBR (visualization)
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ # With uv (recommended)
59
+ uv add git+https://github.com/MorePET/py-mat.git@latest
60
+
61
+ # Or specify version
62
+ uv add git+https://github.com/MorePET/py-mat.git@v1.0.0
63
+ ```
64
+
65
+ ## Quick Start
66
+
67
+ ## Creating Materials
68
+
69
+ Create materials with convenient parameters:
70
+
71
+ ```python
72
+ from pymat import Material
73
+
74
+ # Using convenience parameters
75
+ steel = Material(name="Steel", density=7.85)
76
+ # With visualization color
77
+ aluminum = Material(name="Aluminum", density=2.7, color=(0.88, 0.88, 0.88))
78
+ # With formula
79
+ lyso = Material(name="LYSO", formula="Lu1.8Y0.2SiO5", density=7.1)
80
+ assert lyso.formula == "Lu1.8Y0.2SiO5"
81
+ ```
82
+
83
+ ## Using Property Groups
84
+
85
+ Define multiple properties at once using property group dictionaries:
86
+
87
+ ```python
88
+ from pymat import Material
89
+
90
+ # Define steel with multiple property groups
91
+ steel = Material(
92
+ name="Stainless Steel 304",
93
+ mechanical={"density": 8.0, "youngs_modulus": 193, "yield_strength": 170},
94
+ thermal={"melting_point": 1450, "thermal_conductivity": 15.1},
95
+ pbr={"base_color": (0.75, 0.75, 0.77, 1.0), "metallic": 1.0}
96
+ ) assert steel.properties.pbr.metallic == 1.0
97
+ ```
98
+
99
+ ## Applying Materials to Shapes
100
+
101
+ Apply materials to build123d shapes for visualization and mass calculation:
102
+
103
+ ```python
104
+ from build123d import Box
105
+ from pymat import Material
106
+
107
+ # Create material
108
+ steel = Material(name="Steel", density=7.85, color=(0.7, 0.7, 0.7))
109
+
110
+ # Create shape and apply material
111
+ box = Box(10, 10, 10)
112
+ steel.apply_to(box) assert box.color is not None
113
+ ```
114
+
115
+ ## Chainable Material Hierarchy
116
+
117
+ Build hierarchies with grades, tempers, and treatments:
118
+
119
+ ```python
120
+ from pymat import Material
121
+
122
+ # Create base stainless steel
123
+ stainless = Material(
124
+ name="Stainless Steel",
125
+ density=8.0,
126
+ thermal={"melting_point": 1450}
127
+ )
128
+
129
+ # Add grade
130
+ s304 = stainless.grade_("304", name="SS 304", mechanical={"yield_strength": 170})
131
+ # Add treatment
132
+ passivated = s304.treatment_("passivated", name="SS 304 Passivated") assert passivated.density == 8.0 # Inherited through chain
133
+ ```
134
+
135
+ ## Direct Material Access
136
+
137
+ Load materials and access them directly from the library:
138
+
139
+ ```python
140
+ from pymat import stainless, aluminum, lyso
141
+
142
+ # Direct access to materials
143
+ s316L = stainless.s316L
144
+ al6061 = aluminum.a6061
145
+ lyso_crystal = lyso
146
+ assert "LYSO" in lyso_crystal.name
147
+ ```
148
+
149
+ ## Physics Properties vs Visualization
150
+
151
+ Understand the difference between measured optical properties (physics)
152
+ and rendering properties (visualization):
153
+
154
+ ```python
155
+ from pymat import Material
156
+
157
+ # Create transparent material
158
+ glass = Material(
159
+ name="Optical Glass",
160
+ color=(0.9, 0.9, 0.9, 0.8), # Visual: 80% opaque white
161
+ optical={"transparency": 95, "refractive_index": 1.517}, # Physics: 95% transmission
162
+ pbr={"transmission": 0.8} # Rendering: how transparent it looks
163
+ )
164
+
165
+ # Physics properties (measured)
166
+ # Visualization properties (rendering) assert glass.properties.pbr.transmission == 0.8
167
+ ```
168
+
169
+ ## Scintillator-Specific Properties
170
+
171
+ Define detector crystals with optical physics properties:
172
+
173
+ ```python
174
+ from pymat import Material
175
+
176
+ lyso_crystal = Material(
177
+ name="LYSO:Ce Crystal",
178
+ density=7.1,
179
+ optical={
180
+ "refractive_index": 1.82,
181
+ "transparency": 92,
182
+ "light_yield": 32000, # photons/MeV
183
+ "decay_time": 41, # ns
184
+ "emission_peak": 420, # nm
185
+ },
186
+ pbr={"base_color": (0.0, 1.0, 1.0, 0.85), "transmission": 0.85}
187
+ ) assert lyso_crystal.properties.pbr.transmission == 0.85
188
+ ```
189
+
190
+ ## Temperature-Dependent Materials
191
+
192
+ Use factory functions for materials with properties that depend on external parameters:
193
+
194
+ ```python
195
+ from pymat.factories import water
196
+
197
+ # Water at different temperatures
198
+ cold_water = water(4) # Max density
199
+ room_water = water(20) # Room temperature
200
+ hot_water = water(80) # Heated
201
+ # Verify realistic values assert 0.95 < hot_water.density < 0.98
202
+ ```
203
+
204
+ ## Air at Different Conditions
205
+
206
+ Create air material at specific temperature and pressure:
207
+
208
+ ```python
209
+ from pymat.factories import air
210
+
211
+ sea_level = air(15, 1.0) # 15°C, 1 atm
212
+ high_altitude = air(15, 0.5) # 15°C, 0.5 atm (5500m)
213
+
214
+ assert sea_level.density > high_altitude.density
215
+ ```
216
+
217
+ ## Saline Solutions
218
+
219
+ Create solutions with specific concentration and temperature:
220
+
221
+ ```python
222
+ from pymat.factories import saline, water
223
+
224
+ # Physiological saline at body temperature
225
+ phantom = saline(0.9, temperature_c=37)
226
+ # Saline is slightly denser than pure water at same temperature
227
+ pure_water_37 = water(37)
228
+ # Seawater (3.5% NaCl) at 20°C
229
+ seawater = saline(3.5, temperature_c=20)
230
+ # Higher concentration = higher density
231
+ assert seawater.density > phantom.density
232
+ ```
233
+
234
+ ## Loading Metal Materials
235
+
236
+ Access various metal materials from the metals category:
237
+
238
+ ```python
239
+ from pymat import stainless, aluminum, copper
240
+
241
+ # Stainless steel variants
242
+ s304 = stainless.s304
243
+ s316L = stainless.s316L
244
+ # Aluminum alloys
245
+ al6061 = aluminum.a6061
246
+ al7075 = aluminum.a7075
247
+ # Copper
248
+ copper_material = copper
249
+ assert copper_material.density == 8.96
250
+ ```
251
+
252
+ ## Plastic Materials
253
+
254
+ Access plastic materials for 3D printing and engineering:
255
+
256
+ ```python
257
+ from pymat import peek, pla, pc, pmma
258
+
259
+ # Engineering plastics
260
+ # 3D printing plastics
261
+ # Transparent plastics assert pc.properties.optical.transparency == 89
262
+ ```
263
+
264
+ ## Scintillator Crystals
265
+
266
+ Access scintillator materials for radiation detectors:
267
+
268
+ ```python
269
+ from pymat import lyso, bgo, nai
270
+
271
+ # LYSO crystal
272
+ # BGO crystal
273
+ # NaI crystal
274
+ assert nai.properties.optical.light_yield == 38000
275
+ ```
276
+
277
+ ## Gas Materials
278
+
279
+ Access gases for simulation and detector design:
280
+
281
+ ```python
282
+ from pymat import air, nitrogen, argon, helium, xenon
283
+
284
+ # Common gases at STP
285
+ # Detector gases
286
+ assert argon.properties.compliance.radiation_resistant == True
287
+ ```
288
+
289
+ ## Property Inheritance
290
+
291
+ Child materials inherit properties from parents unless overridden:
292
+
293
+ ```python
294
+ from pymat import Material
295
+
296
+ # Create material hierarchy
297
+ root = Material(
298
+ name="Base",
299
+ density=7.8,
300
+ thermal={"melting_point": 1500, "thermal_conductivity": 50}
301
+ )
302
+
303
+ grade1 = root.grade_("G1", mechanical={"yield_strength": 400})
304
+ # Override inherited property
305
+ grade2 = root.grade_("G2", thermal={"melting_point": 1600})
306
+ assert grade2.properties.thermal.melting_point == 1600 # Overridden
307
+ ```
308
+
309
+ ## Automatic Mass Calculation
310
+
311
+ Materials with density automatically calculate shape mass:
312
+
313
+ ```python
314
+ from build123d import Box
315
+ from pymat import stainless, aluminum
316
+
317
+ # 10x10x10 mm³ box = 1000 mm³ = 1 cm³
318
+ steel_box = Box(10, 10, 10)
319
+ stainless.apply_to(steel_box)
320
+
321
+ # Density = 8.0 g/cm³, Volume = 1 cm³ → Mass = 8.0 g
322
+ # Aluminum box
323
+ al_box = Box(10, 10, 10)
324
+ aluminum.apply_to(al_box)
325
+
326
+ # Density = 2.7 g/cm³ → Mass = 2.7 g
327
+ assert 2.6 < al_box.mass < 2.8
328
+ ```
329
+
330
+ ## Material Visualization
331
+
332
+ Materials render with appropriate colors for visualization:
333
+
334
+ ```python
335
+ from build123d import Box
336
+ from pymat import stainless, aluminum, lyso
337
+
338
+ # Create shapes
339
+ steel_part = Box(10, 10, 10)
340
+ al_part = Box(10, 10, 10)
341
+ crystal = Box(10, 10, 10)
342
+
343
+ # Apply materials
344
+ stainless.apply_to(steel_part)
345
+ aluminum.apply_to(al_part)
346
+ lyso.apply_to(crystal)
347
+
348
+ # Verify colors are set
349
+ # Colors should differ assert crystal.color != steel_part.color
350
+ ```
351
+
352
+ ## Material Categories
353
+
354
+ - **Metals**: Stainless steel, aluminum, copper, tungsten, lead, titanium, brass
355
+ - **Scintillators**: LYSO, BGO, NaI, CsI, LaBr3, PWO, plastic scintillators
356
+ - **Plastics**: PEEK, Delrin, Ultem, PTFE, ESR, Nylon, PLA, ABS, PETG, TPU, PMMA, PE, PC
357
+ - **Ceramics**: Alumina, Macor, Zirconia, Glass (borosilicate, fused silica, BK7)
358
+ - **Electronics**: FR4, Rogers, Kapton, copper PCB, solder, ferrite
359
+ - **Liquids**: Water, Heavy Water, Mineral Oil, Glycerol, Silicone Oil
360
+ - **Gases**: Air, Nitrogen, Oxygen, Argon, CO₂, Helium, Hydrogen, Neon, Xenon, Methane, Vacuum
361
+
362
+ ## Property Groups
363
+
364
+ Each material can have properties organized in these domains:
365
+
366
+ - **Mechanical**: density, Young's modulus, yield strength, hardness
367
+ - **Thermal**: melting point, thermal conductivity, expansion coefficient
368
+ - **Electrical**: resistivity, conductivity, dielectric constant
369
+ - **Optical**: refractive index, transparency, light yield (PHYSICS - measured values)
370
+ - **PBR**: base color, metallic, roughness (VISUALIZATION - rendering appearance)
371
+ - **Manufacturing**: machinability, printability, weldability
372
+ - **Compliance**: RoHS, REACH, food-safe, biocompatible
373
+ - **Sourcing**: cost, availability, suppliers
374
+
375
+ ## Advanced Usage
376
+
377
+ ### Custom Materials
378
+
379
+ Create materials using property group dictionaries:
380
+
381
+ ```python
382
+ from pymat import Material
383
+
384
+ my_material = Material(
385
+ name="Custom Alloy",
386
+ mechanical={
387
+ "density": 8.1,
388
+ "youngs_modulus": 200,
389
+ "yield_strength": 450
390
+ },
391
+ pbr={
392
+ "base_color": (0.7, 0.7, 0.75, 1.0),
393
+ "metallic": 1.0,
394
+ "roughness": 0.4
395
+ }
396
+ )
397
+ ```
398
+
399
+ ### Loading from TOML
400
+
401
+ ```python
402
+ from pymat import load_toml
403
+
404
+ materials = load_toml("my_materials.toml")
405
+ my_material = materials["my_material"]
406
+ ```
407
+
408
+ ### Enrichment from Chemical Formulas
409
+
410
+ ```python
411
+ from pymat import enrich_from_periodictable
412
+
413
+ material = Material(name="Aluminum Oxide", formula="Al2O3")
414
+ enrich_from_periodictable(material)
415
+ print(material.density) # ~3.95 g/cm³
416
+ ```
417
+
418
+ ## Optical vs PBR Properties
419
+
420
+ **Important**: Understand the distinction between physics and visualization:
421
+
422
+ - **Optical Properties** (`optical.*`): Measured/calculated physical values
423
+ - `transparency`: % light transmission (measured)
424
+ - `refractive_index`: optical property (measured)
425
+ - `light_yield`: scintillator brightness (measured)
426
+
427
+ - **PBR Properties** (`pbr.*`): Rendering/visualization parameters
428
+ - `base_color`: RGBA values (0-1) for display
429
+ - `transmission`: how transparent it LOOKS in renders
430
+ - `metallic`: surface finish appearance
431
+ - `roughness`: surface roughness appearance
432
+
433
+ These can differ intentionally! A material might be physically transparent (95% optical transmission) but rendered opaque (0% pbr transmission) for CAD clarity.
434
+
435
+ ## License
436
+
437
+ MIT
438
+
439
+ ## Links
440
+
441
+ - **GitHub**: https://github.com/MorePET/py-mat
442
+ - **Issues**: https://github.com/MorePET/py-mat/issues
443
+