1+ """Example of an actual AiiDA-powered SSCHA run."""
2+ import os
3+ import numpy as np
4+
5+ from cellconstructor .Phonons import Phonons
6+ from sscha .aiida_ensemble import AiiDAEnsemble
7+ from sscha .SchaMinimizer import SSCHA_Minimizer
8+ from sscha .Relax import SSCHA
9+ from sscha .Utilities import IOInfo
10+
11+ from aiida import load_profile
12+
13+ from aiida_quantumespresso .common .types import ElectronicType
14+
15+ load_profile ()
16+
17+ # =========== DEFINITION OF INPUTS =============== #
18+ np .random .seed (0 )
19+ # Define the temperature range (in K)
20+ t_start = 300
21+ t_end = 800
22+ delta_t = 50
23+ target_pressure = 0
24+ number_q_irreducible = 4
25+ kpoints_distance = 0.4 # kpoints mesh
26+ number_of_configurations = 100
27+ max_iterations = 15
28+ data_directory = './minimization'
29+ pw_code_label = 'pw_7.2@hlrn-gottingen'
30+ dyn_filepath = './harmonic_dyn/dynamical-matrix-'
31+ directory_output = "./thermal_expansion"
32+
33+ aiida_inputs = dict (
34+ pw_code_label = pw_code_label ,
35+ protocol = 'precise' ,
36+ overrides = {
37+ 'pseudo_family' : 'SSSP/1.3/PBEsol/precision' ,
38+ 'kpoints_distance' : 0.4 ,
39+ 'pw' :{
40+ 'parameters' :{
41+ 'SYSTEM' :{
42+ # ...
43+ },
44+ 'ELECTRONS' :{
45+ 'mixing_beta' : 0.7
46+ },
47+ },
48+ 'settings' :{
49+ 'cmdline' : ['-nk' , '8' ]
50+ },
51+ }
52+ },
53+ options = {
54+ 'resources' :{
55+ 'num_machines' : 1 ,
56+ 'num_mpiprocs_per_machine' : 96 ,
57+ 'num_cores_per_mpiproc' : 1
58+ },
59+ # 'account': 'myproject',
60+ 'max_wallclock_seconds' : int (1 * 60 * 60 ),
61+ },
62+ electronic_type = ElectronicType .INSULATOR ,
63+ # group_label='Group/Where/To/Add/PwNodes', # You need to create it first
64+ )
65+ # =========== DEFINITION OF INPUTS =============== #
66+
67+ dyn = Phonons (dyn_filepath , number_q_irreducible )
68+ dyn .ForcePositiveDefinite ()
69+ dyn .Symmetrize ()
70+
71+ if not os .path .exists (directory_output ):
72+ os .makedirs ("./thermal_expansion" )
73+
74+ # We cycle over several temperatures
75+ t = t_start
76+ volumes = []
77+ temperatures = []
78+
79+ while t <= t_end :
80+ # Change the temperature
81+ ensemble = AiiDAEnsemble (dyn , t )
82+ minim = SSCHA_Minimizer (ensemble )
83+ minim .set_minimization_step (0.1 )
84+ relax = SSCHA (
85+ minimizer = minim ,
86+ aiida_inputs = aiida_inputs ,
87+ N_configs = number_of_configurations ,
88+ max_pop = max_iterations ,
89+ save_ensemble = True ,
90+ )
91+ # Setup the I/O
92+
93+ ioinfo = IOInfo ()
94+ ioinfo .SetupSaving ( os .path .join (directory_output , "minim_t{}" .format (t )))
95+ relax .setup_custom_functions ( custom_function_post = ioinfo .CFP_SaveAll )
96+ # Run the NPT simulation
97+ relax .vc_relax (
98+ target_press = target_pressure ,
99+ restart_from_ens = False ,
100+ ensemble_loc = f'ensembles_T{ t } '
101+ )
102+
103+ # Save the volume and temperature
104+ volumes .append (relax .minim .dyn .structure .get_volume ())
105+ temperatures .append (t )
106+ # Start the next simulation from the converged value at this temperature
107+ relax .minim .dyn .save_qe (os .path .join (directory_output , f"sscha_T{ t } _dyn" ))
108+ dyn = relax .minim .dyn
109+ # Print in standard output
110+ relax .minim .finalize ()
111+ # Update the temperature
112+ t += delta_t
113+ # Save the thermal expansion
114+ np .savetxt (os .path .join (directory_output , "thermal_expansion.dat" ),
115+ np .transpose ([temperatures , volumes ]),
116+ header = "Temperature [K]; Volume [A^3]" )
0 commit comments