API Documentation🔗
Text representation🔗
Core class🔗
Generate text representations of crystal structure for Language modelling.
Attributes:
| Name | Type | Description |
|---|---|---|
structure |
pymatgen structure |
|
transformations |
list of transformations to apply |
Methods:
| Name | Description |
|---|---|
from_input |
classmethod to create TextRep from various inputs |
get_available_representations |
get list of available representation types |
get_cif_string |
generate CIF string representation |
get_lattice_parameters |
get lattice parameters |
get_coords |
get atomic coordinates |
get_slices |
get SLICES representation |
get_composition |
get composition |
get_local_env_rep |
get local environment representation |
get_crystal_text_llm |
get Crystal-LLM representation |
get_robocrys_rep |
get Robocrystallographer representation |
get_wyckoff_positions |
get Wyckoff positions |
get_wycryst |
get Wycryst representation |
get_atom_sequences_plusplus |
get atom sequences |
get_zmatrix_rep |
get Z-matrix representation |
get_all_text_reps |
get all available representations |
get_requested_text_reps |
get specific representation(s) |
Source code in xtal2txt/core.py
36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 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 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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
backend
property
🔗
Lazy-load SLICES backend as versions keep changing.
__init__(structure, transformations=None, enable_logging=False)
🔗
Initialize TextRep instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
Pymatgen Structure object. |
required |
transformations
|
list[tuple[str, dict]]
|
list of (transformation_name, params) tuples to apply. |
None
|
enable_logging
|
bool
|
Whether to log errors when representations fail. |
False
|
Source code in xtal2txt/core.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
apply_transformations()
🔗
Apply transformations to the structure.
Source code in xtal2txt/core.py
184 185 186 187 188 189 190 | |
from_input(input_data, transformations=None, enable_logging=False)
classmethod
🔗
Instantiate the TextRep class object with the pymatgen structure from a cif file, a cif string, or a pymatgen Structure object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
Union[str, Path, Structure]
|
A cif file of a crystal structure, a cif string, or a pymatgen Structure object. |
required |
transformations
|
list[tuple[str, dict]]
|
list of transformations to apply. |
None
|
enable_logging
|
bool
|
Whether to log errors when representations fail. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
TextRep |
TextRep
|
A TextRep object. |
Source code in xtal2txt/core.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
get_all_text_reps(decimal_places=2, include_none=False)
🔗
Returns all the Text representations of the crystal structure in a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimal_places
|
int
|
Number of decimal places to round to. |
2
|
include_none
|
bool
|
Whether to include None values for unimplemented representations. |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, Optional[str]]
|
dictionary mapping representation names to their values. |
Source code in xtal2txt/core.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
get_atom_sequences_plusplus(lattice_params=False, decimal_places=1)
🔗
Generating a string with the elements of composition inside the crystal lattice with the option to get the lattice parameters as angles (int) and lengths (float) in a string with a space between them
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lattice_params
|
bool
|
Whether to include lattice parameters or not. |
False
|
decimal_places
|
int
|
The number of decimal places to round to. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the crystal structure. |
Source code in xtal2txt/core.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
get_available_representations()
classmethod
🔗
Get list of available representation types.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: list of representation type names. |
Source code in xtal2txt/core.py
138 139 140 141 142 143 144 145 146 | |
get_cif_string(format='symmetrized', decimal_places=3)
🔗
Generate CIF as string in multi-line format.
All float numbers can be rounded to the specified number (decimal_places). Currently supports two formats. Symmetrized (cif with symmetry operations and the least symmetric basis) ... and P1 (conventional unit cell , with all the atoms listed and only identity as symmetry operation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
The format of the CIF file. Can be "symmetrized" or "p1". |
'symmetrized'
|
decimal_places
|
int
|
The number of decimal places to round to. |
3
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The CIF string. |
Source code in xtal2txt/core.py
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 | |
get_composition(format='hill')
🔗
Return composition in hill format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
format in which the composition is required. |
'hill'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The composition in hill format. |
Source code in xtal2txt/core.py
330 331 332 333 334 335 336 337 338 339 340 341 342 | |
get_coords(name='cartesian', decimal_places=3)
🔗
Return list of atoms in unit cell for with their positions in Cartesian or fractional coordinates as per choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the coordinates. Can be "cartesian" or "fractional". |
'cartesian'
|
decimal_places
|
int
|
The number of decimal places to round to. |
3
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The list of atoms with their positions. |
Source code in xtal2txt/core.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
get_crystal_text_llm(permute_atoms=False)
🔗
Code adopted from https://github.com/facebookresearch/crystal-llm/blob/main/llama_finetune.py https://openreview.net/pdf?id=0r5DE2ZSwJ
Returns the representation as per the above citation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permute_atoms
|
bool
|
Whether to permute the atoms in the unit cell. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The crystal-llm representation of the crystal structure. |
Source code in xtal2txt/core.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
get_lattice_parameters(decimal_places=3)
🔗
Return lattice parameters of unit cells in a crystal lattice: the lengths of the cell edges (a, b, and c) in angstrom and the angles between them (alpha, beta, and gamma) in degrees.
All float numbers can be rounded to a specific number (decimal_places).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimal_places
|
int
|
The number of decimal places to round to. |
3
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The lattice parameters. |
Source code in xtal2txt/core.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
get_local_env_rep(local_env_kwargs=None)
🔗
Get the local environment representation of the crystal structure.
The local environment representation is a string that contains the space group symbol and the local environment of each atom in the unit cell. The local environment of each atom is represented as SMILES string and the Wyckoff symbol of the local environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_env_kwargs
|
dict
|
Keyword arguments to pass to the LocalEnvAnalyzer. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The local environment representation of the crystal structure. |
Source code in xtal2txt/core.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
get_requested_text_reps(requested_reps, decimal_places=2, strict=False)
🔗
Returns the requested Text representation(s) of the crystal structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested_reps
|
Union[str, List[str]]
|
A single representation name or an iterable of names to generate.
Accepts strings, lists, tuples, or any iterable of |
required |
decimal_places
|
int
|
Number of decimal places to round to. |
2
|
strict
|
bool
|
If True, raise |
False
|
Returns:
| Type | Description |
|---|---|
Union[Optional[str], Dict[str, Optional[str]]]
|
If requested_reps is a string: the representation value (or None if failed). |
Union[Optional[str], Dict[str, Optional[str]]]
|
If requested_reps is a list/iterable: dictionary mapping names to values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If strict=True and an unknown representation is requested. |
Source code in xtal2txt/core.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
get_robocrys_rep()
🔗
Source code in xtal2txt/core.py
406 407 408 409 410 411 412 | |
get_slices(primitive=True)
🔗
Returns SLICES representation of the crystal structure. https://www.nature.com/articles/s41467-023-42870-7
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitive
|
bool
|
Whether to use the primitive structure or not. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The SLICE representation of the crystal structure. |
Source code in xtal2txt/core.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
get_wyckoff_positions()
🔗
Getting wyckoff positions of the elements in the unit cell as the combination of... number and letter.
Returns:
| Name | Type | Description |
|---|---|---|
str |
A multi-line string that contain elements of the unit cell along with their wyckoff position in each line. |
Hint
At the end of the string, there is an additional newline character.
Source code in xtal2txt/core.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
get_wycryst()
🔗
Obtaining the wyckoff representation for crystal structures that include
chemical formula space group number elements of the unit cell with their wyckoff positions.
Returns:
| Name | Type | Description |
|---|---|---|
str |
A multi-line string that contains the chemical formula, space group number, and the elements of the unit cell with their wyckoff positions. |
Source code in xtal2txt/core.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
get_zmatrix_rep(decimal_places=1)
🔗
Generate the Z-matrix representation of the crystal structure. It provides a description of each atom in terms of its atomic number, bond length, bond angle, and dihedral angle, the so-called internal coordinates.
Disclaimer: The Z-matrix is meant for molecules, current implementation converts atoms within unit cell to molecule. Hence the current implentation might overlook bonds acrosse unit cells.
Source code in xtal2txt/core.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
round_numbers_in_string(original_string, decimal_places)
staticmethod
🔗
Rounds float numbers in the given string to the specified number of decimal places using regex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_string
|
str
|
The input string. |
required |
decimal_places
|
int
|
The number of decimal places to round to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string with the float numbers rounded to the specified number of decimal places. |
Source code in xtal2txt/core.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
updated_zmatrix_rep(zmatrix, decimal_places=1)
🔗
Replace the variables in the Z-matrix with their values and return the updated Z-matrix.
for eg: z-matrix from pymatgen
'N
N 1 B1 N 1 B2 2 A2 N 1 B3 2 A3 3 D3
B1=3.79
B2=6.54
....
is replaced to
'N
N 1 3.79 N 1 6.54 2 90 N 1 6.54 2 90 3 120 '
Args:
Zmatrix (bool): zmatrix multi line string as implemented in pymatgen.
decimal_places (int): The number of decimal places to round to.
Returns:
str: The updated Z-matrix representation of the crystal structure.
Source code in xtal2txt/core.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
Decoding🔗
DecodeTextRep
🔗
Source code in xtal2txt/decoder.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
cif_string_decoder_p1(input)
🔗
Returning a pymatgen structure out of a string format of a cif file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
str String to obtain the items needed for the structure. |
required |
Returns:
| Type | Description |
|---|---|
|
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
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 | |
cif_string_decoder_sym(input)
🔗
Returning a pymatgen structure out of a string format of a symmetrized cif file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
str String to obtain the items needed for the structure. |
required |
Returns:
| Type | Description |
|---|---|
|
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
llm_decoder(input)
🔗
Returning pymatgen structure out of multi-line representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
str String to obtain the items needed for the structure. |
required |
Returns:
| Type | Description |
|---|---|
|
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.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 98 99 100 101 102 103 104 | |
wyckoff_decoder(input, lattice_params=False)
🔗
Generating a pymatgen object from the output of the get_wyckoff_rep() method by using... pyxtal package. In this method, all data are extracted from the multi-line string of the... mentioned method. In pyxtal package, a 3D crystal is produced by specifying the dimensions, elements, composition of elements, space group, and sites as wyckoff positions of the elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lattice_params
|
bool
|
boolean To specify whether use lattice parameters in generating crystal structure. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
pmg_struc |
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 66 67 68 69 70 71 72 | |
MatchRep
🔗
Source code in xtal2txt/decoder.py
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 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 341 342 343 344 345 346 347 | |
cif_string_matcher_p1(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True)
🔗
To check if pymatgen object from the original cif file match with the generated pymatgen structure from cif_string_decoder_p1 method out of string cif representation using fit() method of StructureMatcher module in pymatgen package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str String to obtain the items needed for the structure. |
required | |
StructureMatcher module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StructureMatcher |
).fit(
|
bool |
Source code in xtal2txt/decoder.py
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 341 342 343 344 345 346 347 | |
cif_string_matcher_sym(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True)
🔗
To check if pymatgen object from the original cif file match with the generated pymatgen structure from cif_string_decoder_sym method out of string cif representation. using fit() method of StructureMatcher module in pymatgen package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str String to obtain the items needed for the structure. |
required | |
StructureMatcher module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StructureMatcher |
).fit(
|
bool |
Source code in xtal2txt/decoder.py
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 | |
llm_matcher(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True)
🔗
To check if pymatgen object from the original cif file match with the generated pymatgen structure from llm_decoder method out of llm representation using fit() method of StructureMatcher module in pymatgen package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str String to obtain the items needed for the structure. |
required | |
StructureMatcher module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StructureMatcher |
).fit(
|
bool |
Source code in xtal2txt/decoder.py
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 | |
wyckoff_matcher(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True, lattice_params=False)
🔗
To check if pymatgen object from the original cif file match with the generated... pymatgen structure from wyckoff_decoder method out of wyckoff representation... using fit() method of StructureMatcher module in pymatgen package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
StructureMatcher module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required | |
lattice_params
|
bool
|
bool To specify using lattice parameters in the wyckoff_decoder method. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
StructureMatcher |
).fit_anonymous(
|
bool |
Source code in xtal2txt/decoder.py
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 | |
Transformations🔗
Tokenizer🔗
CifTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
578 579 580 581 582 583 584 585 586 587 | |
CompositionTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
545 546 547 548 549 550 551 552 553 554 | |
CrysllmTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
611 612 613 614 615 616 617 618 619 620 | |
NumTokenizer
🔗
Tokenize numbers as implemented in Regression Transformer. https://www.nature.com/articles/s42256-023-00639-z https://github.com/IBM/regression-transformer/tree/main
Source code in xtal2txt/tokenizer.py
82 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 164 165 | |
__init__()
🔗
Tokenizer for numbers.
Source code in xtal2txt/tokenizer.py
87 88 89 | |
convert_tokens_to_float(tokens)
staticmethod
🔗
Converts tokens representing a float value into a float. NOTE: Expects that non-floating tokens are strippped off
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
List[str]
|
List of tokens, each representing a float. E.g.: ['0_0', '.', '9-1_', '3-2_', '1-3_'] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Float representation for the list of tokens. |
Source code in xtal2txt/tokenizer.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
convert_tokens_to_string(tokens)
🔗
Converts tokens to string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
List[str]
|
List of tokens. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String representation of the tokens. |
Source code in xtal2txt/tokenizer.py
156 157 158 159 160 161 162 163 164 165 | |
num_matcher(text)
🔗
Extract numbers from a sentence and replace them with tokens.
Source code in xtal2txt/tokenizer.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
tokenize(text)
🔗
Tokenization of numbers as in RT. '0.9' -> '0_0', '.', '9-1_'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
number as string to be tokenized. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
extracted tokens. |
Source code in xtal2txt/tokenizer.py
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 | |
RobocrysTokenizer
🔗
Tokenizer for Robocrystallographer. Would be BPE tokenizer. trained on the Robocrystallographer dataset.
Source code in xtal2txt/tokenizer.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
model_max_length
property
writable
🔗
Get the model maximum length.
vocab_size
property
🔗
Return the vocabulary size.
__call__(*args, **kwargs)
🔗
Make the tokenizer callable.
Source code in xtal2txt/tokenizer.py
689 690 691 | |
__getattr__(name)
🔗
Delegate attribute access to the wrapped tokenizer.
Source code in xtal2txt/tokenizer.py
712 713 714 | |
__len__()
🔗
Return the vocabulary size.
Source code in xtal2txt/tokenizer.py
693 694 695 | |
SliceTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
convert_tokens_to_string(tokens)
🔗
Converts tokens to string.
Source code in xtal2txt/tokenizer.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
512 513 514 515 516 517 518 519 520 521 | |
Models🔗
FinetuneLLamaSFT
🔗
Class to perform finetuning of a language model. Initialize the FinetuneModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DictConfig
|
Configuration for the fine-tuning. |
required |
local_rank
|
int
|
Local rank for distributed training. Defaults to None. |
None
|
Source code in src/mattext/models/llama_sft.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 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 | |
finetune()
🔗
Perform fine-tuning of the language model.
Source code in src/mattext/models/llama_sft.py
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 | |
FinetuneLLama
🔗
Class to perform finetuning of LLama using a regression head.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DictConfig
|
Configuration for the fine-tuning. |
required |
local_rank
|
int
|
Local rank for distributed training. Defaults to None. |
None
|
Source code in src/mattext/models/llama.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 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 | |
evaluate()
🔗
Evaluate the fine-tuned model on the test dataset.
Source code in src/mattext/models/llama.py
267 268 269 | |
finetune()
🔗
Perform fine-tuning of the language model.
Source code in src/mattext/models/llama.py
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 | |
smart_tokenizer_and_embedding_resize(special_tokens_dict, llama_tokenizer, model)
🔗
Resize tokenizer and embedding.
Note: This is the unoptimized version that may make your embedding size not be divisible by 64.
Source code in src/mattext/models/llama.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
PotentialModel
🔗
Bases: TokenizerMixin
Class to perform finetuning of a language model on the hypothetical potential task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DictConfig
|
Configuration for the fine-tuning. |
required |
local_rank
|
int
|
Local rank for distributed training. Defaults to None. |
None
|
Source code in src/mattext/models/potential.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 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 | |
evaluate()
🔗
Evaluate the fine-tuned model on the test dataset.
Source code in src/mattext/models/potential.py
188 189 190 | |
finetune()
🔗
Perform fine-tuning of the language model.
Source code in src/mattext/models/potential.py
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
PretrainModel
🔗
Bases: TokenizerMixin
Class to perform pretraining of a language model.
Source code in src/mattext/models/pretrain.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 | |
pretrain_mlm()
🔗
Performs MLM pretraining of the language model.
Source code in src/mattext/models/pretrain.py
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 | |