asaf.framework
Framework class for handling molecular periodic structures and generating simulation files.
Framework
Framework(
lattice: List[float, float, float, float, float, float]
| ArrayLike,
sites: List[str | int],
coordinates: ArrayLike,
lattice_as_matrix: bool = False,
site_types: Optional[List[str]] = None,
charges: Optional[List[float]] = None,
)
Bases: object
Represents a molecular periodic structure.
The basic components are the sequence of sites and the crystal lattice parameters. Additionally, it may store framework-specific and site-specific properties.
Parameters:
-
lattice(list or array - like) –Lattice parameters as a list of six floats representing the lengths (a, b, c) and angles (alpha, beta, gamma) of the unit cell or as a 3x3 matrix. If matrix is provided,
lattice_as_matrixshould be set to True. Note that asaf uses the row -> vector convention lattice matrix. -
sites(list) –Site labels or indices corresponding to the atomic numbers of the sites
-
coordinates(array - like) –2D array of shape (n_sites, 3) containing the fractional coordinates of the sites in the unit cell
-
lattice_as_matrix(bool, default:False) –If True,
latticeis treated as a 3x3 matrix representing the unit cell vectors. If False, it is treated as a list of six floats representing the lattice parameters (a, b, c, alpha, beta, gamma). -
site_types(list, default:None) –List of site types (element symbols) corresponding to each site. If None, site labels will be used to infer types by stripping numeric suffixes.
-
charges(list, default:None) –List of partial charges for each site. If None, all charges will be set to zero.
Source code in src/asaf/framework.py
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 | |
calculate_conversion_factors
Calculate the conversion factors for the isotherm recalculation.
Parameters:
-
adsorbate_molar_mass(float, default:None) –Molar mass of the adsorbate in g/mol. If provided, the g/g conversion factor will be calculated.
Returns:
-
dict–A dictionary containing the conversion factors: - 'molecules_uc__mol_kg': molecules/unit cell to mol/kg - 'molecules_uc__cm3_g': molecules/unit cell to cm3 (STP)/g - 'molecules_uc__cm3_cm3': molecules/unit cell to cm3 (STP)/cm3 - 'molecules_uc__g_g': molecules/unit cell to g/g (if adsorbate_molar_mass is provided)
Source code in src/asaf/framework.py
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 | |
calculate_framework_mass
calculate_framework_mass()
Calculate the molar mass of the framework.
Units: g / mol / unit cell
Source code in src/asaf/framework.py
290 291 292 293 294 295 296 297 298 299 300 301 | |
calculate_framework_unitcell_volume
calculate_framework_unitcell_volume()
Calculate the volume of the unit cell.
Units: Angstrom^3 / unit cell
Source code in src/asaf/framework.py
303 304 305 306 307 308 309 310 | |
check_net_charge
Return the total net charge of the replicated system (all UC).
Prints a warning if |net_charge| > 1e-5 e.
Parameters:
-
unit_cells(tuple) –how many times to replicate in (x, y, z).
Returns:
-
float–net charge in the full system (units of e).
Source code in src/asaf/framework.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
create_supercell
create_supercell(
unit_cells: tuple[int, int, int] = (1, 1, 1),
center: bool = True,
) -> tuple[
DataFrame, tuple[float, ...], tuple[Any, Any, Any]
]
Create a supercell by replicating the unit cell.
Parameters:
-
unit_cells(tuple[int, int, int], default:(1, 1, 1)) –Number of unit cells to replicate in (x, y, z) directions. Default is (1, 1, 1).
-
center(bool, default:True) –If True, center the coordinates in the box. Default is True.
Returns:
-
Tuple[DataFrame, Tuple[float, float, float, float, float, float], Tuple[ndarray, ndarray, ndarray]]–A tuple containing: - DataFrame with columns ['site_label', 'cartesian_x', 'cartesian_y', 'cartesian_z'] - Box parameters as a tuple (lx, ly, lz, xy, xz, yz) - Cell vectors as a tuple of three numpy arrays (a_vec, b_vec, c_vec)
Source code in src/asaf/framework.py
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 | |
create_system
Create a supercell system (wrapper around create_supercell for backward compatibility).
Source code in src/asaf/framework.py
603 604 605 | |
dl_poly_ewald
staticmethod
Calculate alpha and kmax parameters for Ewald summation.
Recipe from the DL_POLY Algorithm https://doi.org/10.1080/002689798167881 thanks to Daniel W. Siderius
Parameters:
-
cutoff(float) –real space cutoff in Angstroms
-
box(tuple) –box parameters (lx, ly, lz, xy, xz, yz)
-
tolerance(float, default:1e-05) –desired accuracy for the Ewald summation
Returns:
-
alpha(float) –Ewald splitting parameter in Angstroms^-1
-
kmax(list) –maximum k-vector components in each direction
Source code in src/asaf/framework.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
fractional_to_cartesian
Convert fractional coordinates to cartesian coordinates.
Parameters:
-
fractional_coords(NDArray) –Nx3 array of fractional coordinates
-
lattice(NDArray, default:None) –3x3 lattice matrix. If None, uses self._lattice
Returns:
-
Nx3 array of cartesian coordinates–
Source code in src/asaf/framework.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
from_cif
classmethod
from_cif(
cif_file: Path,
remove_site_labels: bool = False,
partial_charge_header: str = "_atom_site_charge",
) -> Framework
Read the CIF file and populate self._dataframe.
Parameters:
-
cif_file(Path) –Path to the CIF file.
-
remove_site_labels(bool, default:False) –If True, remove numeric suffixes from site labels to infer site types.
-
partial_charge_header(str, default:'_atom_site_charge') –CIF tag for partial charges. Default is '_atom_site_charge'.
Returns:
-
Framework–An instance of the Framework class populated with data from the CIF file.
Source code in src/asaf/framework.py
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 | |
group_sites_by_charge
group_sites_by_charge(
bond_tolerance: float = 0.15,
small_charge_threshold: float = 0.1,
relative_threshold: float = 0.15,
absolute_threshold: float = 0.05,
charge_bin_size: float = 0.01,
distance_bin_size: float = 0.2,
max_cutoff: float = 6.0,
)
Group atoms in a framework based on their chemical environment and assigns averaged charges to each group.
Updates both the site labels in the dataframe and the force field parameters.
Note: This function modifies site labels and charges in the dataframe, preserving original values in 'site_original_label' and 'site_original_charge' columns. It also updates the force field with averaged charges for each group.
Parameters:
-
bond_tolerance(float, default:0.15) –bond tolerance in percentage (e.g. 0.15 = 15%). Used in sum of covalent radii to determine if two atoms are bonded.
-
small_charge_threshold(float, default:0.1) –charges smaller than this value are considered small and use relative threshold for splitting
-
relative_threshold(float, default:0.15) –relative threshold for splitting groups with small charges
-
absolute_threshold(float, default:0.05) –absolute threshold for splitting groups with large charges
-
charge_bin_size(float, default:0.01) –size of the charge bin for grouping atoms
-
distance_bin_size(float, default:0.2) –size of the distance bin for fingerprinting atoms (in Angstroms)
-
max_cutoff(float, default:6.0) –maximum distance to consider for the supercell creation, should be larger than any potential bond (in Angstroms)
Returns:
-
dict–A dictionary mapping atom labels to their averaged charges
Source code in src/asaf/framework.py
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 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | |
lattice_parameters_to_matrix
staticmethod
lattice_parameters_to_matrix(
a: float,
b: float,
c: float,
alpha: float,
beta: float,
gamma: float,
) -> ArrayLike
Convert lattice parameters to a 3x3 matrix representation of the unit cell.
source: https://dx.doi.org/10.1080/08927022.2013.819102
( a b cos(gamma) c cos(beta) )
h = ( 0 b sin(gamma) c z ) ( 0 0 c sqrt(1-cos^2(beta)-z^2) )
z = (cos(alpha) - cos(gamma) cos(beta)) / sin(gamma)
Here lower triangular form is used, for row -> vector cell convention.
Parameters:
-
a(float) –lengths of the unit cell edges
-
b(float) –lengths of the unit cell edges
-
c(float) –lengths of the unit cell edges
-
alpha(float) –angles between the edges in degrees
-
beta(float) –angles between the edges in degrees
-
gamma(float) –angles between the edges in degrees
Returns:
-
ndarray–3x3 matrix representing the unit cell vectors, each row is a vector
Source code in src/asaf/framework.py
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 | |
matrix_to_lattice_parameters
staticmethod
matrix_to_lattice_parameters(
lattice: NDArray,
) -> Tuple[float, float, float, float, float, float]
Convert a 3x3 lattice matrix (row->vector convention) to lengths and angles.
Parameters:
-
lattice(NDArray) –3x3 matrix representing the unit cell vectors, each row is a vector
Returns:
-
Tuple[float, float, float, float, float, float]–Lattice parameters as (a, b, c, alpha, beta, gamma), where lengths are in Angstroms and angles in degrees. Angles are defined as: - alpha=angle(b,c) - beta=angle(a,c) - gamma=angle(a,b)
Source code in src/asaf/framework.py
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 | |
reduce_net_charge
reduce_net_charge()
Remove any net charge by proportionally adjusting each site by its signed charge.
The adjustment is done as follows: q_i_new = q_i_old - (sum_j q_j) * (q_i_old / sum_k |q_k_old|)
This distributes the total correction in proportion to the signed charges (not absolute values). As a result, atoms with larger |q| change more than atoms with smaller |q|, but corrections can push some sites away from zero. A small uniform residual is then subtracted to ensure exact neutrality.
Notes
- If Σ_k |q_k_old| == 0 (all zero charges), the function logs an error and returns without change.
- This function currently updates only the charges in the dataframe, not in the force field.
TODO: this averages charges only in dataframe, not in the force field.
Source code in src/asaf/framework.py
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 | |
set_force_field
Set the force field parameters for the framework based on the provided parameters.
Parameters:
-
parameters(dict) –A dictionary containing force field parameters. Each parameter should be a dictionary with keys 'sigma', 'epsilon', and 'charge'.
-
by(str, default:'site_type') –Specifies how to group the parameters. Can be either 'site_type' or 'site_label'.
Raises:
-
ValueError: If 'by' is not one of the allowed values ('site_type', 'site_label').–
Source code in src/asaf/framework.py
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 | |
site_labels
Return the site labels as a list or pandas Series.
Parameters:
-
as_list(bool, default:False) –If True, return as a list. If False, return as a pandas Series.
Returns:
Source code in src/asaf/framework.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
site_types
Return the site types as a list or pandas Series.
Parameters:
-
as_list(bool, default:False) –If True, return as a list. If False, return as a pandas Series.
Returns:
Source code in src/asaf/framework.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
write_fstprt
write_fstprt(
file_name: str | Path,
unit_cells: Tuple[int, int, int] = (1, 1, 1),
cutoff: float = 12.8,
return_metadata: bool = False,
ewald_tolerance: float = 1e-05,
) -> None | dict
Write molecule file with framework for FEASST simulation software.
Parameters:
-
file_name(str or Path) –Base name for the output file (without extension).
-
unit_cells(Tuple[int, int, int], default:(1, 1, 1)) –Number of unit cells to replicate in (x, y, z) directions. Default is (1, 1, 1).
-
cutoff(float, default:12.8) –Cutoff distance for non-bonded interactions in Angstroms. Default is 12.8.
-
return_metadata(bool, default:False) –If True, return metadata dictionary. Default is False.
-
ewald_tolerance(float, default:1e-05) –Desired accuracy for the Ewald summation. Default is 1e-5.
Returns:
-
None or dict–If return_metadata is True, returns a dictionary with metadata about the system. Otherwise, returns None.
Source code in src/asaf/framework.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 | |
write_metadata
write_metadata(
metadata_file_name,
box,
unit_cells,
cutoff,
cell_vectors,
)
Write metadata to a separate file.
Source code in src/asaf/framework.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
write_xyz_file
write_xyz_file(
file_name: str,
system: DataFrame,
vectors: tuple[ndarray, ndarray, ndarray],
) -> None
Write system in extxyz file format.
Parameters:
-
file_name(str) –Base name for the output file (without extension).
-
system(DataFrame) –DataFrame containing the system with columns ['site_label', 'cartesian_x', 'cartesian_y', 'cartesian_z'].
-
vectors(tuple of np.ndarray) –Tuple containing the three cell vectors as numpy arrays.
Source code in src/asaf/framework.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
options: filters: ["!^_"]