|
| 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 DFT calculator |
| 9 | +import cellconstructor.calculators |
| 10 | + |
| 11 | +# Import numerical and general pourpouse libraries |
| 12 | +import numpy as np, matplotlib.pyplot as plt |
| 13 | +import sys, os |
| 14 | + |
| 15 | + |
| 16 | +# Initialize the DFT (Quantum Espresso) calculator for gold |
| 17 | +# The input data is a dictionary that encodes the pw.x input file namelist |
| 18 | +input_data = { |
| 19 | + 'control' : { |
| 20 | + # Avoid writing wavefunctions on the disk |
| 21 | + 'disk_io' : 'None', |
| 22 | + # Where to find the pseudopotential |
| 23 | + 'pseudo_dir' : '.' |
| 24 | + }, |
| 25 | + 'system' : { |
| 26 | + # Specify the basis set cutoffs |
| 27 | + 'ecutwfc' : 45, # Cutoff for wavefunction |
| 28 | + 'ecutrho' : 45*4, # Cutoff for the density |
| 29 | + # Information about smearing (it is a metal) |
| 30 | + 'occupations' : 'smearing', |
| 31 | + 'smearing' : 'mv', |
| 32 | + 'degauss' : 0.03 |
| 33 | + }, |
| 34 | + 'electrons' : { |
| 35 | + 'conv_thr' : 1e-8 |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +# the pseudopotential for each chemical element |
| 40 | +# In this case just Gold |
| 41 | +pseudopotentials = {'Au' : 'Au_ONCV_PBE-1.0.oncvpsp.upf'} |
| 42 | + |
| 43 | +# the kpoints mesh and the offset |
| 44 | +kpts = (1,1,1) |
| 45 | +koffset = (1,1,1) |
| 46 | + |
| 47 | +command = 'mpirun -np 4 pw.x -npool 1 -i PREFIX.pwi > PREFIX.pwo' |
| 48 | + |
| 49 | +# Prepare the quantum espresso calculator |
| 50 | +calculator = CC.calculators.Espresso(input_data, |
| 51 | + pseudopotentials, |
| 52 | + command = command, |
| 53 | + kpts = kpts, |
| 54 | + koffset = koffset) |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +TEMPERATURE = 300 |
| 59 | +N_CONFIGS = 50 |
| 60 | +MAX_ITERATIONS = 20 |
| 61 | +START_DYN = 'start_dyn' |
| 62 | +NQIRR = 13 |
| 63 | + |
| 64 | +# Let us load the starting dynamical matrix |
| 65 | +gold_dyn = CC.Phonons.Phonons(START_DYN, NQIRR) |
| 66 | + |
| 67 | +# Initialize the random ionic ensemble |
| 68 | +ensemble = sscha.Ensemble.Ensemble(gold_dyn, TEMPERATURE) |
| 69 | + |
| 70 | +# Initialize the free energy minimizer |
| 71 | +minim = sscha.SchaMinimizer.SSCHA_Minimizer(ensemble) |
| 72 | +minim.set_minimization_step(0.01) |
| 73 | + |
| 74 | +# Initialize the NVT simulation |
| 75 | +relax = sscha.Relax.SSCHA(minim, calculator, N_configs = N_CONFIGS, |
| 76 | + max_pop = MAX_ITERATIONS) |
| 77 | + |
| 78 | +# Define the I/O operations |
| 79 | +# To save info about the free energy minimization after each step |
| 80 | +ioinfo = sscha.Utilities.IOInfo() |
| 81 | +ioinfo.SetupSaving("minim_info") |
| 82 | +relax.setup_custom_functions(custom_function_post = ioinfo.CFP_SaveAll) |
| 83 | + |
| 84 | + |
| 85 | +# Run the NVT simulation (save the stress to compute the pressure) |
| 86 | +relax.relax(get_stress = True) |
| 87 | + |
| 88 | +# If instead you want to run a NPT simulation, use |
| 89 | +# The target pressure is given in GPa. |
| 90 | +#relax.vc_relax(target_press = 0) |
| 91 | + |
| 92 | +# You can also run a mixed simulation (NVT) but with variable lattice parameters |
| 93 | +#relax.vc_relax(fix_volume = True) |
| 94 | + |
| 95 | +# Now we can save the final dynamical matrix |
| 96 | +# And print in stdout the info about the minimization |
| 97 | +relax.minim.finalize() |
| 98 | +relax.minim.dyn.save_qe("sscha_T{}_dyn".format(TEMPERATURE)) |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
0 commit comments