Skip to content

Commit dff54f6

Browse files
committed
different potential scales in example too
1 parent fc6b993 commit dff54f6

File tree

3 files changed

+150
-95
lines changed

3 files changed

+150
-95
lines changed

docs/source/physics/single_chain/fjc/thermodynamics/modified_canonical/example_asymptotic.ipynb

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@
2727
},
2828
{
2929
"cell_type": "markdown",
30-
"id": "8abeab96",
31-
"metadata": {},
32-
"source": [
33-
"## Strong potential"
34-
]
35-
},
36-
{
37-
"cell_type": "markdown",
38-
"id": "8c7dadae",
30+
"id": "1592d36b",
3931
"metadata": {},
4032
"source": [
33+
"## Strong potential\n",
34+
"\n",
4135
"For sufficiently strong potentials, the modified canonical ensemble can be accurately approximated using the reference system (the isometric ensemble) and an asymptotic correction. For example, the nondimensional force $\\eta$ as a function of the nondimensional potential distance $\\gamma$ is approximated as\n",
4236
"\n",
4337
"$$\n",
@@ -68,11 +62,10 @@
6862
"source": [
6963
"gamma = np.linspace(1e-3, 99e-2, 256)\n",
7064
"for varpi in [1e0, 1e1, 1e2]:\n",
71-
" w = varpi*fjc.number_of_links**2\n",
72-
" eta = fjc.nondimensional_force(gamma, w)\n",
65+
" eta = fjc.nondimensional_force(gamma, varpi)\n",
7366
" line = plt.plot(gamma, eta, label=r'$\\varpi=$' + str(varpi))\n",
7467
" eta_asymptotic = \\\n",
75-
" fjc.asymptotic.strong_potential.nondimensional_force(gamma, w)\n",
68+
" fjc.asymptotic.strong_potential.nondimensional_force(gamma, varpi)\n",
7669
" plt.plot(gamma, eta_asymptotic, ':', color=line[0].get_color())\n",
7770
"plt.legend()\n",
7871
"plt.xlim([0, 1])\n",
@@ -84,17 +77,11 @@
8477
},
8578
{
8679
"cell_type": "markdown",
87-
"id": "1d21a64d",
88-
"metadata": {},
89-
"source": [
90-
"## Weak potential"
91-
]
92-
},
93-
{
94-
"cell_type": "markdown",
95-
"id": "dce6f3d2",
80+
"id": "8a77ab06",
9681
"metadata": {},
9782
"source": [
83+
"## Weak potential\n",
84+
"\n",
9885
"For sufficiently distant potentials, the modified canonical ensemble can be accurately approximated using the reference system (the isotensional ensemble) and an asymptotic correction. The potential is considered sufficiently distant when the length of center of the potential well to the end of the chain experiencing it is much larger than the expected end-to-end length of the chain. This disparity in length is only typically possible considering weak potentials. For example, if $\\eta/N_b\\varpi$ is the nondimensional potential distance, the nondimensional end-to-end length per link $\\gamma$ as a function of the effective nondimensional potential force $\\eta$ is approximated as\n",
9986
"\n",
10087
"$$\n",
@@ -105,14 +92,9 @@
10592
"\n",
10693
"$$\n",
10794
" \\gamma(\\eta) = \\frac{1}{N_b}\\frac{\\partial}{\\partial\\eta}\\,\\ln\\left[\\iiint Q_0(\\boldsymbol{\\gamma}') \\, e^{N_b\\boldsymbol{\\eta}\\cdot\\boldsymbol{\\gamma}'} e^{-\\tfrac{\\varpi}{2} N_b^2\\left(\\boldsymbol{\\gamma}'\\right)^2} d^3\\boldsymbol{\\gamma}'\\right].\n",
108-
"$$\n"
109-
]
110-
},
111-
{
112-
"cell_type": "markdown",
113-
"id": "8a77ab06",
114-
"metadata": {},
115-
"source": [
95+
"$$\n",
96+
"\n",
97+
"\n",
11698
"This exact relation is plotted below along with the asymptotic relation while varying $\\varpi$, the nondimensional potential stiffness. As $\\varpi$ decreases and/or the nondimensional force $\\eta$ increases (the nondimensional potential distance $\\eta/N_b\\varpi$ increases), the asymptotic approach appears to do increasingly well. Notably, the asymptoic approach appears to succeed for sufficiently distance potentials for any value of $\\varpi$. This is because the freely-jointed chain model has inextensible links, so even a stiff potential that is distant ($\\eta/N_b\\varpi\\gg 1$) will not stretch the chain past $\\gamma=1$. For chain models which have extensible links, the link stiffness will compete with the potential stiffness, such that the potential would need to be weak ($\\varpi\\ll 1$) in addition to distant ($\\eta/N_b\\varpi\\gg 1$) in order for the asymptotic approach to become accurate."
11799
]
118100
},
@@ -125,11 +107,10 @@
125107
"source": [
126108
"gamma_in = np.linspace(5e-1, 5, 256)\n",
127109
"for varpi in [1e0, 1e-1, 1e-2]:\n",
128-
" w = varpi*fjc.number_of_links**2\n",
129-
" gamma = fjc.nondimensional_end_to_end_length_per_link(gamma_in, w)\n",
110+
" gamma = fjc.nondimensional_end_to_end_length_per_link(gamma_in, varpi)\n",
130111
" line = plt.plot(gamma, gamma_in, label=r'$\\varpi=$' + str(varpi))\n",
131112
" gamma_asymptotic = \\\n",
132-
" fjc.asymptotic.weak_potential.nondimensional_end_to_end_length_per_link(gamma_in, w)\n",
113+
" fjc.asymptotic.weak_potential.nondimensional_end_to_end_length_per_link(gamma_in, varpi)\n",
133114
" plt.plot(gamma_asymptotic, gamma_in, ':', color=line[0].get_color())\n",
134115
"plt.legend()\n",
135116
"plt.xlim([0, 1])\n",

src/physics/single_chain/fjc/thermodynamics/modified_canonical/test.jl

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,8 @@ end
13501350
potential_stiffness,
13511351
temperature,
13521352
)
1353-
@test abs(relative_gibbs_free_energy_0) <= ZERO
1353+
@test abs(relative_gibbs_free_energy_0) <=
1354+
ZERO * number_of_links * BOLTZMANN_CONSTANT * temperature
13541355
end
13551356
end
13561357

@@ -1377,7 +1378,8 @@ end
13771378
potential_stiffness,
13781379
temperature,
13791380
)
1380-
@test abs(relative_gibbs_free_energy_per_link_0) <= ZERO
1381+
@test abs(relative_gibbs_free_energy_per_link_0) <=
1382+
ZERO * BOLTZMANN_CONSTANT * temperature
13811383
end
13821384
end
13831385

@@ -1398,7 +1400,7 @@ end
13981400
ZERO,
13991401
nondimensional_potential_stiffness,
14001402
)
1401-
@test abs(nondimensional_relative_gibbs_free_energy_0) <= ZERO
1403+
@test abs(nondimensional_relative_gibbs_free_energy_0) <= ZERO * number_of_links
14021404
end
14031405
end
14041406

