py-materials 2.0.5__py3-none-any.whl
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.0.5.dist-info/METADATA +443 -0
- py_materials-2.0.5.dist-info/RECORD +19 -0
- py_materials-2.0.5.dist-info/WHEEL +4 -0
- py_materials-2.0.5.dist-info/licenses/LICENSE +22 -0
- pymat/__init__.py +189 -0
- pymat/core.py +521 -0
- pymat/data/ceramics.toml +327 -0
- pymat/data/electronics.toml +356 -0
- pymat/data/gases.toml +384 -0
- pymat/data/liquids.toml +191 -0
- pymat/data/metals.toml +828 -0
- pymat/data/plastics.toml +699 -0
- pymat/data/scintillators.toml +287 -0
- pymat/enrichers.py +154 -0
- pymat/factories.py +203 -0
- pymat/loader.py +260 -0
- pymat/properties.py +456 -0
- pymat/registry.py +50 -0
- pymat/units.py +53 -0
|
@@ -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
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
pymat/__init__.py,sha256=IzzLQoSIOlC2bJlFK4IcQj0S4EAW2G71OQk8ZmH0H40,6100
|
|
2
|
+
pymat/core.py,sha256=FHRzNs67XZsol05dvBedIzuhMWuNE53OUE35mz8qZ_A,21082
|
|
3
|
+
pymat/enrichers.py,sha256=j58MY0gsvZ--xt_ZIavfAG2FpniZ-0nSzmpUZWWlHH8,4351
|
|
4
|
+
pymat/factories.py,sha256=R8EIpCdHmvoLZryo0utJOaKuimPJ1KUadTllBeoPyxQ,7051
|
|
5
|
+
pymat/loader.py,sha256=JKD9VJ9JjAHiPHwOxrXTNCi0QCOau5sKj9bRQ5MZIRw,9302
|
|
6
|
+
pymat/properties.py,sha256=MxVjs7JvU8h_oMVhhmUYxYrxSrNYSbseT-yE3bw1u6A,18737
|
|
7
|
+
pymat/registry.py,sha256=TPrAtsYhM5MUthzj7AmSgd1CRyzp3xAjvgXjKwPKE1Y,1187
|
|
8
|
+
pymat/units.py,sha256=wn5wAcEufOwk2nv-B7NOBGopIwX5oWT8Q-AGYtcQNxY,1429
|
|
9
|
+
pymat/data/ceramics.toml,sha256=wOcf5b7UfYH3dDykXdBSMHm5Q3_60-76emhIdnopMBY,6914
|
|
10
|
+
pymat/data/electronics.toml,sha256=UhenkzQ2eCnNc98mlsST6Zo-OcaGIA_JPaZaIzOGTv0,7724
|
|
11
|
+
pymat/data/gases.toml,sha256=spNEgEtNS0xAq3LicL3ax5sRVSkLY1SSCMVyTYcDp1Y,8086
|
|
12
|
+
pymat/data/liquids.toml,sha256=gR4DQ2ut-xiufSvrysNzK_PDVeH9zsfnPwDBYM_n1Pk,4195
|
|
13
|
+
pymat/data/metals.toml,sha256=lTHtz-LAMhpockIABgtaI90kCzMczyRuFfh9OlyFk7U,18670
|
|
14
|
+
pymat/data/plastics.toml,sha256=UTppsqkwZIVSyPSjYNS6v-EB78CWiY64e1Wjzgycgu8,14712
|
|
15
|
+
pymat/data/scintillators.toml,sha256=D8LKttYaZMuUv2Z4jYArL8vL0-h7NGme-tk9WrSop4I,5301
|
|
16
|
+
py_materials-2.0.5.dist-info/METADATA,sha256=5oNEaaZ3ZOdNNnoknqf2lcRRSm0yGlxN-n-sqtBXq8Y,13986
|
|
17
|
+
py_materials-2.0.5.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
18
|
+
py_materials-2.0.5.dist-info/licenses/LICENSE,sha256=MVbFZ9LZNRJBnTWmwwoP4rPsCh5_NEVo7HHMR3OXy8M,1070
|
|
19
|
+
py_materials-2.0.5.dist-info/RECORD,,
|
|
@@ -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
|
+
|
pymat/__init__.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pymat - Hierarchical material library for CAD applications.
|
|
3
|
+
|
|
4
|
+
Features:
|
|
5
|
+
- Chainable hierarchy: stainless.s316L.electropolished.apply_to(part)
|
|
6
|
+
- Direct access: s316L.apply_to(part) (auto-registered if no collision)
|
|
7
|
+
- Property inheritance: children inherit parent properties
|
|
8
|
+
- Lazy loading: categories load on first access
|
|
9
|
+
- periodictable integration: auto-fill density from formula
|
|
10
|
+
- PBR support: rendering properties for glTF/3MF export
|
|
11
|
+
- Unit-aware properties with Pint for dimensional analysis
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
from pymat import stainless, aluminum, lyso, s304, T6, ureg
|
|
15
|
+
|
|
16
|
+
# Chainable
|
|
17
|
+
housing = stainless.s316L.electropolished.apply_to(Box(50, 50, 10))
|
|
18
|
+
|
|
19
|
+
# Direct access
|
|
20
|
+
crystal = lyso.apply_to(Box(10, 10, 30))
|
|
21
|
+
bracket = s304.apply_to(Box(30, 20, 5))
|
|
22
|
+
|
|
23
|
+
# Check properties
|
|
24
|
+
print(housing.material.properties.pbr.roughness)
|
|
25
|
+
print(crystal.material.properties.optical.light_yield)
|
|
26
|
+
|
|
27
|
+
# Unit-aware calculations
|
|
28
|
+
density_qty = stainless.s304.properties.mechanical.density_qty
|
|
29
|
+
density_kg_m3 = density_qty.to('kg/m^3')
|
|
30
|
+
|
|
31
|
+
# Temperature-dependent properties
|
|
32
|
+
k_at_100c = stainless.properties.thermal.thermal_conductivity_at(100 * ureg.degC)
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from __future__ import annotations
|
|
36
|
+
from pathlib import Path
|
|
37
|
+
from typing import Dict, Any, TYPE_CHECKING
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from .core import Material
|
|
41
|
+
|
|
42
|
+
# Exports
|
|
43
|
+
from .core import Material
|
|
44
|
+
from .properties import (
|
|
45
|
+
AllProperties, MechanicalProperties, ThermalProperties,
|
|
46
|
+
ElectricalProperties, OpticalProperties, PBRProperties,
|
|
47
|
+
ManufacturingProperties, ComplianceProperties, SourcingProperties,
|
|
48
|
+
)
|
|
49
|
+
from .units import ureg
|
|
50
|
+
from . import registry
|
|
51
|
+
from .loader import load_toml, load_category
|
|
52
|
+
from .enrichers import enrich_from_periodictable, enrich_from_matproj, enrich_all
|
|
53
|
+
from . import factories
|
|
54
|
+
|
|
55
|
+
__version__ = "2.0.4"
|
|
56
|
+
__all__ = [
|
|
57
|
+
"Material",
|
|
58
|
+
"AllProperties",
|
|
59
|
+
"MechanicalProperties",
|
|
60
|
+
"ThermalProperties",
|
|
61
|
+
"ElectricalProperties",
|
|
62
|
+
"OpticalProperties",
|
|
63
|
+
"PBRProperties",
|
|
64
|
+
"ManufacturingProperties",
|
|
65
|
+
"ComplianceProperties",
|
|
66
|
+
"SourcingProperties",
|
|
67
|
+
"ureg",
|
|
68
|
+
"load_toml",
|
|
69
|
+
"load_category",
|
|
70
|
+
"enrich_from_periodictable",
|
|
71
|
+
"enrich_from_matproj",
|
|
72
|
+
"enrich_all",
|
|
73
|
+
"factories",
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
# ============================================================================
|
|
77
|
+
# Lazy Loading State
|
|
78
|
+
# ============================================================================
|
|
79
|
+
|
|
80
|
+
_LOADED_CATEGORIES: set[str] = set()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# Category to base materials mapping
|
|
84
|
+
_CATEGORY_BASES: Dict[str, list[str]] = {
|
|
85
|
+
"metals": ["stainless", "aluminum", "copper", "tungsten", "lead", "titanium", "brass"],
|
|
86
|
+
"scintillators": ["lyso", "bgo", "nai", "csi", "labr3", "pwo", "plastic_scint"],
|
|
87
|
+
"plastics": ["peek", "delrin", "ultem", "ptfe", "esr", "nylon", "pla", "abs", "petg", "tpu", "vespel", "torlon", "pctfe", "pmma", "pe", "pc"],
|
|
88
|
+
"ceramics": ["alumina", "macor", "zirconia", "glass"],
|
|
89
|
+
"electronics": ["fr4", "rogers", "kapton", "copper_pcb", "solder"],
|
|
90
|
+
"liquids": ["water", "heavy_water", "mineral_oil", "glycerol", "silicone_oil"],
|
|
91
|
+
"gases": ["air", "nitrogen", "oxygen", "argon", "co2", "helium", "hydrogen", "neon", "xenon", "methane", "vacuum"],
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _ensure_loaded(category: str) -> None:
|
|
96
|
+
"""Load a material category if not already loaded."""
|
|
97
|
+
if category not in _LOADED_CATEGORIES:
|
|
98
|
+
try:
|
|
99
|
+
load_category(category)
|
|
100
|
+
_LOADED_CATEGORIES.add(category)
|
|
101
|
+
except FileNotFoundError:
|
|
102
|
+
raise FileNotFoundError(
|
|
103
|
+
f"Material category '{category}' not found. "
|
|
104
|
+
f"Available categories: {list(_CATEGORY_BASES.keys())}"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _ensure_material_loaded(name: str) -> None:
|
|
109
|
+
"""Ensure a specific material is loaded by finding its category."""
|
|
110
|
+
# Check if already in registry
|
|
111
|
+
if registry.get(name):
|
|
112
|
+
return
|
|
113
|
+
|
|
114
|
+
# Try each category
|
|
115
|
+
for category, bases in _CATEGORY_BASES.items():
|
|
116
|
+
if name in bases or name.lower() in [b.lower() for b in bases]:
|
|
117
|
+
_ensure_loaded(category)
|
|
118
|
+
if registry.get(name):
|
|
119
|
+
return
|
|
120
|
+
|
|
121
|
+
# If still not found, raise error with helpful message
|
|
122
|
+
all_bases = []
|
|
123
|
+
for bases in _CATEGORY_BASES.values():
|
|
124
|
+
all_bases.extend(bases)
|
|
125
|
+
raise AttributeError(
|
|
126
|
+
f"Material '{name}' not found. Available materials: {all_bases}"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def __getattr__(name: str) -> Material:
|
|
131
|
+
"""
|
|
132
|
+
Lazy-load materials on first access.
|
|
133
|
+
|
|
134
|
+
Usage:
|
|
135
|
+
from pymat import stainless # triggers lazy load of metals.toml
|
|
136
|
+
from pymat import lyso # triggers lazy load of scintillators.toml
|
|
137
|
+
"""
|
|
138
|
+
if name.startswith("_"):
|
|
139
|
+
raise AttributeError(f"module 'pymat' has no attribute '{name}'")
|
|
140
|
+
|
|
141
|
+
# Try to find and load the material
|
|
142
|
+
_ensure_material_loaded(name)
|
|
143
|
+
|
|
144
|
+
# Retrieve from registry
|
|
145
|
+
material = registry.get(name)
|
|
146
|
+
if material:
|
|
147
|
+
return material
|
|
148
|
+
|
|
149
|
+
raise AttributeError(f"module 'pymat' has no attribute '{name}'")
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def __dir__() -> list[str]:
|
|
153
|
+
"""
|
|
154
|
+
Help IDE discover available materials.
|
|
155
|
+
|
|
156
|
+
Returns list of all registered materials plus standard exports.
|
|
157
|
+
"""
|
|
158
|
+
base_exports = [
|
|
159
|
+
"Material", "AllProperties",
|
|
160
|
+
"MechanicalProperties", "ThermalProperties",
|
|
161
|
+
"ElectricalProperties", "OpticalProperties",
|
|
162
|
+
"PBRProperties", "ManufacturingProperties",
|
|
163
|
+
"ComplianceProperties", "SourcingProperties",
|
|
164
|
+
"load_toml", "load_category",
|
|
165
|
+
"enrich_from_periodictable", "enrich_from_matproj", "enrich_all",
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
# Add all known base materials
|
|
169
|
+
known_materials = []
|
|
170
|
+
for bases in _CATEGORY_BASES.values():
|
|
171
|
+
known_materials.extend(bases)
|
|
172
|
+
|
|
173
|
+
return base_exports + known_materials
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def load_all() -> Dict[str, Material]:
|
|
177
|
+
"""
|
|
178
|
+
Load all material categories.
|
|
179
|
+
|
|
180
|
+
Useful if you want everything available at startup.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
Dictionary of {name -> Material} for all registered materials
|
|
184
|
+
"""
|
|
185
|
+
for category in _CATEGORY_BASES.keys():
|
|
186
|
+
_ensure_loaded(category)
|
|
187
|
+
|
|
188
|
+
return registry.list_all()
|
|
189
|
+
|