Skip to content

Commit 5956883

Browse files
committed
Implemented the new weight-combining method (using probability ratios) and removed the old ones
1 parent 831df4c commit 5956883

File tree

11 files changed

+228
-154
lines changed

11 files changed

+228
-154
lines changed

docs/requirements.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ dependencies:
99
# Pip-only installs
1010
- pip:
1111
- nbsphinx
12-
- docutils=0.16
12+
- docutils==0.16

docs/theory_implementation.rst

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ other during the simulation ensemble. Below we decribe the details of these para
163163

164164
* :code:`nst_sim`: The number of simulation steps, i.e. exchange frequency. This option assumes replicas with homogeneous simulation lengths. If this option is not specified, the number of steps defined in the template MDP file will be used.
165165
* :code:`mc_scheme`: The method for swapping simulations. Choices include :code:`same-state`/:code:`same_state`, :code:`metropolis`, and :code:`metropolis-eq`/:code:`metropolis_eq`. For more details, please refer to :ref:`doc_mc_schemes`. (Default: :code:`metropolis`)
166-
* :code:`w_scheme`: The method for combining weights. Choices include :code:`None` (unspecified), :code:`exp-avg`/:code:`exp_avg`, and :code:`hist-exp-avg`/:code:`hist_exp_avg`. For more details, please refer to :ref:`doc_w_schemes`. (Default: :code:`hist-exp-avg`)
167-
* :code:`N_cutoff`: The histogram cutoff. Only required if :code:`hist-exp-avg` is used. (Default: 0)
166+
* :code:`w_scheme`: The method for combining weights. Choices include :code:`None` (unspecified), :code:`mean`, and :code:`geo-mean`/:code:`geo_mean`. For more details, please refer to :ref:`doc_w_schemes`. (Default: :code:`None`)
167+
* :code:`N_cutoff`: The histogram cutoff. -1 means that no histogram correction will be performed. (Default: 1000)
168168
* :code:`n_ex`: The number of swaps to be proposed in one attempt. This works basically the same as :code:`-nex` flag in GROMACS. A recommended value is :math:`N^3`, where :math:`N` is the number of replicas. If `n_ex` is unspecified or specified as 0, neighboring swapping will be carried out. For more details, please refer to :ref:`doc_swap_basics`. (Default: 0)
169169
* :code:`outfile`: The output file for logging how replicas interact with each other.
170170
* :code:`verbose`: Whether a verbse log is wanted.
@@ -519,14 +519,14 @@ for each replica. Note that the sum of the probabilities of each row (replica) s
519519

520520
::
521521

522-
State 0 1 2 3 4 5
523-
Rep 1 0.858 0.105 0.016 0.021 X X
524-
Rep 2 X 0.642 0.117 0.193 0.048 X
525-
Rep 3 X X 0.328 0.489 0.133 0.049
522+
State 0 1 2 3 4 5
523+
Rep 1 0.85800 0.10507 0.01571 0.02121 X X
524+
Rep 2 X 0.64179 0.11724 0.19330 0.04767 X
525+
Rep 3 X X 0.32809 0.48945 0.13339 0.04907
526526

527527

528-
Step 2: Calculate the probability ratios between each pair of replicas
529-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
528+
Step 2: Calculate the probability ratios
529+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
530530
Ideally (in the limit of inifinite simulation time), for the 3 states overlapped between replicas 1 and 2,
531531
we should have
532532

@@ -535,15 +535,16 @@ we should have
535535
536536
where :math:`r_{2, 1}` is the "probability ratio" between replicas 2 and 1. However, the probability ratios
537537
corresopnding to different states will not be the same in practice, but will diverge with statistical noise
538-
for short timescales. For example, in our case we have
538+
for short timescales. For example, in our case we have the following ratios. (Note that here we calculate with
539+
full precision but only present a few significant figures.)
539540

540541
.. math::
541-
\frac{p_{21}}{p_{11}}=6.1143, \; \frac{p_{22}}{p_{12}} = 7.3125, \; \frac{p_{23}}{p_{13}}=9.1905
542+
\frac{p_{21}}{p_{11}}=6.10828, \; \frac{p_{22}}{p_{12}} = 7.46068, \; \frac{p_{23}}{p_{13}}=9.11249
542543
543544
Similarly, for states 2 to 4, we need to calculate the probability ratios between replicas 2 and 3:
544545

