Skip to content

Commit 74061a6

Browse files
Merge pull request #148 from bastonero/examples/aiida
`Examples`: add a sscha-aiida example
2 parents 586cf88 + a694e5d commit 74061a6

2 files changed

Lines changed: 164 additions & 0 deletions

File tree

Examples/sscha_and_aiida/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Instructions
2+
3+
We provide here the script `run_aiida_sscha.py`, which performs a thermal expansion calculation using SSCHA and aiida-quantumespresso.
4+
5+
It is preferable to execute the example that you already have some experience with both the SSCHA and AiiDA-QuantumEspresso codes. Nevertheless, you can try following the instructions and to run the example.
6+
7+
## Installation
8+
9+
We recommend to install all the packages via `mamba` (which is based on top of `conda`). After having installed `mamba`, you can simply run the following:
10+
11+
```console
12+
> mamba create -n aiida-sscha -c conda-forge python gfortran libblas lapack openmpi julia openmpi-mpicc pip numpy scipy spglib aiida-core
13+
> pip install ase quippy-ase cellconstructor python-sscha aiida-quantumespresso aiida-pseudo
14+
> mamba activate aiida-sscha
15+
```
16+
17+
Then, you should configure an AiiDA profile in order to use the example script (see also Prerequisites section).
18+
19+
## Prerequisites
20+
21+
You need to have installed in the same environment:
22+
- `python-sscha`
23+
- `cellconstructor`
24+
- `aiida-core`
25+
- `aiida-quantumespresso`
26+
27+
For the AiiDA part, it is essential the dameon is running and you have:
28+
1. Configured a computer where to run the code (e.g. on your own laptop; see `aiida-core` docs for further details)
29+
2. Configured a code for the `pw.x` binary, related to the computer (see `aiida-quantumespresso` docs for further details)
30+
3. Installed a pseupopotentials library via `aiida-pseudo`. E.g. `aiida-pseudo install -x PBEsol -v 1.3`
31+
32+
Please refer to the aiida-core and aiida-quantumespresso for further installation instruction.
33+
34+
## How-to run
35+
36+
Open the `run_aiida_sscha.py` and change the data according to your needs and local installation. Then simply
37+
38+
```console
39+
> python run_aiida_sscha.py > run_aiida_sscha.log
40+
```
41+
42+
Usually an actual production run would take a while. We suggest to use instead
43+
44+
```console
45+
> nohup python run_aiida_sscha.py > run_aiida_sscha.log &
46+
```
47+
48+
or a submit script at glance.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)