asaf.mpd
Module for handling Macrostate Probability Distribution (MPD) data.
MPD
MPD(
dataframe: DataFrame,
temperature: float,
beta_mu: Optional[float] = None,
fugacity: Optional[float] = None,
metadata: Optional[dict[str, Any]] = None,
order: int = 50,
tolerance: float = 10.0,
)
Class for storing and processing macrostate probability distribution.
Parameters:
-
dataframe
(DataFrame
) –a pandas dataframe with state specific data
-
temperature
(float
) –temperature (in K) at which the simulation was performed
-
beta_mu
(Optional[float]
, default:None
) –beta_mu (unitless) at which the simulation was performed. At least one of beta_mu or fugacity must be specified
-
fugacity
(Optional[float]
, default:None
) –fugacity (in Pa) at which the simulation was performed. At least one of beta_mu or fugacity must be specified
-
metadata
(Optional[dict[str, Any]]
, default:None
) –a dictionary with the simulation metadata
-
order
(int
, default:50
) –how many points on each side use to find minimum in lnp
-
tolerance
(float
, default:10.0
) –used when checking the probability at lnp tail
Source code in src/asaf/mpd.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 |
|
lnp
property
lnp: DataFrame
Return a dataframe with the natural logarithm of the macrostate probability.
tolerance
property
writable
tolerance: float
Return the tolerance used when checking the probability at lnp tail.
average_macrostate
Calculate the average macrostate from the MPD data.
Note that this function does not check for multiple phases. Use average_macrostate_at_fugacity
to calculate the average macrostate at a given fugacity, which checks for multiple phases.
Source code in src/asaf/mpd.py
418 419 420 421 422 423 424 425 426 |
|
average_macrostate_at_fugacity
Calculate the average macrostate at a given fugacity.
Source code in src/asaf/mpd.py
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 |
|
beta_to_temperature
staticmethod
Convert beta to temperature using Boltzmann constant.
Source code in src/asaf/mpd.py
198 199 200 201 202 |
|
calculate_isotherm
calculate_isotherm(
fugacity: ArrayLike,
saturation_fugacity: Optional[float] = None,
pressure: Optional[ArrayLike] = None,
order: Optional[int] = None,
return_dataframe: bool = True,
) -> Union[DataFrame | Isotherm]
Calculate the adsorption isotherm.
Parameters:
-
fugacity
(ArrayLike
) –Array of fugacities.
-
saturation_fugacity
(Optional[float]
, default:None
) –Saturation pressure to calculate the pressure in relative scale (p/p0).
-
pressure
(Optional[ArrayLike]
, default:None
) –Array of pressures corresponding to the fugacities.
-
order
(Optional[int]
, default:None
) –How many points on each side use to find minimum in lnp.
-
return_dataframe
(bool
, default:True
) –Whether to return the adsorption isotherm as a dataframe or Isotherm instance.
Returns:
-
DataFrame or Isotherm
–DataFrame containing the adsorption isotherm or Isotherm instance if return_dataframe is False.
-
Args
(Union[DataFrame | Isotherm]
) –pressure:
Source code in src/asaf/mpd.py
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 |
|
calculate_lnp
staticmethod
calculate_lnp(prob_df: DataFrame) -> DataFrame
Calculate the natural logarithm of the macrostate transition probability[1].
Parameters:
-
prob_df
(DataFrame
) –A pandas DataFrame containing transition probabilities.
Returns:
-
lnp_df
–A pandas DataFrame containing natural logarithm of the macrostate transition probability.
References
.. [1] Shen, V. K., & Errington, J. R. (2004). Metastability and Instability in the Lennard-Jones Fluid Investigated by Transition-Matrix Monte Carlo, In The Journal of Physical Chemistry B (Vol. 108, Issue 51, pp. 19595–19606). American Chemical Society (ACS). https://doi.org/10.1021/jp040218y
Source code in src/asaf/mpd.py
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 |
|
check_tail
Check the probability at the tail of the lnp distribution.
Source code in src/asaf/mpd.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
dataframe
dataframe() -> DataFrame
Return dataframe.
Source code in src/asaf/mpd.py
194 195 196 |
|
extrapolate
extrapolate(
temperature: float,
energy: Optional[DataFrame | Series] = None,
terms: int = 1,
) -> "MPD"
Extrapolates the MPD to a new temperature.
Parameters:
-
temperature
(float
) –Temperature to which to extrapolate MPD.
-
energy
(Optional[DataFrame | Series]
, default:None
) –Energy fluctuation data. If None ASAF will look for data in prob_df.
-
terms
(int
, default:1
) –Number of Taylor series terms used for extrapolation.
Returns:
-
MPD
–Extrapolated MPD.
Source code in src/asaf/mpd.py
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 |
|
find_phase_equilibrium
find_phase_equilibrium(
tolerance: float = 1e-06,
max_iterations: int = 100,
return_probabilities: bool = False,
) -> Union[Tuple[float, float, float], float]
Find the fugacity at which the two phases are in equilibrium.
Arguments
tolerance Tolerance for the root finding algorithm. max_iterations Maximum number of iterations for the root finding algorithm. return_probabilities Whether to return the probabilities of the two phases at equilibrium.
Returns:
-
float or Tuple[float, float, float]
–The fugacity at which the two phases are in equilibrium. If
return_probabilities
is True, also returns the probabilities of the two phases at equilibrium.
Source code in src/asaf/mpd.py
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 |
|
free_energy_at_fugacity
free_energy_at_fugacity(fug: float) -> DataFrame
Calculate the free energy profile at a given fugacity.
Source code in src/asaf/mpd.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
from_csv
classmethod
Read natural logarithm of macrostates probability or transition probabilities from a csv file.
Source code in src/asaf/mpd.py
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 |
|
fugacity_to_mu
staticmethod
Convert fugacity (in Pa) to chemical potential (in J A^-3).
Source code in src/asaf/mpd.py
210 211 212 213 214 |
|
interpolate_df
staticmethod
interpolate_df(
df: DataFrame, based_on: str = "macrostate"
) -> DataFrame
Interpolates data in a dataframe.
Parameters:
-
df
(DataFrame
) –A pandas DataFrame containing data to be interpolated.
-
based_on
(str
, default:'macrostate'
) –Column name in df containing values of the independent variable. Values must be real, finite, and in strictly increasing order.
Returns:
-
df_interp
–A pandas DataFrame containing interpolated data.
Source code in src/asaf/mpd.py
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 |
|
minimums
Find the local minimums in the lnp data.
Source code in src/asaf/mpd.py
428 429 430 431 432 433 434 435 |
|
mu_to_fugacity
staticmethod
Convert chemical potential (in J A^-3) to fugacity (in Pa).
Source code in src/asaf/mpd.py
216 217 218 219 220 |
|
plot
Plot the MPD data using plotly.
Source code in src/asaf/mpd.py
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 |
|
reweight
reweight(delta_beta_mu: float) -> DataFrame
Reweight the MPD to a new mu / fugacity value using delta_beta_mu
.
Source code in src/asaf/mpd.py
333 334 335 336 337 338 339 340 |
|
reweight_to_fug
Reweight the MPD to a new mu / fugacity value using desired fugacity.
Source code in src/asaf/mpd.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
temperature_to_beta
staticmethod
Convert temperature to beta using Boltzmann constant.
Source code in src/asaf/mpd.py
204 205 206 207 208 |
|
normalize
Normalize the natural logarithm of the macrostate probability.
Parameters:
Returns:
-
Normalized natural logarithm of the macrostate probability.
–
Source code in src/asaf/mpd.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
|
options: filters: ["!^_"]