545546
.. math::
546-
\frac{p_{32}}{p_{22}}=2.8034, \; \frac{p_{33}}{p_{23}} = 2.5337, \; \frac{p_{34}}{p_{24}}=2.7708
547+
\frac{p_{32}}{p_{22}}=2.79834, \; \frac{p_{33}}{p_{23}} = 2.53204, \; \frac{p_{34}}{p_{24}}=2.79834
547548
548549
Notably, in this case, there is no need to calculate :math:`r_{3, 1}` because :math:`r_{3, 1}` is already determined
549550
as :math:`r_{3, 1}=r_{3, 2} \times r_{2, 1}`. Also, there are only 2 overlapping states between replicas 1 and 3,
@@ -559,14 +560,14 @@ or geometric averages.
559560
- Method 1: Simple average
560561

561562
.. math::
562-
r_{2, 1} = \frac{1}{3}\left(\frac{p_{21}}{p_{11}} + \frac{p_{22}}{p_{12}} + \frac{p_{23}}{p_{13}} \right) \approx 7.5391, \;
563-
r_{3, 2} = \frac{1}{3}\left(\frac{p_{32}}{p_{22}} + \frac{p_{33}}{p_{23}} + \frac{p_{34}}{p_{24}} \right) \approx 2.7026
563+
r_{2, 1} = \frac{1}{3}\left(\frac{p_{21}}{p_{11}} + \frac{p_{22}}{p_{12}} + \frac{p_{23}}{p_{13}} \right) \approx 7.56049, \;
564+
r_{3, 2} = \frac{1}{3}\left(\frac{p_{32}}{p_{22}} + \frac{p_{33}}{p_{23}} + \frac{p_{34}}{p_{24}} \right) \approx 2.70957
564565
565566
- Method 2: Geometric average
566567

567568
.. math::
568-
r_{2, 1}' = \left(\frac{p_{21}}{p_{11}} \times \frac{p_{22}}{p_{12}} \times \frac{p_{23}}{p_{13}} \right)^{\frac{1}{3}} \approx 7.4345, \;
569-
r_{3, 2}' = \left(\frac{p_{32}}{p_{22}} \times \frac{p_{33}}{p_{23}} \times \frac{p_{34}}{p_{24}} \right)^{\frac{1}{3}} \approx 2.6999
569+
r_{2, 1}' = \left(\frac{p_{21}}{p_{11}} \times \frac{p_{22}}{p_{12}} \times \frac{p_{23}}{p_{13}} \right)^{\frac{1}{3}} \approx 7.46068, \;
570+
r_{3, 2}' = \left(\frac{p_{32}}{p_{22}} \times \frac{p_{33}}{p_{23}} \times \frac{p_{34}}{p_{24}} \right)^{\frac{1}{3}} \approx 2.70660
570571
571572
Notably, if we take the negative natural logarithm of a probability ratio, we will get a free energy difference. For example,
572573
:math:`-\ln (p_{21}/p_{11})=f_{21}-f_{11}`, i.e. the free energy difference between state 1 in replica 2 and state 1 in replica 1.
@@ -583,10 +584,10 @@ replicas 2 and 3 as follows:
583584

584585
::
585586

586-
State 0 1 2 3 4 5
587-
Rep 1 0.858 0.105 0.016 0.021 X X
588-
Rep 2’ X 0.08529 0.01552 0.02560 0.00637 X
589-
Rep 3’ X X 0.01610 0.02400 0.00653 0.00240
587+
State 0 1 2 3 4 5
588+
Rep 1 0.85800 0.10507 0.01571 0.02121 X X
589+
Rep 2’ X 0.08489 0.01551 0.02557 0.00630 X
590+
Rep 3’ X X 0.01602 0.02389 0.00651 0.00240
590591
591592
As shown above, we keep the probability vector of replica 1 the same but scale that for the other two. Specifically, the probability
592593
vector of replica 2' is that of replica 2 divided by :math:`r_21` and the probability vector of replica 3' is that of replica 3
@@ -596,10 +597,10 @@ Similarly, if we used the probability ratios :math:`r_{21}'` and :math:`r_{32}'`
596597

