Skip to content

Commit

Permalink
Merge branch 'master' into fix/test-aiida-sssp
Browse files Browse the repository at this point in the history
  • Loading branch information
mesonepigreco authored Feb 7, 2024
2 parents b174b3b + a048fa8 commit 45fa397
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 360 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/python-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.8]

services:
rabbitmq:
image: rabbitmq:latest
Expand All @@ -38,6 +38,7 @@ jobs:
pip install flake8 pytest~=6.0 pgtest~=1.3 aiida-core~=2.3 aiida-quantumespresso~=4.3
if [ ${{matrix.python-version}} -eq 2.7 ]; then pip install -r requirements2.txt;
else pip install -r requirements.txt; fi
aiida-pseudo install
- name: Lint with flake8
run: |
Expand All @@ -54,7 +55,7 @@ jobs:
cd CellConstructor
python setup.py install --user
cd ..
python setup.py install --user
# Install julia requirements
Expand Down
74 changes: 54 additions & 20 deletions Modules/AdvancedCalculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
This module contains useful functions to do post-processing analysis of the SSCHA.
For example, it implements custom cluster calculators to compute the electron-phonon effect on
absorbption and the bandgap.
absorption and the bandgap.
'''

Expand All @@ -23,7 +23,7 @@ class OpticalQECluster(sscha.Cluster.Cluster):
'''

def __init__(self, new_k_grid = None, random_offset = True, epsilon_data = None,
epsilon_binary = 'epsilon.x -npool NPOOL -i PREFIX.pwi > PREFIX.pwo',
epsilon_binary = 'epsilon.x -npool NPOOL -i PREFIX.pwi > PREFIX.pwo',
**kwargs):
'''
Initialize the cluster object.
Expand All @@ -40,7 +40,7 @@ def __init__(self, new_k_grid = None, random_offset = True, epsilon_data = None,
epsilon.x file
epsilon_binary : string
The path to the epsilon.x binary inside the cluster.
**kwargs :
**kwargs :
All other arguments to be passed to the cluster.
'''
Expand All @@ -67,7 +67,7 @@ def __init__(self, new_k_grid = None, random_offset = True, epsilon_data = None,
'wmax' : 40,
'nw' : 10000,
'temperature' : 300
}
}
}
if epsilon_data is not None:
self.epsilon_data = epsilon_data
Expand All @@ -79,10 +79,10 @@ def __setattr__(self, __name, __value):
super().__setattr__(__name, __value)

# Always regenerate the kpts
if __name == 'new_k_grid' and not __value is None:
if __name == 'new_k_grid' and not __value is None:
assert len(__value) == 3, 'Error, new_k_grid must be a tuple with 3 elements'
self.generate_kpts()


def generate_kpts(self):
'''
Expand Down Expand Up @@ -119,7 +119,7 @@ def get_execution_command(self, label):

# Get the MPI command replacing NPROC
new_mpicmd = self.mpi_cmd.replace("NPROC", str(self.n_cpu))

# Replace the NPOOL variable and the PREFIX in the binary
binary = self.binary.replace("NPOOL", str(self.n_pool)).replace("PREFIX", label)
binary_nscf = self.binary.replace("NPOOL", str(self.n_pool)).replace("PREFIX", label + '_nscf')
Expand Down Expand Up @@ -147,6 +147,18 @@ def get_execution_command(self, label):
def read_results(self, calc, label):
'''
Get the results
Parameters
----------
calc : the ASE or CellConstructor calculator.
In this case, it works with quantum espresso
labels : List of strings
The unique name of this calculation
Returns
-------
results : array
An array containing the real part of epsilon,
and the mean of the real and imaginary parst of epsilon.
'''

results = super().read_results(calc, label)
Expand Down Expand Up @@ -176,7 +188,31 @@ def read_results(self, calc, label):
def prepare_input_file(self, structures, calc, labels):
'''
Prepare the input files for the cluster
'''
This is specific for quantum espresso and must be inherit and replaced for
other calculators.
This crates the input files in the local working directory
self.local_workdir and it returns the list of all the files generated.
Parameters
----------
structures : List of cellconstructor.Structure.Structure
The atomic structures.
calc : the ASE or CellConstructor calculator.
In this case, it works with quantum espresso
labels : List of strings
The unique name of this calculation
Returns
-------
List_of_input : list
List of strings containing all the input files
List_of_output : list
List of strings containing the output files expected
for the calculation
'''


# Prepare the input file
Expand All @@ -185,7 +221,7 @@ def prepare_input_file(self, structures, calc, labels):
for i, (label, structure) in enumerate(zip(labels, structures)):
# Avoid thread conflict
self.lock.acquire()

try:
calc.set_directory(self.local_workdir)
PREFIX = label
Expand All @@ -204,7 +240,7 @@ def prepare_input_file(self, structures, calc, labels):
input_file = '{}.pwi'.format(label)
output_file = '{}.pwo'.format(label)

list_of_inputs.append(input_file)
list_of_inputs.append(input_file)
list_of_outputs.append(output_file)

# prepare the nscf calculation
Expand All @@ -218,7 +254,7 @@ def prepare_input_file(self, structures, calc, labels):
calc.write_input(structure)
input_file = '{}.pwi'.format(new_label)
output_file = '{}.pwo'.format(new_label)
list_of_inputs.append(input_file)
list_of_inputs.append(input_file)
list_of_outputs.append(output_file)


Expand All @@ -239,8 +275,8 @@ def prepare_input_file(self, structures, calc, labels):
print('fname: {} prepared'.format(eps_in_filename))


list_of_inputs.append(input_file)

list_of_inputs.append(input_file)
list_of_outputs.append(output_file)

# Append also the imaginary and real part of epsilon and sigma
Expand All @@ -263,11 +299,11 @@ def prepare_input_file(self, structures, calc, labels):
print(e)

# Release the lock on the threads
self.lock.release()
self.lock.release()

print('THREAD: {} inputs: {} outputs: {}'.format(threading.get_native_id(), list_of_inputs, list_of_outputs))


return list_of_inputs, list_of_outputs


Expand Down Expand Up @@ -306,7 +342,7 @@ def get_optical_spectrum(ensemble, w_array = None):
Error, the configuration {} has no 'epsilon' data.
""".format(i)
raise ValueError(ERR)

data = np.array(ensemble.all_properties[i]['epsilon'])

if w_data is None:
Expand All @@ -330,13 +366,11 @@ def get_optical_spectrum(ensemble, w_array = None):
kind = 'cubic', bounds_error = False, fill_value = 'extrapolate')
eps_imag = f_imag(w_array)
w_data = w_array

# Build the complex epsilon
epsilon = eps_real + 1j * eps_imag

# Build the refractive index
n = np.sqrt(epsilon)

return w_data, n


Loading

0 comments on commit 45fa397

Please sign in to comment.