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
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 | |
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
379 380 381 382 383 384 385 386 387 | |
average_macrostate_at_fugacity
Calculate the average macrostate at a given fugacity.
Source code in src/asaf/mpd.py
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 | |
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
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 | |
check_tail
Check the probability at the tail of the lnp distribution.
Source code in src/asaf/mpd.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
dataframe
dataframe() -> DataFrame
Return dataframe.
Source code in src/asaf/mpd.py
137 138 139 | |
extrapolate
extrapolate(
temperature: float,
energy: Optional[DataFrame | Series] = None,
terms: int = 1,
) -> "MPD"
Extrapolates the MPD to a new temperature.
Parameters:
-
temperature(float) –Temperature (in K) to which to extrapolate MPD.
-
energy(Optional[DataFrame | Series], default:None) –Energy fluctuation data. If None ASAF will look for data in prob_df. Unit must be J.
-
terms(int, default:1) –Number of Taylor series terms used for extrapolation. Note that
energymust contain columns namedterm_1,term_2, ...,term_nwhere n is the number of terms.
Returns:
-
MPD–Extrapolated MPD.
Source code in src/asaf/mpd.py
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 | |
find_phase_equilibrium
find_phase_equilibrium(
delta_beta_mu_guess: Optional[float] = None,
tolerance: float = 1e-06,
return_probabilities: bool = False,
) -> Union[Tuple[float, float, float], float]
Find the fugacity at which the two phases are in equilibrium.
Uses minimize_scalar (Brent's method) on an objective that is zero
only when the low-density and high-density phase probabilities are
equal. The objective is designed to guide the optimizer smoothly
through unimodal, degenerate, and bimodal regimes.
Parameters:
-
delta_beta_mu_guess(Optional[float], default:None) –Initial hint for the shift in betamu that brings the distribution closer to equilibrium. Passed to
minimize_scalaras a bracket starting point — the optimizer can search beyond* this value. IfNone, the direction is auto-detected from the current distribution shape. -
tolerance(float, default:1e-06) –Tolerance for the minimization algorithm.
-
return_probabilities(bool, default:False) –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_probabilitiesis True, returns(fugacity, p_low, p_high).
Raises:
-
RuntimeError–If no phase equilibrium is found (distribution remains unimodal at the optimizer's solution).
Source code in src/asaf/mpd.py
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 | |
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
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
from_csv
classmethod
Read natural logarithm of macrostates probability or transition probabilities from a csv file.
Source code in src/asaf/mpd.py
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 | |
minimums
Find the local minimums in the lnp data.
Source code in src/asaf/mpd.py
389 390 391 392 393 394 395 396 397 398 399 | |
plot
Plot the MPD data using plotly.
Source code in src/asaf/mpd.py
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 | |
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
254 255 256 257 258 259 260 261 | |
reweight_to_fug
Reweight the MPD to a new mu / fugacity value using desired fugacity.
Source code in src/asaf/mpd.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
options: filters: ["!^_"]