From 70b6880f4b53bea4480aaefc291c24dbe0e8901e Mon Sep 17 00:00:00 2001 From: DavideTisi Date: Tue, 10 Dec 2024 18:35:59 +0100 Subject: [PATCH] linter --- examples/free-energy/free-energy.py | 85 ++++++++++++++++++----------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/examples/free-energy/free-energy.py b/examples/free-energy/free-energy.py index 69535352..763b4f7e 100644 --- a/examples/free-energy/free-energy.py +++ b/examples/free-energy/free-energy.py @@ -20,7 +20,6 @@ import ase.io import chemiscope import ipi -import ipi.utils.parsing as pimdmooc import matplotlib.pyplot as plt import numpy as np @@ -110,7 +109,8 @@ def PES(x, y, z): # The harmonic approximation to the PES is essentially # a truncated Taylor series expansion to second # order around one of its minima. -# :math:`V^{\text{harm}} = V(q_0) + \frac{2}{2} \left.\frac{\partial^2 V}{\partial q^2}\right|_{q_0} (q - q_0)^2` +# :math:`V^{\text{harm}} = V(q_0) + +# \frac{1}{2} \left.\frac{\partial^2 V}{\partial q^2}\right|_{q_0} (q - q_0)^2` # where :math:`q = (x,y,z)` # is a position vector and :math:`q_0 = \text{arg min}_{q} V` is # the position where the PES has a local minimum. @@ -150,7 +150,7 @@ def PES(x, y, z): # simply move towards a local minimum of the PES. There are # many algorithms for locally optimizing high-dimensional functions; # here we use the robust -# `BFGS `_ +# `BFGS` (Broyden-Fletcher-Goldfarb-Shanno) quasi-Newton # method. The tolerances set thershold values for changes in the energy, # positions and forces, that are sufficient to deem an optimization converged. # @@ -252,8 +252,10 @@ def PES(x, y, z): # - \epsilon} \right) # # At every step instead of performing "dynamics", we will displace a degree of -# freedom along :math:`\pm \epsilon` and estimate one row of the Hessian. `pos_shift` sets -# the value of :math:`\epsilon` while `asr` zeros out the blocks of the Hessian due to continuous +# freedom along :math:`\pm \epsilon` and estimate one row of the Hessian. +# `pos_shift` sets +# the value of :math:`\epsilon` while `asr` zeros out the blocks +# of the Hessian due to continuous # symmetries (translations or rotations for solids or clusters). In this example, # we set this option to `none` as our system doesn't possess any continuous symmetries. # @@ -396,9 +398,11 @@ def quantum_harmonic_free_energy(Ws, T): # # Calculating free energies beyond the harmonic approximation is non-trivial. # There exist a familty of methods that can solve the vibrational Schroedinger -# Equation by approximating the anharmonic component of the PES, yielding an amharmonic +# Equation by approximating the anharmonic component of +# the PES, yielding an amharmonic # free energy. While highly effective for low-dimensional or mildly anharmonic systems, -# the method of resort for *numerically-exact amharmonic free energies* of solid and clusters +# the method of resort for *numerically-exact amharmonicfree energies* +# of solid and clusters # is the thermodynamic integration method combined with the path-integral method # ( for applications see Refs. # `M. Rossi et al, PRL (2016) `_, @@ -439,7 +443,8 @@ def quantum_harmonic_free_energy(Ws, T): # Classical Statistical Mechanics # ------------------------------- # -# Let's first compute the anharmonic free energy difference within the classical approximation. +# Let's first compute the anharmonic free +# energy difference within the classical approximation. # # To create the input file for I-PI we need to defines a "mixed" # :math:`\lambda`-dependent Hamiltonian. Let's see the new most important parts. @@ -463,8 +468,12 @@ def quantum_harmonic_free_energy(Ws, T): # defines the harmonic PES <--> # # HESSIAN_FILE -# X_REF_FILE relative path to a file containing the optimized positon vector <--> -# V_REF the value of the PES at its local minimum <--> +# X_REF_FILE +# relative path to a file containing the optimized positon vector <--> +# +# V_REF +# the value of the PES at its local minimum <--> +# # # # an intrinsic harmonic forcefield that builds the harmonic potential. @@ -494,10 +503,10 @@ def quantum_harmonic_free_energy(Ws, T): # # .. code-block:: xml # -# -# set this to lambda <--> -# set this to 1 - lambda <--> -# +# +# set this to lambda <--> +# set this to 1 - lambda <--> +# # # You can print out the harmonic and the anharmonic # components as a in the output class @@ -521,9 +530,14 @@ def quantum_harmonic_free_energy(Ws, T): with open(f"cti/input_{i}.xml", "w") as f: strfile = """ - [ step, time{{picosecond}}, conserved, temperature{{kelvin}}, kinetic_cv, potential, pressure_cv, volume, ensemble_temperature ] - [ pot_component_raw(0), pot_component_raw(1) ] - positions + [ step, time{{picosecond}}, + conserved, temperature{{kelvin}}, kinetic_cv, potential, pressure_cv, + volume, ensemble_temperature ] + + [ pot_component_raw(0), pot_component_raw(1) ] + + positions + x_centroid @@ -534,13 +548,13 @@ def quantum_harmonic_free_energy(Ws, T): 1e-3 - {HESSIAN_FILE} - {X_REF_FILE} - {V_REF} + {HESSIAN_FILE} + {X_REF_FILE} + {V_REF} - ./cti/init.xyz + ./cti/init.xyz 300 @@ -548,7 +562,7 @@ def quantum_harmonic_free_energy(Ws, T): - False + False 1.00 @@ -584,7 +598,7 @@ def quantum_harmonic_free_energy(Ws, T): # # wait 5 # -# for x in {0..10..2}; do +# for x in {0..10}; do # i-pi-driver -u -h f${x} -m doublewell_1D & # done # @@ -613,7 +627,7 @@ def quantum_harmonic_free_energy(Ws, T): duerr_list = [] dir_list = ["0.0", "0.2", "0.4", "0.6", "0.8", "1.0"] -l_list = [float(l) for l in dir_list] +l_list = [float(lst) for lst in dir_list] for i in dir_list: @@ -702,9 +716,14 @@ def classical_harmonic_free_energy(Ws, T): with open(f"qti/input_{i}.xml", "w") as f: strfile = """ - [ step, time{{picosecond}}, conserved, temperature{{kelvin}}, kinetic_cv, potential, pressure_cv, volume, ensemble_temperature ] - [ pot_component_raw(0), pot_component_raw(1) ] - positions + [ step, time{{picosecond}}, + conserved, temperature{{kelvin}}, kinetic_cv, potential, + pressure_cv, volume, ensemble_temperature ] + + [ pot_component_raw(0), pot_component_raw(1) ] + + positions + x_centroid @@ -715,13 +734,13 @@ def classical_harmonic_free_energy(Ws, T): 1e-3 - {HESSIAN_FILE} - {X_REF_FILE} - {V_REF} + {HESSIAN_FILE} + {X_REF_FILE} + {V_REF} - ./qti/init.xyz + ./qti/init.xyz 300 @@ -729,7 +748,7 @@ def classical_harmonic_free_energy(Ws, T): - False + False 1.00 @@ -781,7 +800,7 @@ def classical_harmonic_free_energy(Ws, T): Q_duerr_list = [] Q_dir_list = ["0.0", "0.2", "0.4", "0.6", "0.8", "1.0"] -Q_l_list = [float(l) for l in Q_dir_list] +Q_l_list = [float(lst) for lst in Q_dir_list] for i in Q_dir_list: filename = f"qti_{i}.pots"