Skip to content

Commit 172ef45

Browse files
committed
Added a simple example to compute the free energy of Gold
1 parent 81d743c commit 172ef45

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# generated using pymatgen
2+
data_Au
3+
_symmetry_space_group_name_H-M 'P 1'
4+
_cell_length_a 2.94954603
5+
_cell_length_b 2.94954603
6+
_cell_length_c 2.94954603
7+
_cell_angle_alpha 60.00000000
8+
_cell_angle_beta 60.00000000
9+
_cell_angle_gamma 60.00000000
10+
_symmetry_Int_Tables_number 1
11+
_chemical_formula_structural Au
12+
_chemical_formula_sum Au1
13+
_cell_volume 18.14473112
14+
_cell_formula_units_Z 1
15+
loop_
16+
_symmetry_equiv_pos_site_id
17+
_symmetry_equiv_pos_as_xyz
18+
1 'x, y, z'
19+
loop_
20+
_atom_site_type_symbol
21+
_atom_site_label
22+
_atom_site_symmetry_multiplicity
23+
_atom_site_fract_x
24+
_atom_site_fract_y
25+
_atom_site_fract_z
26+
_atom_site_occupancy
27+
Au Au0 1 0.00000000 0.00000000 0.00000000 1
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)