597598
::
598599

599-
State 0 1 2 3 4 5
600-
Rep 1 0.858 0.105 0.016 0.021 X X
601-
Rep 2’ X 0.08645 0.01573 0.02596 0.00646 X
602-
Rep 3’ X X 0.01634 0.02436 0.00663 0.00244
600+
State 0 1 2 3 4 5
601+
Rep 1 0.85800 0.10507 0.01614 0.02121 X X
602+
Rep 2’ X 0.08602 0.01571 0.02591 0.00639 X
603+
Rep 3’ X X 0.01625 0.02424 0.00661 0.00243
603604

604605

605606
Step 5: Average and convert the probabilities
@@ -611,25 +612,25 @@ and :math:`r_{32}`), we have the following probability vector of full range:
611612

612613
::
613614

614-
Final p 0.858 0.9515 0.01587 0.02353 0.00645 0.00240
615+
Final p 0.85800 0.09498 0.01575 0.02356 0.00641 0.00240
615616

616617
which can be converted to the following vector of alchemical weights (denoted as :math:`\vec{g}`) by taking the negative natural logarithm:
617618

618619
::
619620

620-
Final g 0.1532 0.0497 4.1433 3.7495 5.0437 6.0322
621+
Final g 0.15321 2.35412 4.15117 3.74831 5.05019 6.03420
621622

622623
For the second case (scaled with :math:`r_{21}'` and :math:`r_{32}'`), we have
623624

624625
::
625626

626-
Final p 0.858 0.09527 0.01602 0.02368 0.00654 0.00244
627+
Final p 0.85800 0.09507 0.01589 0.02371 0.00649 0.00243
627628

628-
which can be converted to the following vector of alchemical weights (denoted as :math:`\vec{g'}`):
629+
which can be converted to the following vector of alchemical weights (denoted as :math:`\vec{g}'`):
629630

630631
::
631632

632-
Final g 0.1532 2.3510 4.1339 3.7431 5.0437 6.0158
633+
Final g 0.15315 2.35314 4.14203 3.74204 5.03658 6.01981
633634

634635

635636
Step 6: Determine the vector of alchemical weights for each replica
@@ -640,20 +641,28 @@ we have:
640641

641642
::
642643

643-
State 0 1 2 3 4 5
644-
Rep 1 0.0 2.199 3.990 3.596 X X
645-
Rep 2 X 0.0 1.791 1.397 2.691 X
646-
Rep 3 X X 0.0 -0.393 0.900 1.889
644+
State 0 1 2 3 4 5
645+
Rep 1 0.00000 2.20097 3.99802 3.59516 X X
646+
Rep 2 X 0.00000 1.79706 1.39419 2.69607 X
647+
Rep 3 X X 0.00000 -0.40286 0.89901 1.88303
647648

648-
Similarly, with :math:`\vec{g'}`, we have:
649+
Similarly, with :math:`\vec{g}'`, we have:
649650

650651
::
651652

652-
State 0 1 2 3 4 5
653-
Rep 1 0.0 2.198 3.981 3.590 X X
654-
Rep 2 X 0.0 1.783 1.392 2.693 X
655-
Rep 3 X X 0.0 -0.391 0.910 1.882
653+
State 0 1 2 3 4 5
654+
Rep 1 0.00000 2.20000 3.98889 3.58889 X X
655+
Rep 2 X 0.00000 1.78889 1.38889 2.68333 X
656+
Rep 3 X X 0.00000 -0.40000 0.89444 1.87778
657+
658+
As a reference, here are the original weights:
659+
660+
::
656661

662+
State 0 1 2 3 4 5
663+
Rep 1 0.0 2.1 4.0 3.7 X X
664+
Rep 2 X 0.0 1.7 1.2 2.6 X
665+
Rep 3 X X 0.0 -0.4 0.9 1.9
657666

658667
As shown above, the results using Method 1 and Method 2 are pretty close to each other. Notably, regardless of
659668
which type of averages we took, in the case here we were assuming that each replica is equally weighted. In the

0 commit comments

Comments
 (0)