@@ -2429,12 +2431,12 @@ end
24292431
residual_rel_2 = residual_rel(
24302432
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
24312433
)
2432-
@test abs(residual_rel_1) <=
2433-
parameters.nondimensional_potential_stiffness_small^2 &&
2434+
log_log_slope =
2435+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2436+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2437+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
24342438
abs(residual_rel_2) <=
2435-
(
2436-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2437-
)^2
2439+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
24382440
end
24392441
end
24402442

@@ -2495,12 +2497,12 @@ end
24952497
residual_rel_2 = residual_rel(
24962498
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
24972499
)
2498-
@test abs(residual_rel_1) <=
2499-
parameters.nondimensional_potential_stiffness_small^2 &&
2500+
log_log_slope =
2501+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2502+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2503+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
25002504
abs(residual_rel_2) <=
2501-
(
2502-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2503-
)^2
2505+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
25042506
end
25052507
end
25062508

@@ -2549,12 +2551,12 @@ end
25492551
residual_rel_2 = residual_rel(
25502552
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
25512553
)
2552-
@test abs(residual_rel_1) <=
2553-
parameters.nondimensional_potential_stiffness_small^2 &&
2554+
log_log_slope =
2555+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2556+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2557+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
25542558
abs(residual_rel_2) <=
2555-
(
2556-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2557-
)^2
2559+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
25582560
end
25592561
end
25602562

