|
| 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 | +""" |
| 19 | +Here we load the primitive cell of Gold from a cif file. |
| 20 | +And we use CellConstructor to compute phonons from finite differences. |
| 21 | +The phonons are computed on a q-mesh 4x4x4 |
| 22 | +""" |
| 23 | + |
| 24 | +gold_structure = CC.Structure.Structure() |
| 25 | +gold_structure.read_generic_file("Au.cif") |
| 26 | + |
| 27 | +# Get the force field for gold |
| 28 | +calculator = EMT() |
| 29 | + |
| 30 | +# Relax the gold structure (useless since for symmetries it is already relaxed) |
| 31 | +relax = CC.calculators.Relax(gold_structure, calculator) |
| 32 | +gold_structure_relaxed = relax.static_relax() |
| 33 | + |
| 34 | +# Compute the harmonic phonons |
| 35 | +# NOTE: if the code is run with mpirun, the calculation goes in parallel |
| 36 | +gold_harmonic_dyn = CC.Phonons.compute_phonons_finite_displacements(gold_structure_relaxed, calculator, supercell = (4,4,4)) |
| 37 | + |
| 38 | +# Impose the symmetries and |
| 39 | +# save the dynamical matrix in the quantum espresso format |
| 40 | +gold_harmonic_dyn.Symmetrize() |
| 41 | +gold_harmonic_dyn.save_qe("harmonic_dyn") |
| 42 | + |
| 43 | + |
| 44 | +# If the dynamical matrix has imaginary frequencies, remove them |
| 45 | +gold_harmonic_dyn.ForcePositiveDefinite() |
| 46 | + |
| 47 | +""" |
| 48 | +gold_harmonic_dyn is ready to start the SSCHA calculation. |
| 49 | +
|
| 50 | +Now let us initialize the ensemble, and the calculation at 300 K. |
| 51 | +We will run a NVT calculation, using 100 configurations at each step |
| 52 | +""" |
| 53 | + |
| 54 | +TEMPERATURE = 300 |
| 55 | +N_CONFIGS = 50 |
| 56 | +MAX_ITERATIONS = 20 |
| 57 | + |
| 58 | +# Initialize the random ionic ensemble |
| 59 | +ensemble = sscha.Ensemble.Ensemble(gold_harmonic_dyn, TEMPERATURE) |
| 60 | + |
| 61 | +# Initialize the free energy minimizer |
| 62 | +minim = sscha.SchaMinimizer.SSCHA_Minimizer(ensemble) |
| 63 | +minim.set_minimization_step(0.01) |
| 64 | + |
| 65 | +# Initialize the NVT simulation |
| 66 | +relax = sscha.Relax.SSCHA(minim, calculator, N_configs = N_CONFIGS, |
| 67 | + max_pop = MAX_ITERATIONS) |
| 68 | + |
| 69 | +# Define the I/O operations |
| 70 | +# To save info about the free energy minimization after each step |
| 71 | +ioinfo = sscha.Utilities.IOInfo() |
| 72 | +ioinfo.SetupSaving("minim_info") |
| 73 | +relax.setup_custom_functions(custom_function_post = ioinfo.CFP_SaveAll) |
| 74 | + |
| 75 | + |
| 76 | +# Run the NVT simulation (save the stress to compute the pressure) |
| 77 | +relax.relax(get_stress = True) |
| 78 | + |
| 79 | +# If instead you want to run a NPT simulation, use |
| 80 | +# The target pressure is given in GPa. |
| 81 | +#relax.vc_relax(target_press = 0) |
| 82 | + |
| 83 | +# You can also run a mixed simulation (NVT) but with variable lattice parameters |
| 84 | +#relax.vc_relax(fix_volume = True) |
| 85 | + |
| 86 | +# Now we can save the final dynamical matrix |
| 87 | +# And print in stdout the info about the minimization |
| 88 | +relax.minim.finalize() |
| 89 | +relax.minim.dyn.save_qe("sscha_T{}_dyn".format(TEMPERATURE)) |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
0 commit comments