Skip to main content

3D crystal geometry engine for crystallographic visualization

Project description

Crystal Geometry

3D crystal geometry engine for crystallographic visualization. Computes polyhedra from Crystal Description Language (CDL) strings using half-space intersection with point group symmetry.

Part of the Gemmology Project.

Installation

pip install crystal-geometry

Quick Start

from crystal_geometry import cdl_string_to_geometry, create_octahedron

# Create geometry from CDL string
geom = cdl_string_to_geometry("cubic[m3m]:{111}@1.0 + {100}@1.3")
print(f"Vertices: {len(geom.vertices)}, Faces: {len(geom.faces)}")

# Use convenience constructors
octahedron = create_octahedron()
print(f"Octahedron has {len(octahedron.faces)} faces")

Features

  • CDL Integration: Parse Crystal Description Language strings to 3D geometry
  • Point Group Symmetry: All 32 crystallographic point groups supported
  • Half-Space Intersection: Robust geometry computation using scipy
  • 7 Crystal Systems: Cubic, tetragonal, orthorhombic, hexagonal, trigonal, monoclinic, triclinic
  • Miller Indices: Full support for 3-index (hkl) and 4-index (hkil) notation

Core API

Geometry Generation

from cdl_parser import parse_cdl
from crystal_geometry import cdl_to_geometry, cdl_string_to_geometry

# From CDL string directly
geom = cdl_string_to_geometry("cubic[m3m]:{111}")

# From parsed description (more control)
desc = parse_cdl("cubic[m3m]:{111}@1.0 + {100}@1.3")
geom = cdl_to_geometry(desc, c_ratio=1.0)

Convenience Constructors

from crystal_geometry import (
    create_octahedron,
    create_cube,
    create_dodecahedron,
    create_truncated_octahedron,
)

# Regular polyhedra
octahedron = create_octahedron(scale=1.0)
cube = create_cube(scale=1.0)
dodecahedron = create_dodecahedron(scale=1.0)
truncated = create_truncated_octahedron(octahedron_scale=1.0, cube_scale=1.3)

CrystalGeometry Class

from crystal_geometry import CrystalGeometry

geom = cdl_string_to_geometry("cubic[m3m]:{111}")

# Properties
geom.vertices      # Nx3 numpy array of vertex positions
geom.faces         # List of face vertex indices
geom.face_normals  # List of unit normal vectors
geom.face_forms    # Form index for each face
geom.face_millers  # Miller indices for each face

# Methods
geom.get_edges()           # Get unique edges as vertex pairs
geom.center()              # Compute centroid
geom.scale_to_unit()       # Scale to fit unit sphere
geom.translate(offset)     # Translate by vector
geom.euler_characteristic()  # V - E + F (should be 2)
geom.is_valid()            # Verify geometry integrity
geom.to_dict()             # Export to dictionary

Symmetry Operations

from crystal_geometry import (
    get_point_group_operations,
    generate_equivalent_faces,
    miller_to_normal,
    LatticeParams,
)

# Get symmetry operations for a point group
ops = get_point_group_operations('m3m')  # 48 operations
ops = get_point_group_operations('6/mmm')  # 24 operations

# Generate equivalent faces from one Miller index
faces = generate_equivalent_faces(1, 1, 1, 'm3m')  # 8 faces for {111}
faces = generate_equivalent_faces(1, 0, 0, 'm3m')  # 6 faces for {100}

# Convert Miller indices to normal vector
lattice = LatticeParams.cubic()
normal = miller_to_normal(1, 1, 1, lattice)

# Create lattice parameters
cubic = LatticeParams.cubic()
tetragonal = LatticeParams.tetragonal(c_ratio=1.5)
hexagonal = LatticeParams.hexagonal(c_ratio=1.2)

Crystal Systems and Point Groups

System Point Groups
Cubic m3m, 432, -43m, m-3, 23
Tetragonal 4/mmm, 422, 4mm, -42m, 4/m, -4, 4
Hexagonal 6/mmm, 622, 6mm, -6m2, 6/m, -6, 6
Trigonal -3m, 32, 3m, -3, 3
Orthorhombic mmm, 222, mm2
Monoclinic 2/m, 2, m
Triclinic -1, 1

