API Reference¶
Query Functions¶
get_preset¶
Get a mineral preset dictionary by name.
from mineral_database import get_preset
diamond = get_preset('diamond')
print(diamond['cdl']) # CDL string
print(diamond['system']) # Crystal system
print(diamond['hardness']) # Mohs hardness
mineral_database.get_preset(name)
¶
Get a crystal preset by name.
This is the primary compatibility function matching the original API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Preset name (case-insensitive) |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Preset dictionary or None if not found |
Source code in src/mineral_database/queries.py
get_mineral¶
Get a Mineral object by name.
from mineral_database import get_mineral
mineral = get_mineral('ruby')
print(mineral.id) # 'ruby'
print(mineral.name) # 'Ruby'
print(mineral.system) # 'trigonal'
print(mineral.chemistry) # 'Al2O3:Cr'
print(mineral.hardness) # 9
print(mineral.ri) # '1.762-1.770'
print(mineral.localities) # ['Myanmar', 'Mozambique', ...]
mineral_database.get_mineral(name)
¶
Get a Mineral object by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Preset name (case-insensitive) |
required |
Returns:
| Type | Description |
|---|---|
Mineral | None
|
Mineral object or None if not found |
Source code in src/mineral_database/queries.py
list_presets¶
List preset names, optionally filtered by crystal system.
from mineral_database import list_presets
# All presets
all_presets = list_presets()
# Filter by system
cubic_presets = list_presets('cubic')
trigonal_presets = list_presets('trigonal')
mineral_database.list_presets(category=None)
¶
List available preset names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str | None
|
Optional crystal system or category to filter by |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of preset names |
Source code in src/mineral_database/queries.py
list_preset_categories¶
List all preset categories/tags.
from mineral_database import list_preset_categories
categories = list_preset_categories()
# ['cubic', 'hexagonal', 'trigonal', 'twins', ...]
mineral_database.list_preset_categories()
¶
List available preset categories (crystal systems).
Source code in src/mineral_database/queries.py
search_presets¶
Full-text search across mineral names and properties.
from mineral_database import search_presets
# Search by name
garnet_matches = search_presets('garnet')
# Search by property
red_gems = search_presets('red')
mineral_database.search_presets(query)
¶
Search presets by name, mineral name, or chemistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search term |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of matching preset names |
Source code in src/mineral_database/queries.py
filter_minerals¶
Filter minerals by multiple criteria.
from mineral_database import filter_minerals
# Filter by system and hardness
hard_cubic = filter_minerals(system='cubic', min_hardness=8)
# Filter by optical properties
birefringent = filter_minerals(has_birefringence=True)
mineral_database.filter_minerals(system=None, min_hardness=None, max_hardness=None, has_twin=False)
¶
Filter minerals by various criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str | None
|
Filter by crystal system |
None
|
min_hardness
|
float | None
|
Minimum Mohs hardness |
None
|
max_hardness
|
float | None
|
Maximum Mohs hardness |
None
|
has_twin
|
bool
|
Only return minerals with twin laws |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of matching preset names |
Source code in src/mineral_database/queries.py
get_presets_by_form¶
Get presets that include a specific crystal form.
from mineral_database import get_presets_by_form
# Get all minerals with octahedral habit
octahedral = get_presets_by_form('octahedron')
mineral_database.get_presets_by_form(form_name)
¶
Get presets that include a specific crystal form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_name
|
str
|
Form name (e.g., 'octahedron', 'cube') |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of preset names |
Source code in src/mineral_database/queries.py
count_presets¶
Get total count of presets.
from mineral_database import count_presets
total = count_presets()
print(f"Database contains {total} presets") # 94+
mineral_database.count_presets()
¶
Get total number of presets in database.
Returns:
| Type | Description |
|---|---|
int
|
Number of presets |
Data Classes¶
Mineral¶
Full mineral data object.
from mineral_database import Mineral
@dataclass
class Mineral:
id: str
name: str
cdl: str
system: str
point_group: str
chemistry: Optional[str]
hardness: Optional[float]
description: Optional[str]
sg: Optional[float]
ri: Optional[str]
birefringence: Optional[float]
optical_character: Optional[str]
dispersion: Optional[float]
lustre: Optional[str]
cleavage: Optional[str]
fracture: Optional[str]
pleochroism: Optional[str]
twin_law: Optional[str]
phenomenon: Optional[str]
localities: List[str]
forms: List[str]
colors: List[str]
treatments: List[str]
inclusions: List[str]
mineral_database.Mineral
dataclass
¶
A mineral preset with crystallographic and gemmological properties.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique preset identifier (e.g., 'diamond', 'ruby') |
name |
str
|
Display name (e.g., 'Diamond', 'Ruby') |
cdl |
str
|
Crystal Description Language notation |
system |
str
|
Crystal system (cubic, hexagonal, etc.) |
point_group |
str
|
Hermann-Mauguin point group symbol |
chemistry |
str
|
Chemical formula |
hardness |
int | float | str
|
Mohs hardness (can be range like '5-7') |
description |
str
|
Crystal habit description |
localities |
list[str]
|
List of notable localities |
forms |
list[str]
|
List of crystal forms present |
sg |
float | str | None
|
Specific gravity (may be range string) |
ri |
float | str | None
|
Refractive index (may be range string) |
birefringence |
float | None
|
Birefringence value or None for isotropic |
optical_character |
str | None
|
Optical character (Uniaxial +/-, Biaxial +/-, Isotropic) |
dispersion |
float | None
|
Dispersion coefficient |
lustre |
str | None
|
Surface lustre |
cleavage |
str | None
|
Cleavage description |
fracture |
str | None
|
Fracture type |
pleochroism |
str | None
|
Pleochroism description |
colors |
list[str]
|
List of possible colors |
treatments |
list[str]
|
List of known treatments |
inclusions |
list[str]
|
List of diagnostic inclusions |
twin_law |
str | None
|
Associated twin law name |
phenomenon |
str | None
|
Optical phenomenon (e.g., 'Adularescence') |
note |
str | None
|
Additional notes |
Source code in src/mineral_database/models.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
from_dict(id, data)
classmethod
¶
Create Mineral from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The preset identifier |
required |
data
|
dict[str, Any]
|
Dictionary of mineral properties |
required |
Returns:
| Type | Description |
|---|---|
Mineral
|
Mineral instance |
Source code in src/mineral_database/models.py
to_dict()
¶
Convert to dictionary representation.
Source code in src/mineral_database/models.py
Property Formatting¶
INFO_GROUPS¶
Property groups for display organization.
from mineral_database import INFO_GROUPS
# Groups: 'identification', 'physical', 'optical', 'crystallographic'
for group, props in INFO_GROUPS.items():
print(f"{group}: {props}")
get_info_properties¶
Get formatted properties for display.
from mineral_database import get_info_properties
# Get FGA-style properties
props = get_info_properties('ruby', 'fga')
# Returns: {'name': 'Ruby', 'ri': '1.762-1.770', 'sg': 4.0, ...}
mineral_database.get_info_properties(preset_name, group_or_keys)
¶
Get specific properties from a preset for info panel display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset_name
|
str
|
Name of the preset |
required |
group_or_keys
|
str
|
Either a group name ('basic', 'full', 'fga', etc.) or comma-separated property keys |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of property key -> value for display |
Source code in src/mineral_database/queries.py
get_property_label¶
Get display label for a property key.
from mineral_database import get_property_label
label = get_property_label('sg') # 'SG'
label = get_property_label('ri') # 'RI'
mineral_database.get_property_label(key)
¶
format_property_value¶
Format a property value for display.
from mineral_database import format_property_value
value = format_property_value('sg', 4.0) # '4.00'
value = format_property_value('hardness', 9) # '9'
mineral_database.format_property_value(key, value)
¶
Format a property value for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Property key |
required |
value
|
Any
|
Property value |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string for display |
Source code in src/mineral_database/models.py
Pre-generated Models¶
Functions for accessing pre-generated 3D visualizations stored in the database.
get_model_svg¶
Get pre-generated SVG visualization.
from mineral_database import get_model_svg
svg = get_model_svg('diamond')
if svg:
with open('diamond.svg', 'w') as f:
f.write(svg)
mineral_database.get_model_svg(mineral_id)
¶
Get the pre-generated SVG for a mineral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mineral_id
|
str
|
Mineral preset ID (case-insensitive) |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
SVG markup string or None if not generated |
Source code in src/mineral_database/queries.py
get_model_stl¶
Get pre-generated binary STL for 3D printing.
from mineral_database import get_model_stl
stl = get_model_stl('quartz')
if stl:
with open('quartz.stl', 'wb') as f:
f.write(stl)
mineral_database.get_model_stl(mineral_id)
¶
Get the pre-generated STL binary for a mineral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mineral_id
|
str
|
Mineral preset ID (case-insensitive) |
required |
Returns:
| Type | Description |
|---|---|
bytes | None
|
Binary STL data or None if not generated |
Source code in src/mineral_database/queries.py
get_model_gltf¶
Get pre-generated glTF for web display.
from mineral_database import get_model_gltf
import json
gltf = get_model_gltf('ruby')
if gltf:
with open('ruby.gltf', 'w') as f:
json.dump(gltf, f)
mineral_database.get_model_gltf(mineral_id)
¶
Get the pre-generated glTF for a mineral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mineral_id
|
str
|
Mineral preset ID (case-insensitive) |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object] | None
|
glTF dictionary or None if not generated |
Source code in src/mineral_database/queries.py
get_models_generated_at¶
Check when models were generated.
from mineral_database import get_models_generated_at
timestamp = get_models_generated_at('emerald')
# Returns ISO timestamp or None
mineral_database.get_models_generated_at(mineral_id)
¶
Get the timestamp when models were generated for a mineral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mineral_id
|
str
|
Mineral preset ID (case-insensitive) |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ISO timestamp string or None if not generated |
Source code in src/mineral_database/queries.py
Backwards Compatibility¶
CRYSTAL_PRESETS¶
Dict-like interface for legacy code migration.
from mineral_database import CRYSTAL_PRESETS
# Supports all dict operations
preset = CRYSTAL_PRESETS['diamond']
preset = CRYSTAL_PRESETS.get('ruby', None)
'garnet' in CRYSTAL_PRESETS
len(CRYSTAL_PRESETS)
list(CRYSTAL_PRESETS.keys())
list(CRYSTAL_PRESETS.values())
list(CRYSTAL_PRESETS.items())