aims
FHI-aims format readers and writers.
This module handles FHI-aims geometry.in, control.in, and aims.out files for crystals and molecules.
AimsOutput
dataclass
Parser for FHI-aims output files (aims.out).
This class parses FHI-aims output files and extracts key information including energies, forces, and optimization trajectories.
Attributes:
| Name | Type | Description |
|---|---|---|
filename |
str | None
|
Path to the aims.out file |
converged |
bool
|
Whether a geometry optimization converged (always False for
single points; kept for compatibility, prefer |
geometry_converged |
Same as |
|
finished_normally |
bool
|
Whether aims reached its normal end ("Have a nice day") |
scf_converged |
bool | None
|
Whether the last SCF cycle converged (None if no SCF status was printed) |
is_optimization |
bool
|
Whether this was a geometry optimization |
is_periodic |
bool
|
Whether this is a periodic calculation |
final_energy |
float | None
|
Final total energy (uncorrected) in eV |
total_energy_corrected |
float | None
|
Final corrected total energy in eV (meaningful for periodic metals with smearing) |
free_energy |
float | None
|
Final electronic free energy in eV |
forces |
ndarray | None
|
(n, 3) array of the last total atomic forces in eV/Angstrom (in QM/MM runs n includes pseudocores that aims adds to the QM region) |
stress |
ndarray | None
|
(3, 3) array of the last stress tensor (analytical symmetrized or numerical) in eV/Angstrom^3 |
n_atoms |
int
|
Number of atoms |
n_steps |
int
|
Number of optimization steps (0 for single-point) |
steps |
list
|
List of OptimizationStep objects for optimization runs |
final_structure |
OptimizationStep | None
|
The final atomic structure (OptimizationStep) |
Examples:
>>> output = AimsOutput.from_file("aims.out")
>>> print(f"Final energy: {output.final_energy:.6f} eV")
>>> if output.is_optimization:
... print(f"Converged in {output.n_steps} steps")
... for step in output.steps:
... print(f" Step {step.step_number}: E = {step.energy:.6f} eV")
>>> final_mol = output.final_structure.to_molecule()
Source code in chmpy/fmt/aims.py
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 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 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 | |
geometry_converged
property
Whether a geometry optimization converged (same as converged).
from_file(filename)
classmethod
Parse an FHI-aims output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Path to the aims.out file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AimsOutput |
Parsed output data |
Source code in chmpy/fmt/aims.py
from_string(contents, filename=None)
classmethod
Parse FHI-aims output from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
str
|
Contents of the aims.out file |
required |
filename
|
str
|
Original filename for reference |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AimsOutput |
Parsed output data |
Source code in chmpy/fmt/aims.py
get_energies()
Get all energies from the optimization trajectory.
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Array of energies in eV for each step |
Source code in chmpy/fmt/aims.py
get_max_forces()
Get maximum force components from the optimization trajectory.
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Array of max force components in eV/Angstrom |
Source code in chmpy/fmt/aims.py
get_trajectory()
Get the optimization trajectory as a list of Molecule or Crystal objects.
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of Molecule or Crystal objects for each optimization step |
Source code in chmpy/fmt/aims.py
to_xyz_trajectory(filename)
Write the optimization trajectory to an XYZ file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Output XYZ file path |
required |
Source code in chmpy/fmt/aims.py
OptimizationStep
dataclass
Data from a single geometry optimization step.
Attributes:
| Name | Type | Description |
|---|---|---|
step_number |
int
|
The optimization step number (0 = initial) |
energy |
float
|
Total energy in eV |
max_force |
float | None
|
Maximum force component in eV/Angstrom |
forces_on_atoms |
float | None
|
Norm of forces on atoms in eV/Angstrom |
forces_on_lattice |
float | None
|
Norm of forces on lattice vectors in eV/Angstrom^3 (if periodic) |
lattice |
ndarray | None
|
(3, 3) array of lattice vectors in Angstrom (if periodic) |
elements |
list | None
|
List of Element objects |
positions |
ndarray | None
|
(N, 3) array of atomic positions in Angstrom (Cartesian) |
Source code in chmpy/fmt/aims.py
to_crystal()
Convert this step to a Crystal object.
Source code in chmpy/fmt/aims.py
to_molecule()
Convert this step to a Molecule object.
crystal_to_geometry_string(crystal, use_cartesian=False)
Convert a Crystal object to an FHI-aims geometry.in string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal
|
Crystal object to convert |
required | |
use_cartesian
|
bool
|
If True, write atom positions in Cartesian coordinates. If False (default), use fractional coordinates. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
FHI-aims geometry.in format string |
Examples:
>>> from chmpy import Crystal
>>> crystal = Crystal.load("structure.cif")
>>> geom_str = crystal_to_geometry_string(crystal)
Source code in chmpy/fmt/aims.py
generate_control_in(crystal_or_molecule, species_defaults_dir, basis='light', xc='pbe', k_grid=None, relax_geometry=False, relax_unit_cell=False, output_options=None, extra_keywords=None)
Generate an FHI-aims control.in file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crystal_or_molecule
|
Crystal or Molecule object |
required | |
species_defaults_dir
|
str or Path
|
Path to species_defaults directory (e.g., "~/src/FHIaims-250822/species_defaults") |
required |
basis
|
str
|
Basis set tier (default: "light") Options: "light", "lightdense", "intermediate", "tight", "really_tight", etc. |
'light'
|
xc
|
str
|
Exchange-correlation functional (default: "pbe") Common options: "pbe", "pbe0", "b86bpbe-25", "hse06", etc. |
'pbe'
|
k_grid
|
tuple or list
|
k-point grid for periodic systems (e.g., (4, 4, 4)) If None, will use defaults based on system size |
None
|
relax_geometry
|
bool or dict
|
Enable geometry relaxation If True, uses default settings. If dict, can specify method and convergence |
False
|
relax_unit_cell
|
bool or str
|
Enable unit cell relaxation If True, uses "full". Can also be "shape" or specific constraints |
False
|
output_options
|
list
|
List of output keywords (e.g., ["hirshfeld", "mulliken"]) |
None
|
extra_keywords
|
dict
|
Additional control.in keywords as key-value pairs |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
FHI-aims control.in format string |
Examples:
>>> from chmpy import Crystal
>>> crystal = Crystal.load("structure.cif")
>>> control_str = generate_control_in(
... crystal,
... species_defaults_dir="~/src/FHIaims-250822/species_defaults",
... basis="light",
... xc="pbe",
... k_grid=(4, 4, 4),
... relax_geometry=True,
... relax_unit_cell="full"
... )
Source code in chmpy/fmt/aims.py
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 | |
geometry_file_to_crystal(filename)
Load a Crystal from an FHI-aims geometry.in file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Path to the geometry.in file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Crystal |
A new Crystal object |
Source code in chmpy/fmt/aims.py
geometry_file_to_molecule(filename)
Load a Molecule from an FHI-aims geometry.in file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Path to the geometry.in file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Molecule |
A new Molecule object |
Source code in chmpy/fmt/aims.py
geometry_string_to_crystal(contents)
Convert an FHI-aims geometry.in string to a Crystal object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
str
|
Contents of the geometry.in file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Crystal |
A new Crystal object |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the geometry does not contain lattice vectors |
Examples:
>>> from pathlib import Path
>>> geom_str = Path("geometry.in").read_text()
>>> crystal = geometry_string_to_crystal(geom_str)
Source code in chmpy/fmt/aims.py
geometry_string_to_molecule(contents)
Convert an FHI-aims geometry.in string to a Molecule object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
str
|
Contents of the geometry.in file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Molecule |
A new Molecule object |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the geometry contains lattice vectors (use geometry_string_to_crystal instead) |
Examples:
>>> from pathlib import Path
>>> geom_str = Path("geometry.in").read_text()
>>> mol = geometry_string_to_molecule(geom_str)
Source code in chmpy/fmt/aims.py
molecule_to_geometry_string(molecule)
Convert a Molecule object to an FHI-aims geometry.in string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
molecule
|
Molecule object to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
FHI-aims geometry.in format string (no lattice vectors for molecules) |
Examples:
>>> from chmpy import Molecule
>>> mol = Molecule.load("water.xyz")
>>> geom_str = molecule_to_geometry_string(mol)
Source code in chmpy/fmt/aims.py
parse_geometry_string(contents)
Parse an FHI-aims geometry.in file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
str
|
Contents of the geometry.in file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary containing: - lattice: (3, 3) array of lattice vectors (if periodic) - elements: List of Element objects - positions: (N, 3) array of atomic positions - fractional: bool indicating if positions are fractional |
Examples:
>>> from pathlib import Path
>>> geom_str = Path("geometry.in").read_text()
>>> data = parse_geometry_string(geom_str)
Source code in chmpy/fmt/aims.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 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 | |
to_geometry_string(obj, **kwargs)
Convert a Crystal or Molecule object to FHI-aims geometry.in format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Crystal or Molecule object |
required | |
**kwargs
|
Additional keyword arguments passed to the appropriate conversion function |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
FHI-aims geometry.in format string |