|
| 1 | +# Import the sscha code |
| 2 | +import sscha, sscha.Ensemble, sscha.SchaMinimizer, sscha.Relax, sscha.Utilities |
| 3 | + |
| 4 | +# Import the cellconstructor library to manage phonons |
| 5 | +import cellconstructor as CC, cellconstructor.Phonons |
| 6 | +import cellconstructor.Structure, cellconstructor.calculators |
| 7 | + |
| 8 | +# Import the force field of Gold |
| 9 | +import ase, ase.calculators |
| 10 | +from ase.calculators.emt import EMT |
| 11 | + |
| 12 | +# Import numerical and general pourpouse libraries |
| 13 | +import numpy as np, matplotlib.pyplot as plt |
| 14 | +import sys, os |
| 15 | + |
| 16 | + |
| 17 | +""" |
| 18 | +You need first to run the |
| 19 | +get_gold_free_energy.py |
| 20 | +
|
| 21 | +Here we use NPT simulation to compute the gold thermal expansion. |
| 22 | +""" |
| 23 | + |
| 24 | +# Define the temperature range (in K) |
| 25 | +T_START = 300 |
| 26 | +T_END = 1000 |
| 27 | +DT = 50 |
| 28 | + |
| 29 | +N_CONFIGS = 50 |
| 30 | +MAX_ITERATIONS = 10 |
| 31 | + |
| 32 | +# Import the gold force field |
| 33 | +calculator = EMT() |
| 34 | + |
| 35 | +# Import the starting dynamical matrix (final result of get_gold_free_energy.py) |
| 36 | +dyn = CC.Phonons.Phonons("sscha_T300_dyn", nqirr = 13) |
| 37 | + |
| 38 | +# Create the directory on which to store the output |
| 39 | +DIRECTORY = "thermal_expansion" |
| 40 | +if not os.path.exists(DIRECTORY): |
| 41 | + os.makedirs("thermal_expansion") |
| 42 | + |
| 43 | +# We cycle over several temperatures |
| 44 | +t = T_START |
| 45 | + |
| 46 | + |
| 47 | +volumes = [] |
| 48 | +temperatures = [] |
| 49 | +while t <= T_END: |
| 50 | + # Change the temperature |
| 51 | + ensemble = sscha.Ensemble.Ensemble(dyn, t) |
| 52 | + minim = sscha.SchaMinimizer.SSCHA_Minimizer(ensemble) |
| 53 | + minim.set_minimization_step(0.1) |
| 54 | + |
| 55 | + relax = sscha.Relax.SSCHA(minim, calculator, N_configs = N_CONFIGS, |
| 56 | + max_pop = MAX_ITERATIONS) |
| 57 | + |
| 58 | + # Setup the I/O |
| 59 | + ioinfo = sscha.Utilities.IOInfo() |
| 60 | + ioinfo.SetupSaving( os.path.join(DIRECTORY, "minim_t{}".format(t))) |
| 61 | + relax.setup_custom_functions( custom_function_post = ioinfo.CFP_SaveAll) |
| 62 | + |
| 63 | + |
| 64 | + # Run the NPT simulation |
| 65 | + relax.vc_relax(target_press = 0) |
| 66 | + |
| 67 | + # Save the volume and temperature |
| 68 | + volumes.append(relax.minim.dyn.structure.get_volume()) |
| 69 | + temperatures.append(t) |
| 70 | + |
| 71 | + # Start the next simulation from the results |
| 72 | + relax.minim.dyn.save_qe( os.path.join(DIRECTORY, "sscha_T{}_dyn".format(t))) |
| 73 | + dyn = relax.minim.dyn |
| 74 | + relax.minim.finalize() |
| 75 | + |
| 76 | + # Update the temperature |
| 77 | + t += DT |
| 78 | + |
| 79 | +# Save the thermal expansion |
| 80 | +np.savetxt(os.path.join(DIRECTORY, "thermal_expansion.dat"), |
| 81 | + np.transpose([temperatures, volumes]), |
| 82 | + header = "Temperature [K]; Volume [A^3]") |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
0 commit comments