|
| 1 | +# API Reference |
| 2 | + |
| 3 | +## Core Functions |
| 4 | + |
| 5 | +### parse_cdl |
| 6 | + |
| 7 | +Parse a CDL string into a structured description. |
| 8 | + |
| 9 | +```python |
| 10 | +from cdl_parser import parse_cdl |
| 11 | + |
| 12 | +desc = parse_cdl("cubic[m3m]:{111}@1.0 + {100}@1.3") |
| 13 | +``` |
| 14 | + |
| 15 | +::: cdl_parser.parse_cdl |
| 16 | + |
| 17 | +### validate_cdl |
| 18 | + |
| 19 | +Validate a CDL string without parsing. |
| 20 | + |
| 21 | +```python |
| 22 | +from cdl_parser import validate_cdl |
| 23 | + |
| 24 | +is_valid, error = validate_cdl("cubic[m3m]:{111}") |
| 25 | +if not is_valid: |
| 26 | + print(f"Error: {error}") |
| 27 | +``` |
| 28 | + |
| 29 | +::: cdl_parser.validate_cdl |
| 30 | + |
| 31 | +## Data Classes |
| 32 | + |
| 33 | +### CrystalDescription |
| 34 | + |
| 35 | +Main output of CDL parsing. |
| 36 | + |
| 37 | +```python |
| 38 | +@dataclass |
| 39 | +class CrystalDescription: |
| 40 | + system: str # Crystal system |
| 41 | + point_group: str # Point group symbol |
| 42 | + forms: List[CrystalForm] # Crystal forms |
| 43 | + modifications: List[Modification] # Morphological mods |
| 44 | + twin: Optional[TwinSpec] # Twin specification |
| 45 | +``` |
| 46 | + |
| 47 | +::: cdl_parser.CrystalDescription |
| 48 | + |
| 49 | +### MillerIndex |
| 50 | + |
| 51 | +Miller index representation. |
| 52 | + |
| 53 | +```python |
| 54 | +@dataclass |
| 55 | +class MillerIndex: |
| 56 | + h: int |
| 57 | + k: int |
| 58 | + l: int |
| 59 | + i: Optional[int] = None # For 4-index notation |
| 60 | + |
| 61 | + def as_tuple(self) -> tuple[int, ...] |
| 62 | + def as_3index(self) -> tuple[int, int, int] |
| 63 | +``` |
| 64 | + |
| 65 | +::: cdl_parser.MillerIndex |
| 66 | + |
| 67 | +### CrystalForm |
| 68 | + |
| 69 | +A crystal form with scale. |
| 70 | + |
| 71 | +```python |
| 72 | +@dataclass |
| 73 | +class CrystalForm: |
| 74 | + miller: MillerIndex |
| 75 | + scale: float = 1.0 |
| 76 | + name: Optional[str] = None |
| 77 | +``` |
| 78 | + |
| 79 | +::: cdl_parser.CrystalForm |
| 80 | + |
| 81 | +## Constants |
| 82 | + |
| 83 | +```python |
| 84 | +from cdl_parser import ( |
| 85 | + CRYSTAL_SYSTEMS, # Set of system names |
| 86 | + POINT_GROUPS, # Dict[system, Set[groups]] |
| 87 | + DEFAULT_POINT_GROUPS, # Dict[system, default_group] |
| 88 | + NAMED_FORMS, # Dict[name, (h, k, l)] |
| 89 | + TWIN_LAWS, # Set of twin law names |
| 90 | +) |
| 91 | +``` |
| 92 | + |
| 93 | +### CRYSTAL_SYSTEMS |
| 94 | + |
| 95 | +Set of valid crystal system names: |
| 96 | + |
| 97 | +- `cubic` |
| 98 | +- `tetragonal` |
| 99 | +- `orthorhombic` |
| 100 | +- `hexagonal` |
| 101 | +- `trigonal` |
| 102 | +- `monoclinic` |
| 103 | +- `triclinic` |
| 104 | + |
| 105 | +### POINT_GROUPS |
| 106 | + |
| 107 | +Dictionary mapping each crystal system to its valid point groups. |
| 108 | + |
| 109 | +### DEFAULT_POINT_GROUPS |
| 110 | + |
| 111 | +Dictionary mapping each crystal system to its default (highest symmetry) point group. |
| 112 | + |
| 113 | +### NAMED_FORMS |
| 114 | + |
| 115 | +Dictionary mapping common form names to their Miller indices: |
| 116 | + |
| 117 | +| Name | Miller Index | |
| 118 | +|------|-------------| |
| 119 | +| `octahedron` | {111} | |
| 120 | +| `cube` | {100} | |
| 121 | +| `dodecahedron` | {110} | |
| 122 | +| `trapezohedron` | {211} | |
| 123 | +| `prism` | {10-10} | |
| 124 | +| `basal` | {0001} | |
| 125 | +| `rhombohedron` | {10-11} | |
| 126 | + |
| 127 | +### TWIN_LAWS |
| 128 | + |
| 129 | +Set of recognized twin law names: |
| 130 | + |
| 131 | +- `spinel` - Spinel law (111) twin |
| 132 | +- `brazil` - Brazil law quartz twin |
| 133 | +- `japan` - Japan law quartz twin |
| 134 | +- `fluorite` - Fluorite interpenetration twin |
| 135 | +- `iron_cross` - Iron cross pyrite twin |
| 136 | + |
| 137 | +## Exceptions |
| 138 | + |
| 139 | +### ParseError |
| 140 | + |
| 141 | +Raised when parsing fails due to syntax errors. |
| 142 | + |
| 143 | +```python |
| 144 | +from cdl_parser import ParseError |
| 145 | + |
| 146 | +try: |
| 147 | + desc = parse_cdl("invalid{{{") |
| 148 | +except ParseError as e: |
| 149 | + print(f"Syntax error at position {e.position}: {e.message}") |
| 150 | +``` |
| 151 | + |
| 152 | +::: cdl_parser.ParseError |
| 153 | + |
| 154 | +### ValidationError |
| 155 | + |
| 156 | +Raised when validation fails due to invalid values. |
| 157 | + |
| 158 | +```python |
| 159 | +from cdl_parser import ValidationError |
| 160 | + |
| 161 | +try: |
| 162 | + desc = parse_cdl("invalid[xxx]:{111}") |
| 163 | +except ValidationError as e: |
| 164 | + print(f"Validation error: {e.message}") |
| 165 | +``` |
| 166 | + |
| 167 | +::: cdl_parser.ValidationError |
0 commit comments