SVG and 3D visualization for crystal geometries
Project description
Crystal Renderer
SVG and 3D visualization for crystal geometries. Renders crystal structures from CDL notation with export to multiple formats including SVG, STL, and glTF.
Part of the Gemmology Project.
Installation
pip install crystal-renderer
For raster image export (PNG, JPG):
pip install crystal-renderer[raster]
Quick Start
from crystal_renderer import generate_cdl_svg
# Generate SVG from CDL notation
generate_cdl_svg("cubic[m3m]:{111}@1.0 + {100}@1.3", "crystal.svg")
# Export to 3D formats
from crystal_geometry import create_octahedron
from crystal_renderer import export_stl, export_gltf
geom = create_octahedron()
export_stl(geom.vertices, geom.faces, "octahedron.stl")
export_gltf(geom.vertices, geom.faces, "octahedron.gltf")
Features
- CDL Visualization: Generate SVG images from Crystal Description Language notation
- Multi-Format Export: SVG, PNG, JPG, STL, glTF
- Customizable Rendering: Face colors, axes, grid, labels
- Info Panels: FGA-style property panels on visualizations
- 3D Projection: Configurable elevation and azimuth angles
- Color Schemes: System-based and form-based coloring
API Reference
High-Level Visualization
from crystal_renderer import generate_cdl_svg, generate_geometry_svg
# From CDL string
generate_cdl_svg(
cdl_string="cubic[m3m]:{111}@1.0",
output_path="crystal.svg",
show_axes=True,
elev=30,
azim=-45,
color_by_form=False,
show_grid=True,
face_labels=False
)
# From raw geometry
generate_geometry_svg(
vertices=geom.vertices,
faces=geom.faces,
output_path="geometry.svg",
face_color='#81D4FA',
edge_color='#0277BD'
)
3D Export
from crystal_renderer import export_stl, export_gltf
# STL for 3D printing
export_stl(vertices, faces, "model.stl", binary=True)
# glTF for web/AR
export_gltf(
vertices, faces, "model.gltf",
color=(0.5, 0.7, 0.9, 0.8), # RGBA
name="crystal"
)
Format Conversion
from crystal_renderer import convert_svg_to_raster, generate_with_format
# Convert existing SVG to PNG
convert_svg_to_raster("input.svg", "output.png", scale=2.0)
# Generate directly to raster format
generate_with_format(
generator_func=generate_cdl_svg,
output_path="crystal.png",
output_format="png",
cdl_string="cubic[m3m]:{111}"
)
Info Panels
from crystal_renderer import render_info_panel, create_fga_info_panel
# On a matplotlib axes
properties = {
'name': 'Ruby',
'chemistry': 'Al2O3',
'hardness': '9',
'ri': '1.762-1.770'
}
render_info_panel(ax, properties, position='top-right', style='compact')
# Create FGA-style panel from mineral data
fga_props = create_fga_info_panel(mineral_data)
Color Constants
from crystal_renderer import (
AXIS_COLOURS, # a, b, c axis colors
ELEMENT_COLOURS, # Per-element colors
HABIT_COLOURS, # Per-crystal-system colors
FORM_COLORS, # Colors for multi-form rendering
)
# Get element color
from crystal_renderer import get_element_colour
color = get_element_colour('Si') # '#F0C8A0'
Projection Utilities
from crystal_renderer import (
calculate_view_direction,
calculate_axis_origin,
calculate_vertex_visibility,
is_face_visible,
)
# Calculate which vertices are front-facing
visibility = calculate_vertex_visibility(vertices, faces, elev=30, azim=-45)
Output Formats
| Format | Extension | Description |
|---|---|---|
| SVG | .svg |
Vector graphics, scalable |
| PNG | .png |
Raster with transparency |
| JPG | .jpg |
Compressed raster |
| STL | .stl |
3D printing format |
| glTF | .gltf |
Web/AR 3D format |
Requirements
- Python >= 3.10
- numpy >= 1.20.0
- matplotlib >= 3.5.0
- cdl-parser >= 1.0.0
- crystal-geometry >= 1.0.0
Optional
cairosvg- SVG to raster conversionPillow- Image processingase- Atomic structure visualization
Documentation
See crystal-renderer.gemmology.dev for full documentation.
License
MIT License - see LICENSE for details.
Related Packages
- cdl-parser - Crystal Description Language parser
- crystal-geometry - 3D geometry engine
- mineral-database - Mineral preset database
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_crystal_renderer-1.0.0.tar.gz.
File metadata
- Download URL: gemmology_crystal_renderer-1.0.0.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
863ba539d7789626979aa6fcd226d2ae53da2f4b6d6bb1f897fab830e97a8174
|
|
| MD5 |
0060071a78be79e4be3049fdeb6c29d1
|
|
| BLAKE2b-256 |
7c866463091a23968af4a8fb130db348aaed4c770cc45cc1661891e7e71343b8
|
Provenance
The following attestation bundles were made for gemmology_crystal_renderer-1.0.0.tar.gz:
Publisher:
pypi-publish.yml on gemmology-dev/crystal-renderer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gemmology_crystal_renderer-1.0.0.tar.gz -
Subject digest:
863ba539d7789626979aa6fcd226d2ae53da2f4b6d6bb1f897fab830e97a8174 - Sigstore transparency entry: 841129805
- Sigstore integration time:
-
Permalink:
gemmology-dev/crystal-renderer@fd2ab273972a23938593e11cbd6546e83a2132ad -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/gemmology-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@fd2ab273972a23938593e11cbd6546e83a2132ad -
Trigger Event:
release
-
Statement type:
File details
Details for the file gemmology_crystal_renderer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gemmology_crystal_renderer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a879c01268b67c1a1719712913c3d8146718ac0f4d01db749cc9627adbce367
|
|
| MD5 |
06bfafd3fb20eb3572d45a4172181d14
|
|
| BLAKE2b-256 |
13e943681bdb728acaa88735704cc4568459a2221b4977a8e5748ace9c801771
|
Provenance
The following attestation bundles were made for gemmology_crystal_renderer-1.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on gemmology-dev/crystal-renderer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gemmology_crystal_renderer-1.0.0-py3-none-any.whl -
Subject digest:
9a879c01268b67c1a1719712913c3d8146718ac0f4d01db749cc9627adbce367 - Sigstore transparency entry: 841129824
- Sigstore integration time:
-
Permalink:
gemmology-dev/crystal-renderer@fd2ab273972a23938593e11cbd6546e83a2132ad -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/gemmology-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@fd2ab273972a23938593e11cbd6546e83a2132ad -
Trigger Event:
release
-
Statement type: