Skip to content

Commit

Permalink
CI: Enable flake8 for the scripts/ directory
Browse files Browse the repository at this point in the history
  • Loading branch information
BvB93 committed Aug 1, 2023
1 parent 3873ddf commit 131ee6c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:
run: pip list

- name: Run flake8
run: flake8 nanoqm test setup.py
run: flake8 nanoqm test setup.py scripts

- name: Run pydocstyle
run: pydocstyle nanoqm
Expand Down
6 changes: 4 additions & 2 deletions scripts/convert_legacy_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def copy_orbitals(self) -> None:
points = [k for k in self.source[self.project].keys() if k.startswith("point_")]
keys = {"coefficients", "eigenvalues", "energy"}
# "project/point_x/cp2k/mo/<coefficients,eigenvalues,energy>"
old_names = chain(*[[f"{self.project}/{point}/cp2k/mo/{k}" for point in points] for k in keys])
new_names = chain(*[[f"{k}/{point}" for point in points] for k in keys])
old_names = chain.from_iterable(
[f"{self.project}/{point}/cp2k/mo/{k}" for point in points] for k in keys
)
new_names = chain.from_iterable([f"{k}/{point}" for point in points] for k in keys)
self.copy_node_values(old_names, new_names)

def copy_couplings(self) -> None:
Expand Down
3 changes: 0 additions & 3 deletions scripts/hamiltonians/plot_mos_energies.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def read_cmd_line(parser: argparse.ArgumentParser) -> tuple[str, str, int, int,
Parse Command line options.
"""
args = parser.parse_args()

attributes = ['p', 'ts', 'ihomo', 'nhomos', 'nlumos']

return (args.p, args.ts, args.ihomo, args.nhomos, args.nlumos)


Expand Down
5 changes: 3 additions & 2 deletions scripts/pyxaid/iconds_excess_energy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#! /usr/bin/env python

"""
This program finds the indexes of the states for electron and hole cooling calculations (ONLY!)
extrapolated at a desired initial condition. It reads the me_energies0 file from pyxaid [at initial condition t=0].
This program finds the indexes of the states for electron and hole cooling calculations (ONLY!) \
extrapolated at a desired initial condition. It reads the me_energies0 file from \
pyxaid [at initial condition t=0].
Example:
Expand Down
45 changes: 34 additions & 11 deletions scripts/pyxaid/plot_cooling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""This program plots the average electronic energy during a NAMD simulation averaged over several initial conditions.
"""This program plots the average electronic energy during a NAMD simulation \
averaged over several initial conditions.
It plots both the SH and SE population based energies.
Expand Down Expand Up @@ -46,7 +47,11 @@ def plot_stuff(
plt.xlabel('Time (fs)')
plt.ylabel('Energy (eV)')
for iconds in range(nconds):
plt.imshow(y_grid[iconds, :, :].T, aspect='auto', extent=(0, len(ts)*dt, np.min(x_grid), np.max(x_grid)), origin='lower', interpolation='bicubic', cmap='hot')
plt.imshow(
y_grid[iconds, :, :].T, aspect='auto',
extent=(0, len(ts)*dt, np.min(x_grid), np.max(x_grid)),
origin='lower', interpolation='bicubic', cmap='hot',
)
plt.plot(ts * dt, w_en, 'w')
interactive(True)
plt.show()
Expand All @@ -55,7 +60,11 @@ def plot_stuff(
plt.xlabel('Time (fs)')
plt.ylabel('Excess Energy (eV)')
for iconds in range(nconds):
plt.imshow(y_grid_scaled[iconds, :, :].T, aspect='auto', extent=(0, len(ts)*dt, np.min(x_grid_scaled), np.max(x_grid_scaled)), origin='lower', interpolation='bicubic', cmap='hot')
plt.imshow(
y_grid_scaled[iconds, :, :].T, aspect='auto',
extent=(0, len(ts)*dt, np.min(x_grid_scaled), np.max(x_grid_scaled)),
origin='lower', interpolation='bicubic', cmap='hot',
)
plt.plot(ts * dt, w_en_scaled, 'w')
interactive(True)
plt.show()
Expand All @@ -64,7 +73,10 @@ def plot_stuff(
plt.xlabel('Time (fs)')
plt.ylabel('State Number')
for iconds in range(nconds):
plt.imshow(outs[:, :, iconds].T, aspect='auto', origin='lower', extent = ( 0, len(ts) * dt, 0, outs.shape[1]), interpolation='bicubic', cmap='hot')
plt.imshow(
outs[:, :, iconds].T, aspect='auto', origin='lower',
extent=(0, len(ts) * dt, 0, outs.shape[1]), interpolation='bicubic', cmap='hot'
)
interactive(True)
plt.show()

Expand Down Expand Up @@ -94,7 +106,11 @@ def plot_stuff(
plt.xlabel('Freqencies cm-1')
sd_int = sd[:, 0, :int(sd.shape[2]/2)]
sd_freq = sd[0, 1, :int(sd.shape[2]/2)]
plt.imshow(sd_int, aspect='auto', origin='lower', extent = (np.min(sd_freq), np.max(sd_freq), 0, sd_int.shape[0] ), interpolation='bicubic', cmap='hot')
plt.imshow(
sd_int, aspect='auto', origin='lower',
extent=(np.min(sd_freq), np.max(sd_freq), 0, sd_int.shape[0]),
interpolation='bicubic', cmap='hot',
)
interactive(False)
plt.show()

Expand All @@ -120,12 +136,16 @@ def main(path_output: str, nstates: int, nconds: int, dt: float, sigma: float) -
energies_scaled = np.stack([
energies[:, istate, :] - lowest_hl_gap for istate in range(nstates-1)
])
energies_scaled = energies_scaled.swapaxes(0,1) # Just reshape to have the energies shape (time, nstates, nconds)
# Just reshape to have the energies shape (time, nstates, nconds)
energies_scaled = energies_scaled.swapaxes(0, 1)
x_grid_scaled = np.linspace(0, np.max(energies_scaled), 100)
y_grid_scaled = np.stack([
np.stack([
convolute(energies_scaled[time, :, iconds], outs[time, :, iconds], x_grid_scaled, sigma)
for time in range(energies_scaled.shape[0])
convolute(
energies_scaled[time, :, iconds],
outs[time, :, iconds],
x_grid_scaled, sigma,
) for time in range(energies_scaled.shape[0])
]) for iconds in range(nconds)
])
# This part is done
Expand All @@ -135,9 +155,9 @@ def main(path_output: str, nstates: int, nconds: int, dt: float, sigma: float) -
el_ene_outs = np.sum(eav_outs, axis=1)
# Scale them to the lowest excitation energy
ene_outs_ref0 = el_ene_outs - lowest_hl_gap
#Average over initial conditions
# Average over initial conditions
ene_outs_ref0 = np.average(ene_outs_ref0, axis=1)
el_ene_av = np.average(el_ene_outs, axis = 1)
el_ene_av = np.average(el_ene_outs, axis=1)
##################################
# Compute autocorrelation function for consecutive pair of states
d_en = np.stack(
Expand All @@ -150,7 +170,10 @@ def main(path_output: str, nstates: int, nconds: int, dt: float, sigma: float) -
#################################
# Call plotting function
ts = np.arange(energies.shape[0])
plot_stuff(x_grid, y_grid, x_grid_scaled, y_grid_scaled, sd, el_ene_av, ene_outs_ref0, nconds, outs, energies, ts, dt)
plot_stuff(
x_grid, y_grid, x_grid_scaled, y_grid_scaled, sd, el_ene_av,
ene_outs_ref0, nconds, outs, energies, ts, dt,
)


def read_cmd_line(parser: argparse.ArgumentParser) -> tuple[str, int, int, float, float]:
Expand Down
2 changes: 1 addition & 1 deletion scripts/pyxaid/plot_spectra_pyxaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def main(path_output: str, s1: int, s2: int, dt: float, wsd: int, wdeph: int) ->
# Take the transpose to have the correct shape for spectral_density
acf = np.stack([autocorrelate(en_states[i, :]) for i in range(en_states.shape[0])]).T
# Compute the spectral density for each column using the normalized acf
sd = np.stack([spectral_density(acf[:, 1, i], dt) for i in range(en_states.shape[0])])
sd = np.stack([spectral_density(acf[:, 1, i], dt) for i in range(en_states.shape[0])])
# Compute the dephasing time for the uncorrelated acf between two states
deph, rate = dephasing(acf[:, 0, 2], dt)
# Plot stuff
Expand Down
6 changes: 4 additions & 2 deletions scripts/qmflows/convolution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python
""" This script convolutes the calculated oscillator strengts for different snapshots in a MD trajectory and plot the average spectrum.
""" This script convolutes the calculated oscillator strengts for different snapshots \
in a MD trajectory and plot the average spectrum.
Usage:
convolution.py -sigma 0.05 -n 2 -nm True -write True
Expand Down Expand Up @@ -94,7 +95,8 @@ def read_cmd_line(parser) -> tuple[float, int, bool, bool]:
# ============<>===============
if __name__ == "__main__":

msg = """convolution.py -sigma <sigma parameter of the gaussian functions> -n <plot only the spectrum of structure n>
msg = """convolution.py -sigma <sigma parameter of the gaussian functions> \
-n <plot only the spectrum of structure n> \
-nm <plot in nm> -write <write the coordinates from the convolution>"""

parser = argparse.ArgumentParser(description=msg)
Expand Down
8 changes: 7 additions & 1 deletion scripts/qmflows/coordination_ldos.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ def create_ldos_lists(coord: NestedDict) -> Settings:
return s


def compute_ldos(mol: Molecule, coord: NestedDict, name: str, workdir: str, path_results: str) -> None:
def compute_ldos(
mol: Molecule,
coord: NestedDict,
name: str,
workdir: str,
path_results: str,
) -> None:
"""Compute the DOS projected on subsets of atoms given through lists.
These lists are divided by atom type and coordination number.
Expand Down
3 changes: 2 additions & 1 deletion scripts/qmflows/dos_cp2k.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python
"""This programs performs a density of states (DOS) calculation with cp2k using generic settings, i.e. DFT/PBE
"""This programs performs a density of states (DOS) calculation with cp2k \
using generic settings, i.e. DFT/PBE
Note that is mandatory to define a cell_parameter, and a xyz structure.
If you have a restart file, a basis set and you can also define it
Expand Down

0 comments on commit 131ee6c

Please sign in to comment.