Skip to content

Commit 2bb5323

Browse files
Merge branch 'master' into asr_1d
2 parents be9df67 + a708d2e commit 2bb5323

119 files changed

Lines changed: 130589 additions & 380 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/python-testsuite.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest
16-
16+
1717
strategy:
1818
matrix:
1919
python-version: [3.8]
20-
20+
2121
services:
2222
rabbitmq:
2323
image: rabbitmq:latest
@@ -38,6 +38,7 @@ jobs:
3838
pip install flake8 pytest~=6.0 pgtest~=1.3 aiida-core~=2.3 aiida-quantumespresso~=4.3
3939
if [ ${{matrix.python-version}} -eq 2.7 ]; then pip install -r requirements2.txt;
4040
else pip install -r requirements.txt; fi
41+
aiida-pseudo install
4142
4243
- name: Lint with flake8
4344
run: |
@@ -54,7 +55,7 @@ jobs:
5455
cd CellConstructor
5556
python setup.py install --user
5657
cd ..
57-
58+
5859
python setup.py install --user
5960
6061
# Install julia requirements

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing Guidelines
2+
3+
Welcome to python-sscha! We appreciate your interest in contributing. Below are the guidelines to contribute effectively to our codebase.
4+
5+
## Forking and Pull Requests
6+
7+
1. **Fork the Repository:** Start by forking the repository to your GitHub account. This creates a copy where you can make your changes.
8+
2. **Create a Branch:** Within your fork, create a new branch for your changes. This keeps the work organized and separate from the main codebase.
9+
3. **Open a Pull Request:** Once your changes are complete, open a pull request against the main repository. This is where your contributions will be reviewed before merging.
10+
11+
## Making Atomic Changes
12+
13+
- **Keep Changes Well-Localized:** Ensure that your changes are atomic. This means that each change should be self-contained and impact only a specific aspect of the code.
14+
- **Avoid Complete Rewrites:** Use existing code as a basis for your changes. Avoid rewriting everything or duplicating existing code unless absolutely necessary.
15+
- **Make use of CellConstructor** Most utility functions are implemented in CellConstructor, please, look into the code, specifically the Methods.py, Phonons.py and Structure.py to find helper and utility functions.
16+
- **Mind the final user** Do not expect the user to be an expert on what you are doing. Ideally, the final API for the user should be as much as black box as possible. Avoid making the user to do unit conversion from the standard SSCHA and CellConstructor units.
17+
- **Ensure backward compatibility** Its very bad if an user updates the code and they cannot reuse all their scripts. Ideally, your change shoud not break any existing feature or require the user to change their scripts.
18+
19+
## Adding Tests
20+
21+
- **Write Complete Tests:** For every edit or addition, include a complete test. This ensures that your changes work as expected and do not break existing functionality.
22+
- **Tests inside the tests/ directory** Look for examples on other tests. Include files to reproduce your tests. The tests must be quick to run, maximum few seconds.
23+
- **Run the testsuit yourself** You can install pytest and run all the tests yourself to ensure everything is working before opening the pull request.
24+
25+
## Documentation and Examples
26+
27+
- **Document Your Changes:** Clearly document any changes or additions you make to the codebase. This helps others understand what you've done and why. Use docstrings for functions! (we use reStructuredText .rst format)
28+
- **Provide Usage Examples:** Include examples demonstrating how to use the new implementations or changes. Put an example inside the Examples/ directory.
29+
- **Write a tutorial** The best way to have your pull request quickly merged into the main code is to write a usefull tutorial for users on how to use your new functionality.
30+
31+
By following these guidelines, you help maintain the quality and integrity of the SSCHA project. We look forward to your contributions!
32+

Modules/AdvancedCalculations.py

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
This module contains useful functions to do post-processing analysis of the SSCHA.
1212
1313
For example, it implements custom cluster calculators to compute the electron-phonon effect on
14-
absorbption and the bandgap.
14+
absorption and the bandgap.
1515
1616
'''
1717

@@ -23,7 +23,7 @@ class OpticalQECluster(sscha.Cluster.Cluster):
2323
'''
2424

2525
def __init__(self, new_k_grid = None, random_offset = True, epsilon_data = None,
26-
epsilon_binary = 'epsilon.x -npool NPOOL -i PREFIX.pwi > PREFIX.pwo',
26+
epsilon_binary = 'epsilon.x -npool NPOOL -i PREFIX.pwi > PREFIX.pwo',
2727
**kwargs):
2828
'''
2929
Initialize the cluster object.
@@ -40,7 +40,7 @@ def __init__(self, new_k_grid = None, random_offset = True, epsilon_data = None,
4040
epsilon.x file
4141
epsilon_binary : string
4242
The path to the epsilon.x binary inside the cluster.
43-
**kwargs :
43+
**kwargs :
4444
All other arguments to be passed to the cluster.
4545
4646
'''
@@ -67,7 +67,7 @@ def __init__(self, new_k_grid = None, random_offset = True, epsilon_data = None,
6767
'wmax' : 40,
6868
'nw' : 10000,
6969
'temperature' : 300
70-
}
70+
}
7171
}
7272
if epsilon_data is not None:
7373
self.epsilon_data = epsilon_data
@@ -79,10 +79,10 @@ def __setattr__(self, __name, __value):
7979
super().__setattr__(__name, __value)
8080

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