@@ -2603,12 +2605,12 @@ end
26032605
residual_rel_2 = residual_rel(
26042606
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
26052607
)
2606-
@test abs(residual_rel_1) <=
2607-
parameters.nondimensional_potential_stiffness_small^2 &&
2608+
log_log_slope =
2609+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2610+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2611+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
26082612
abs(residual_rel_2) <=
2609-
(
2610-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2611-
)^2
2613+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
26122614
end
26132615
end
26142616

@@ -2689,12 +2691,12 @@ end
26892691
residual_rel_2 = residual_rel(
26902692
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
26912693
)
2692-
@test abs(residual_rel_1) <=
2693-
parameters.nondimensional_potential_stiffness_small^2 &&
2694+
log_log_slope =
2695+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2696+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2697+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
26942698
abs(residual_rel_2) <=
2695-
(
2696-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2697-
)^2
2699+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
26982700
end
26992701
end
27002702

@@ -2775,12 +2777,12 @@ end
27752777
residual_rel_2 = residual_rel(
27762778
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
27772779
)
2778-
@test abs(residual_rel_1) <=
2779-
parameters.nondimensional_potential_stiffness_small^2 &&
2780+
log_log_slope =
2781+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2782+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2783+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
27802784
abs(residual_rel_2) <=
2781-
(
2782-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2783-
)^2
2785+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
27842786
end
27852787
end
27862788

@@ -2861,12 +2863,12 @@ end
28612863
residual_rel_2 = residual_rel(
28622864
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
28632865
)
2864-
@test abs(residual_rel_1) <=
2865-
parameters.nondimensional_potential_stiffness_small^2 &&
2866+
log_log_slope =
2867+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2868+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2869+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
28662870
abs(residual_rel_2) <=
2867-
(
2868-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2869-
)^2
2871+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
28702872
end
28712873
end
28722874

@@ -2948,12 +2950,12 @@ end
29482950
residual_rel_2 = residual_rel(
29492951
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
29502952
)
2951-
@test abs(residual_rel_1) <=
2952-
parameters.nondimensional_potential_stiffness_small^2 &&
2953+
log_log_slope =
2954+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
2955+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
2956+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
29532957
abs(residual_rel_2) <=
2954-
(
2955-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
2956-
)^2
2958+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
29572959
end
29582960
end
29592961

@@ -3021,12 +3023,12 @@ end
30213023
residual_rel_2 = residual_rel(
30223024
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
30233025
)
3024-
@test abs(residual_rel_1) <=
3025-
parameters.nondimensional_potential_stiffness_small^2 &&
3026+
log_log_slope =
3027+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
3028+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
3029+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
30263030
abs(residual_rel_2) <=
3027-
(
3028-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
3029-
)^2
3031+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
30303032
end
30313033
end
30323034

@@ -3101,12 +3103,12 @@ end
31013103
residual_rel_2 = residual_rel(
31023104
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
31033105
)
3104-
@test abs(residual_rel_1) <=
3105-
parameters.nondimensional_potential_stiffness_small^2 &&
3106+
log_log_slope =
3107+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
3108+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
3109+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
31063110
abs(residual_rel_2) <=
3107-
(
3108-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
3109-
)^2
3111+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
31103112
end
31113113
end
31123114

@@ -3167,12 +3169,12 @@ end
31673169
residual_rel_2 = residual_rel(
31683170
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
31693171
)
3170-
@test abs(residual_rel_1) <=
3171-
parameters.nondimensional_potential_stiffness_small^2 &&
3172+
log_log_slope =
3173+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
3174+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
3175+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
31723176
abs(residual_rel_2) <=
3173-
(
3174-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
3175-
)^2
3177+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
31763178
end
31773179
end
31783180

@@ -3233,12 +3235,12 @@ end
32333235
residual_rel_2 = residual_rel(
32343236
parameters.nondimensional_potential_stiffness_small * parameters.log_log_scale,
32353237
)
3236-
@test abs(residual_rel_1) <=
3237-
parameters.nondimensional_potential_stiffness_small^2 &&
3238+
log_log_slope =
3239+
-log(residual_rel_2 / residual_rel_1) / log(parameters.log_log_scale)
3240+
@test abs(log_log_slope + 1.0) <= parameters.log_log_tol &&
3241+
abs(residual_rel_1) <= parameters.nondimensional_potential_stiffness_small &&
32383242
abs(residual_rel_2) <=
3239-
(
3240-
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
3241-
)^2
3243+
parameters.nondimensional_potential_stiffness_small / parameters.log_log_scale
32423244
end
32433245
end
32443246

0 commit comments

Comments
 (0)