Fingerprints¶
Inorganic Composition Fingerprints¶
matgpr.inorganic_fingerprints
¶
CompositionFingerprintResult
dataclass
¶
Result returned by composition featurization helpers.
Attributes:
| Name | Type | Description |
|---|---|---|
features |
DataFrame
|
Numeric composition descriptors indexed like the input formulas. |
failed |
DataFrame
|
Formulas that could not be parsed or featurized. Empty when
|
cache_keys |
Series | None
|
Deterministic cache keys for each input row. |
cache_hit |
Series | None
|
Boolean flags indicating whether each row was loaded from cache. |
Source code in matgpr/inorganic_fingerprints.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
clean_formula(formula)
¶
Normalize common text artifacts before parsing an inorganic formula.
Source code in matgpr/inorganic_fingerprints.py
80 81 82 83 84 | |
composition_fingerprint(formula, *, properties=DEFAULT_ELEMENTAL_PROPERTIES, statistics=DEFAULT_COMPOSITION_STATISTICS)
¶
Create statistical elemental-property descriptors for one composition.
The default descriptor set follows a compact materials-informatics pattern:
each elemental property is summarized by composition-weighted statistics
such as the fraction-weighted mean (fwm), absolute deviation (ad),
minimum, maximum, range, and standard deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
object
|
Inorganic composition string, for example |
required |
properties
|
Sequence[str]
|
Element-level properties to summarize. Supported defaults include atomic number, mass, electronegativity, radius, periodic-table row and column, and s/p/d/f valence counts. |
DEFAULT_ELEMENTAL_PROPERTIES
|
statistics
|
Sequence[str]
|
Summary statistics to compute for each property. |
DEFAULT_COMPOSITION_STATISTICS
|
Source code in matgpr/inorganic_fingerprints.py
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 | |
default_element_symbols(max_atomic_number=118)
¶
Return periodic-table element symbols up to max_atomic_number.
Source code in matgpr/inorganic_fingerprints.py
138 139 140 141 142 143 144 | |
element_fraction_fingerprint(formula, *, elements=None)
¶
Create a fixed-length elemental-fraction vector for one formula.
Each output feature is named element_fraction_<symbol>. If elements
is omitted, the vector spans all elements up to atomic number 118. Passing a
smaller element list is useful for project-specific models, but every
element present in formula must be included in that list.
Source code in matgpr/inorganic_fingerprints.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
featurize_element_fractions(formulas, *, elements=None, errors='raise', cache_dir=None)
¶
Featurize formulas as fixed element-fraction vectors.
Element-fraction vectors are the recommended inputs for
:class:matgpr.ElementFractionKernel. They preserve direct compositional
information, unlike statistical elemental-property descriptors.
Source code in matgpr/inorganic_fingerprints.py
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
featurize_compositions(formulas, *, properties=DEFAULT_ELEMENTAL_PROPERTIES, statistics=DEFAULT_COMPOSITION_STATISTICS, errors='raise', cache_dir=None)
¶
Featurize a sequence of inorganic formulas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formulas
|
Iterable[object]
|
Iterable of formula strings. |
required |
properties
|
Sequence[str]
|
Descriptor controls passed to |
DEFAULT_ELEMENTAL_PROPERTIES
|
statistics
|
Sequence[str]
|
Descriptor controls passed to |
DEFAULT_ELEMENTAL_PROPERTIES
|
errors
|
str
|
|
'raise'
|
cache_dir
|
str | Path | None
|
Optional directory for persistent row-level JSON cache files. Cache keys are deterministic hashes of the normalized formula and descriptor settings. |
None
|
Source code in matgpr/inorganic_fingerprints.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
append_composition_fingerprints(data, *, formula_column='composition', drop_formula_column=False, errors='raise', cache_dir=None)
¶
Append inorganic composition descriptors to a dataframe.
The returned dataframe preserves the original index and columns, then adds
descriptor columns produced by featurize_compositions.
Source code in matgpr/inorganic_fingerprints.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
append_element_fractions(data, *, formula_column='composition', elements=None, drop_formula_column=False, errors='raise', cache_dir=None)
¶
Append element-fraction columns to a dataframe.
Source code in matgpr/inorganic_fingerprints.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
Crystal Structure Fingerprints¶
matgpr.structure_fingerprints
¶
StructureFingerprintResult
dataclass
¶
Result returned by structure featurization helpers.
Attributes:
| Name | Type | Description |
|---|---|---|
features |
DataFrame
|
Numeric structure descriptors indexed like the input structures. |
failed |
DataFrame
|
Structures that could not be parsed or featurized. Empty when
|
cache_keys |
Series | None
|
Deterministic cache keys for each input row. |
cache_hit |
Series | None
|
Boolean flags indicating whether each row was loaded from cache. |
Source code in matgpr/structure_fingerprints.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
structure_fingerprint(structure, *, features=DEFAULT_STRUCTURE_FEATURES)
¶
Create lightweight global structure descriptors for one crystal structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
object
|
A |
required |
features
|
Sequence[str]
|
Descriptor names to return. Defaults are global lattice-shape and packing descriptors intended for small tabular GPR workflows. |
DEFAULT_STRUCTURE_FEATURES
|
Source code in matgpr/structure_fingerprints.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
featurize_structures(structures, *, features=DEFAULT_STRUCTURE_FEATURES, errors='raise', cache_dir=None)
¶
Featurize a sequence of crystal structures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
Iterable[object]
|
Iterable of |
required |
features
|
Sequence[str]
|
Descriptor names passed to |
DEFAULT_STRUCTURE_FEATURES
|
errors
|
str
|
|
'raise'
|
cache_dir
|
str | Path | None
|
Optional directory for persistent row-level JSON cache files. |
None
|
Source code in matgpr/structure_fingerprints.py
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 | |
append_structure_fingerprints(data, *, structure_column='structure', features=DEFAULT_STRUCTURE_FEATURES, drop_structure_column=False, errors='raise', cache_dir=None)
¶
Append lightweight structure descriptors to a dataframe.
Source code in matgpr/structure_fingerprints.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
structure_feature_names(features=DEFAULT_STRUCTURE_FEATURES, *, column_prefix=None)
¶
Return validated structure descriptor names with an optional prefix.
Source code in matgpr/structure_fingerprints.py
190 191 192 193 194 195 196 197 198 199 | |
Organic And Polymer Fingerprints¶
matgpr.organic_fingerprints
¶
SmilesFingerprintResult
dataclass
¶
Result returned by featurize_smiles.
Attributes:
| Name | Type | Description |
|---|---|---|
features |
DataFrame
|
Numeric fingerprint or descriptor features. |
canonical_smiles |
Series
|
Canonical SMILES used for fingerprinting. For polymers, this is the
canonicalized cyclic trimer surrogate built from the two |
failed |
DataFrame
|
Rows that could not be parsed or featurized. Empty when
|
cache_keys |
Series | None
|
Deterministic cache keys for each input row. |
cache_hit |
Series | None
|
Boolean flags indicating whether each row was loaded from cache. |
Source code in matgpr/organic_fingerprints.py
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 | |
canonicalize_molecule_smiles(smiles)
¶
Canonicalize a molecule SMILES string with RDKit.
Source code in matgpr/organic_fingerprints.py
68 69 70 71 | |
canonicalize_polymer_smiles(smiles, *, repeat_units=3, join_ends=True)
¶
Canonicalize a polymer repeat-unit SMILES string.
By default, polymer repeat units must contain exactly two dummy atoms
represented as [*]. The repeat unit is expanded to a trimer, neighboring
atoms at adjacent [*] ends are connected using the dummy-end bond order,
the trimer is closed into a loop, and the dummy atoms are removed before
RDKit canonicalization.
Source code in matgpr/organic_fingerprints.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
fingerprint_smiles(smiles, *, smiles_type='molecule', fingerprint_type='morgan', n_bits=1024, radius=2, descriptors=DEFAULT_RDKIT_DESCRIPTORS)
¶
Fingerprint one molecule or polymer SMILES string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smiles
|
object
|
Molecule SMILES, or polymer repeat-unit SMILES containing exactly two
|
required |
smiles_type
|
str
|
|
'molecule'
|
fingerprint_type
|
str
|
|
'morgan'
|
n_bits
|
int
|
Fingerprint length for Morgan and RDKit fingerprints. |
1024
|
radius
|
int
|
Morgan fingerprint radius. |
2
|
descriptors
|
Sequence[str]
|
RDKit descriptor names to include for descriptor-based features. |
DEFAULT_RDKIT_DESCRIPTORS
|
Source code in matgpr/organic_fingerprints.py
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 | |
featurize_smiles(smiles_values, *, smiles_type='molecule', fingerprint_type='morgan', n_bits=1024, radius=2, descriptors=DEFAULT_RDKIT_DESCRIPTORS, column_prefix=None, errors='raise', cache_dir=None)
¶
Featurize a sequence of molecule or polymer SMILES strings.
Source code in matgpr/organic_fingerprints.py
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
append_smiles_features(data, *, smiles_column, smiles_type='molecule', fingerprint_type='morgan', n_bits=1024, radius=2, descriptors=DEFAULT_RDKIT_DESCRIPTORS, column_prefix=None, errors='raise', include_canonical_smiles=True, cache_dir=None)
¶
Append RDKit features for a SMILES column to a dataframe.
Source code in matgpr/organic_fingerprints.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
Fingerprint Cache¶
matgpr.fingerprint_cache
¶
fingerprint_cache_key(*, namespace, value, parameters)
¶
Return a deterministic cache key for one fingerprint input.
The key is based on a versioned JSON payload containing the fingerprint namespace, the input value, and all featurization parameters. The same input and settings produce the same SHA-256 hash across Python sessions.
Source code in matgpr/fingerprint_cache.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
fingerprint_cache_path(cache_dir, *, namespace, cache_key)
¶
Return the JSON file path for a cache key.
Source code in matgpr/fingerprint_cache.py
47 48 49 50 51 52 53 54 | |
read_fingerprint_cache_record(cache_dir, *, namespace, cache_key)
¶
Read a cached fingerprint record, returning None for misses.
Source code in matgpr/fingerprint_cache.py
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 | |
write_fingerprint_cache_record(cache_dir, *, namespace, cache_key, record)
¶
Write one fingerprint cache record as JSON.
Writes are atomic within the cache directory: data are first written to a temporary sibling file, then moved into place.
Source code in matgpr/fingerprint_cache.py
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 | |