8787
def generate_kpts(self):
8888
'''
@@ -119,7 +119,7 @@ def get_execution_command(self, label):
119119

120120
# Get the MPI command replacing NPROC
121121
new_mpicmd = self.mpi_cmd.replace("NPROC", str(self.n_cpu))
122-
122+
123123
# Replace the NPOOL variable and the PREFIX in the binary
124124
binary = self.binary.replace("NPOOL", str(self.n_pool)).replace("PREFIX", label)
125125
binary_nscf = self.binary.replace("NPOOL", str(self.n_pool)).replace("PREFIX", label + '_nscf')
@@ -147,6 +147,18 @@ def get_execution_command(self, label):
147147
def read_results(self, calc, label):
148148
'''
149149
Get the results
150+
151+
Parameters
152+
----------
153+
calc : the ASE or CellConstructor calculator.
154+
In this case, it works with quantum espresso
155+
labels : List of strings
156+
The unique name of this calculation
157+
Returns
158+
-------
159+
results : array
160+
An array containing the real part of epsilon,
161+
and the mean of the real and imaginary parst of epsilon.
150162
'''
151163

152164
results = super().read_results(calc, label)
@@ -176,7 +188,31 @@ def read_results(self, calc, label):
176188
def prepare_input_file(self, structures, calc, labels):
177189
'''
178190
Prepare the input files for the cluster
179-
'''
191+
192+
This is specific for quantum espresso and must be inherit and replaced for
193+
other calculators.
194+
195+
This crates the input files in the local working directory
196+
self.local_workdir and it returns the list of all the files generated.
197+
198+
199+
Parameters
200+
----------
201+
structures : List of cellconstructor.Structure.Structure
202+
The atomic structures.
203+
calc : the ASE or CellConstructor calculator.
204+
In this case, it works with quantum espresso
205+
labels : List of strings
206+
The unique name of this calculation
207+
208+
Returns
209+
-------
210+
List_of_input : list
211+
List of strings containing all the input files
212+
List_of_output : list
213+
List of strings containing the output files expected
214+
for the calculation
215+
'''
180216

181217

182218
# Prepare the input file
@@ -185,7 +221,7 @@ def prepare_input_file(self, structures, calc, labels):
185221
for i, (label, structure) in enumerate(zip(labels, structures)):
186222
# Avoid thread conflict
187223
self.lock.acquire()
188-
224+
189225
try:
190226
calc.set_directory(self.local_workdir)
191227
PREFIX = label
@@ -204,7 +240,7 @@ def prepare_input_file(self, structures, calc, labels):
204240
input_file = '{}.pwi'.format(label)
205241
output_file = '{}.pwo'.format(label)
206242

207-
list_of_inputs.append(input_file)
243+
list_of_inputs.append(input_file)
208244
list_of_outputs.append(output_file)
209245

210246
# prepare the nscf calculation
@@ -218,7 +254,7 @@ def prepare_input_file(self, structures, calc, labels):
218254
calc.write_input(structure)
219255
input_file = '{}.pwi'.format(new_label)
220256
output_file = '{}.pwo'.format(new_label)
221-
list_of_inputs.append(input_file)
257+
list_of_inputs.append(input_file)
222258
list_of_outputs.append(output_file)
223259

224260

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

241277

242-
243-
list_of_inputs.append(input_file)
278+
279+
list_of_inputs.append(input_file)
244280
list_of_outputs.append(output_file)
245281

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

265301
# Release the lock on the threads
266-
self.lock.release()
302+
self.lock.release()
267303

268304
print('THREAD: {} inputs: {} outputs: {}'.format(threading.get_native_id(), list_of_inputs, list_of_outputs))
269-
270-
305+
306+
271307
return list_of_inputs, list_of_outputs
272308

273309

@@ -306,7 +342,7 @@ def get_optical_spectrum(ensemble, w_array = None):
306342
Error, the configuration {} has no 'epsilon' data.
307343
""".format(i)
308344
raise ValueError(ERR)
309-
345+
310346
data = np.array(ensemble.all_properties[i]['epsilon'])
311347

312348
if w_data is None:
@@ -330,13 +366,11 @@ def get_optical_spectrum(ensemble, w_array = None):
330366
kind = 'cubic', bounds_error = False, fill_value = 'extrapolate')
331367
eps_imag = f_imag(w_array)
332368
w_data = w_array
333-
369+
334370
# Build the complex epsilon
335371
epsilon = eps_real + 1j * eps_imag
336372

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

340376
return w_data, n
341-
342-

0 commit comments

Comments
 (0)