Examples

Diamond-like Crystal

# Octahedron truncated by cube
geom = cdl_string_to_geometry("cubic[m3m]:{111}@1.0 + {100}@1.3")
assert len(geom.faces) == 14  # 8 octahedron + 6 cube

Garnet-like Crystal

# Dodecahedron with trapezohedron
geom = cdl_string_to_geometry("cubic[m3m]:{110}@1.0 + {211}@0.6")

Hexagonal Prism

# Prism with pinacoid termination
geom = cdl_string_to_geometry("hexagonal[6/mmm]:{10-10}@1.0 + {0001}@0.5")

Quartz-like Crystal

# Prism with rhombohedron
geom = cdl_string_to_geometry("trigonal[-3m]:{10-10}@1.0 + {10-11}@0.8")

Requirements

  • Python >= 3.10
  • numpy >= 1.20.0
  • scipy >= 1.7.0
  • cdl-parser >= 1.0.0

Documentation

See crystal-geometry.gemmology.dev for full documentation.

License

MIT License - see LICENSE for details.

Related Packages

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemmology_crystal_geometry-1.0.2.tar.gz (74.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gemmology_crystal_geometry-1.0.2-cp313-cp313-macosx_11_0_arm64.whl (128.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gemmology_crystal_geometry-1.0.2-cp312-cp312-macosx_11_0_arm64.whl (128.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gemmology_crystal_geometry-1.0.2-cp311-cp311-macosx_11_0_arm64.whl (128.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gemmology_crystal_geometry-1.0.2-cp310-cp310-macosx_11_0_arm64.whl (127.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file gemmology_crystal_geometry-1.0.2.tar.gz.

File metadata

File hashes

Hashes for gemmology_crystal_geometry-1.0.2.tar.gz
Algorithm Hash digest
SHA256 eb45469a2b57438f3a5339acc89e44d2c01311c5a26655c8ee0f3eb7181fa56d
MD5 e5e3f8dde0ad6f14975a5d2cee3d6a26
BLAKE2b-256 68ba49a5834a0bdd4fb5bd7f23bc82c5e51c1125aa856fbaa2fc0455df3af172

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemmology_crystal_geometry-1.0.2.tar.gz:

Publisher: pypi-publish.yml on gemmology-dev/crystal-geometry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gemmology_crystal_geometry-1.0.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gemmology_crystal_geometry-1.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43427ed7b9d72294ddb3afd26d2c640996b6c366c4b7f3f2759c91e7a89a08fd
MD5 4db72cdb2c0e61697b5f5aa647c39e57
BLAKE2b-256 27f263d04f51d6821c5ad4f7621f48b854f047df9631a8f434231fcbf5701231

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemmology_crystal_geometry-1.0.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on gemmology-dev/crystal-geometry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gemmology_crystal_geometry-1.0.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gemmology_crystal_geometry-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72d0f99def24b39b1ab032a3bd3a70146882131d6003b363cab5aba79f42eb02
MD5 6ede3ccd333a978cc15bb8f960972247
BLAKE2b-256 8e0b8c5640bdfc9cdadc1acce89e5a7eee804d0741d146397982f2a5ceadd45d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemmology_crystal_geometry-1.0.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on gemmology-dev/crystal-geometry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gemmology_crystal_geometry-1.0.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gemmology_crystal_geometry-1.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a406c149e21cbe11c7f344022d4cf0549765d1a97de02cb46a6e0d2370a64088
MD5 8c18662051d1a65f46606aa22403f3ac
BLAKE2b-256 f38acae92473701dcc9e863163c2a2ab38636e37745fb6837cd7b4c2d7b0d3cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemmology_crystal_geometry-1.0.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on gemmology-dev/crystal-geometry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gemmology_crystal_geometry-1.0.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gemmology_crystal_geometry-1.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cb70868c6f1e7aaf80688b463bdf6eae826e7a4a4d938b622d77daffae0045a
MD5 a9b31eecdbf6dcfb4f375376357b06a7
BLAKE2b-256 77cb13a0032cc1ba821d643ee2b762ad455e24251904f18550560c75d61ed037

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemmology_crystal_geometry-1.0.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on gemmology-dev/crystal-geometry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page