Crystal presets database for gemmological and mineralogical visualization
Project description
mineral-database
Mineral Database - A comprehensive database of mineral crystal habits with CDL notation and gemmological properties for visualization applications.
Part of the Gemmology Project.
Installation
pip install mineral-database
Quick Start
from mineral_database import get_preset, list_presets, search_presets
# Get a specific mineral preset
diamond = get_preset('diamond')
print(diamond['cdl']) # 'cubic[m3m]:{111}@1.0 + {110}@0.2'
print(diamond['system']) # 'cubic'
print(diamond['hardness']) # 10
# List all presets
all_presets = list_presets()
# List presets by crystal system
cubic_presets = list_presets('cubic')
# Search presets
garnet_matches = search_presets('garnet')
Features
- 140 CDL expressions across 96 mineral families (68 natural + 15 synthetic + 9 simulant + 4 composite)
- CDL v2.0 notation for crystal habit visualization, including amorphous, nested growth, and aggregate expressions
- FGA-standard properties (RI, SG, optical character, etc.)
- SQLite backend for fast queries
- Full-text search across mineral names and properties
- Backwards compatible with original
CRYSTAL_PRESETSdict API
Database Contents
The database includes presets for all major crystal systems:
| System | Count | Examples |
|---|---|---|
| Cubic | ~25 | Diamond, Garnet, Fluorite, Pyrite |
| Hexagonal | ~8 | Beryl, Emerald, Aquamarine, Apatite |
| Trigonal | ~15 | Quartz, Ruby, Sapphire, Tourmaline |
| Tetragonal | ~5 | Zircon, Rutile, Cassiterite |
| Orthorhombic | ~10 | Topaz, Peridot, Tanzanite |
| Monoclinic | ~10 | Kunzite, Epidote, Gypsum |
| Triclinic | ~5 | Turquoise, Kyanite, Labradorite |
| Amorphous | ~7 | Opal, Pearl, Malachite, Turquoise, Sodalite, Lazurite |
| Twins | ~15 | Japan Law, Spinel Macle, Iron Cross |
CDL v2.0 Expressions
All 140 CDL expressions parse successfully with CDL v2.0, including:
- Amorphous expressions for materials without crystalline structure: opal (
amorphous[opalescent]:{botryoidal}), pearl, malachite, turquoise, sodalite, lazurite, rhodochrosite (banded form) - Nested growth expressions using the
>operator: scepter quartz, phantom quartz, diamond phantom - Aggregate expressions using the
~operator: quartz cluster, amethyst geode druse, pyrite cluster, fluorite cluster, calcite parallel growth - Doc comments (
#!) on major expressions documenting system, habit, and species information
Database Completeness (Updated 2026-01-25)
The mineral database has been comprehensively enriched with FGA-standard gemmological data:
- 96 mineral families (68 natural + 15 synthetic + 9 simulant + 4 composite) with complete crystallographic data
- 92/95 minerals (96.8%) with complete RI (refractive index)
- 94/95 minerals (98.9%) with complete SG (specific gravity)
- 94/95 minerals (98.9%) with optical character classification
- 93/95 minerals (97.9%) with pleochroism data
- 94/95 minerals (98.9%) with lustre, cleavage, and fracture data
- 60/95 minerals (63.2%) with dispersion values
- 40+ gemstones with comprehensive treatments and diagnostic inclusions
Data Completeness by Crystal System
| System | Minerals | RI | SG | Optical Character |
|---|---|---|---|---|
| Cubic | 26 | 92.3% | 100% | 100% |
| Trigonal | 19 | 100% | 100% | 100% |
| Monoclinic | 15 | 100% | 100% | 100% |
| Orthorhombic | 13 | 92.3% | 92.3% | 92.3% |
| Hexagonal | 8 | 100% | 100% | 100% |
| Triclinic | 7 | 100% | 100% | 100% |
| Tetragonal | 6 | 100% | 100% | 100% |
| Amorphous | 1 | 100% | 100% | 100% |
Data Sources
- FGA (Fellowship of the Gemmological Association) curriculum materials
- Mindat.org mineralogical database
- GIA (Gemological Institute of America) gem encyclopedia
- Webmineral.com physical property database
- International Gem Society reference materials
All data has been cross-validated against multiple authoritative sources and validated for consistency with crystal system optical properties.
API Reference
Query Functions
from mineral_database import (
get_preset, # Get preset dict by name
get_mineral, # Get Mineral object by name
list_presets, # List preset names
list_preset_categories, # List categories
search_presets, # Full-text search
filter_minerals, # Filter by criteria
get_presets_by_form, # Get by crystal form
count_presets, # Total count
)
Backwards Compatibility
The package provides dict-like CRYSTAL_PRESETS for code migration:
from mineral_database import CRYSTAL_PRESETS
# All dict operations work
preset = CRYSTAL_PRESETS['diamond']
preset = CRYSTAL_PRESETS.get('ruby')
'garnet' in CRYSTAL_PRESETS
for name in CRYSTAL_PRESETS:
print(name)
Mineral Object
from mineral_database import get_mineral, 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', ...]
Property Formatting
from mineral_database import (
INFO_GROUPS,
get_info_properties,
get_property_label,
format_property_value,
)
# Get FGA-style properties
props = get_info_properties('ruby', 'fga')
# Returns: {'name': 'Ruby', 'ri': '1.762-1.770', 'sg': 4.0, ...}
# Format for display
label = get_property_label('sg') # 'SG'
value = format_property_value('sg', 4.0) # '4'
CLI Usage
# List all presets
mineral-db --list
# List by crystal system
mineral-db --list cubic
# Show preset details
mineral-db --info diamond
# Search presets
mineral-db --search garnet
# Output as JSON
mineral-db --json ruby
# Show categories
mineral-db --categories
Database Schema
The SQLite database stores minerals with full gemmological properties:
# Core fields (all minerals)
id, name, cdl, system, point_group, chemistry, hardness, description
# Optional gemmological properties
sg, ri, birefringence, optical_character, dispersion, lustre,
cleavage, fracture, pleochroism, twin_law, phenomenon
# List fields (JSON-encoded)
localities, forms, colors, treatments, inclusions
Building the Database
For development, you can rebuild the database from source:
# From legacy Python dict
python scripts/build_db.py --from-legacy crystal_presets.py -o minerals.db
# From YAML files
python scripts/build_db.py --from-yaml data/source/minerals -o minerals.db
# Export to YAML for editing
python scripts/build_db.py --export-yaml minerals.db -o data/source/minerals
Development
# Clone and install
git clone https://github.com/gemmology-dev/mineral-database.git
cd mineral-database
pip install -e ".[dev]"
# Run tests
pytest
# Build database
python scripts/build_db.py --from-legacy /path/to/crystal_presets.py -o src/mineral_database/data/minerals.db
License
MIT License - see LICENSE for details.
Related Projects
- cdl-parser - CDL notation parser
- crystal-geometry - 3D geometry from CDL
- crystal-renderer - SVG/3D rendering
- gemmology-plugin - Claude Code plugin
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gemmology_mineral_database-2.1.1.tar.gz.
File metadata
- Download URL: gemmology_mineral_database-2.1.1.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d74c36b9fa8fc6bd970098fe6e3ab87ea0db90286404d902301316e35f87fa1
|
|
| MD5 |
48b4f489e72aa3b93879c7adbc230019
|
|
| BLAKE2b-256 |
4f8f9c8fbbf96949ea7a0dac80e898844d73c1aa1323dd65495a33147b74f6e7
|
Provenance
The following attestation bundles were made for gemmology_mineral_database-2.1.1.tar.gz:
Publisher:
pypi-publish.yml on gemmology-dev/mineral-database
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gemmology_mineral_database-2.1.1.tar.gz -
Subject digest:
6d74c36b9fa8fc6bd970098fe6e3ab87ea0db90286404d902301316e35f87fa1 - Sigstore transparency entry: 956106033
- Sigstore integration time:
-
Permalink:
gemmology-dev/mineral-database@488cf8663f78c9a7c97c0e88e517c868f5f5fd09 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/gemmology-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@488cf8663f78c9a7c97c0e88e517c868f5f5fd09 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gemmology_mineral_database-2.1.1-py3-none-any.whl.
File metadata
- Download URL: gemmology_mineral_database-2.1.1-py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51dac79d70aea38492323f39d08aef3fa00767f6bd016c11ea43f948f8347bcb
|
|
| MD5 |
9bc7716c7a3862f35ee26ad5896523a6
|
|
| BLAKE2b-256 |
8a7088feaaed6ab2409e6b36b631db630d3d470bd5f110e6351c6ac50c62fae2
|
Provenance
The following attestation bundles were made for gemmology_mineral_database-2.1.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on gemmology-dev/mineral-database
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gemmology_mineral_database-2.1.1-py3-none-any.whl -
Subject digest:
51dac79d70aea38492323f39d08aef3fa00767f6bd016c11ea43f948f8347bcb - Sigstore transparency entry: 956106036
- Sigstore integration time:
-
Permalink:
gemmology-dev/mineral-database@488cf8663f78c9a7c97c0e88e517c868f5f5fd09 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/gemmology-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@488cf8663f78c9a7c97c0e88e517c868f5f5fd09 -
Trigger Event:
release
-
Statement type: