Skip to content

Commit 3e2f0b4

Browse files
committed
Refactor code for improved readability and consistency across multiple scripts
- Updated spacing and formatting in `franck_condon_model_system.py` for better clarity. - Enhanced function definition formatting in `gaussian_to_xyz.py` for improved readability. - Standardized spacing and comments in `matmul_method_slowest_2_fastest.py` to enhance code structure. - Added spacing in `monte_carlo_area_of_circle.py` for better visual separation of code blocks. - Improved formatting and spacing in `pca_program.py` for consistency and readability. - Refined spacing and comments in `pytorched_strassen_matmul.py` to enhance clarity and maintainability. - Standardized formatting and improved readability in `qmsolvet_to_strip_solvent.py` for better code organization.
1 parent 45123da commit 3e2f0b4

9 files changed

+595
-243
lines changed

align_spectra_with_offset.py

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
# The code creates a normalized plot using the matplotlib library in Python. It imports the necessary
22
# libraries (matplotlib.pyplot, numpy, and sys) and defines a conversion factor from inverse
3-
# centimeters to electron volts. Plots the reference data, which is the first argument and
4-
#, then plot the remaining spectra arguments 2 and onwards and align them with respect to the
5-
# desired offset. Here, it aligns with the first index of the x-axis of the reference data.
3+
# centimeters to electron volts. Plots the reference data, which is the first argument and
4+
# , then plot the remaining spectra arguments 2 and onwards and align them with respect to the
5+
# desired offset. Here, it aligns with the first index of the x-axis of the reference data.
66
import matplotlib.pyplot as plt
77
import numpy as np
88
import sys
99

10-
# Conversion factor
11-
invcm_to_eV = 1.0/8065.54429
10+
# Conversion factor
11+
invcm_to_eV = 1.0 / 8065.54429
1212
offset = int(0)
1313

1414
# Set up plot
15-
fig, axs = plt.subplots(1, 2, figsize=(10,5))
15+
fig, axs = plt.subplots(1, 2, figsize=(10, 5))
1616
filename = str(sys.argv[1])
17-
ref_data = np.loadtxt(f'{filename}', skiprows=7, usecols=(0,1,2))
18-
ref_data[:,0] = ref_data[:,0] * invcm_to_eV
17+
ref_data = np.loadtxt(f"{filename}", skiprows=7, usecols=(0, 1, 2))
18+
ref_data[:, 0] = ref_data[:, 0] * invcm_to_eV
1919

2020
# Plot reference
21-
axs[0].plot(ref_data[:,0], ref_data[:,1]/ref_data[:,1].max(), label='Explicit')
22-
axs[1].plot(ref_data[:,0], ref_data[:,2]/ref_data[:,2].max(), label='Explicit')
21+
axs[0].plot(ref_data[:, 0], ref_data[:, 1] / ref_data[:, 1].max(), label="Explicit")
22+
axs[1].plot(ref_data[:, 0], ref_data[:, 2] / ref_data[:, 2].max(), label="Explicit")
2323

24-
# Process each file provided as command line argument
24+
# Process each file provided as command line argument
2525
for i, filename in enumerate(sys.argv[2:]):
2626

2727
# Load data
28-
data = np.loadtxt(filename, skiprows=7, usecols=(0,1,2))
29-
28+
data = np.loadtxt(filename, skiprows=7, usecols=(0, 1, 2))
29+
3030
# Convert x-axis to eV
31-
data[:,0] = data[:,0] * invcm_to_eV
32-
31+
data[:, 0] = data[:, 0] * invcm_to_eV
32+
3333
# Normalize y-axis
34-
data[:,1] /= data[:,1].max()
35-
data[:,2] /= data[:,2].max()
34+
data[:, 1] /= data[:, 1].max()
35+
data[:, 2] /= data[:, 2].max()
3636

37-
label = f'File {i+1}'
37+
label = f"File {i+1}"
3838

3939
# Plot 0K data
4040
if i == 0:
41-
# Reference plot
42-
axs[0].plot(data[:,0], data[:,1], label=label)
41+
# Reference plot
42+
axs[0].plot(data[:, 0], data[:, 1], label=label)
4343
else:
44-
# Align to reference
45-
offset = data[offset,offset] - ref_data[offset,offset]
46-
axs[0].plot(data[:,0] - offset, data[:,1]/ref_data[0,1], label=label)
44+
# Align to reference
45+
offset = data[offset, offset] - ref_data[offset, offset]
46+
axs[0].plot(data[:, 0] - offset, data[:, 1] / ref_data[0, 1], label=label)
4747

4848
# Plot 300K data
4949
if i == 0:
50-
# Reference plot
51-
axs[1].plot(data[:,0], data[:,2], label=label)
50+
# Reference plot
51+
axs[1].plot(data[:, 0], data[:, 2], label=label)
5252
else:
53-
# Align to reference
54-
offset = data[0,0] - ref_data[0,0]
55-
axs[1].plot(data[:,0] - offset, data[:,2]/ref_data[0,2], label=label)
56-
57-
# Add axes labels
58-
axs[0].set_xlabel('Energy (eV)')
59-
axs[0].set_ylabel('Intensity')
60-
axs[1].set_xlabel('Energy (eV)')
61-
axs[1].set_ylabel('Intensity')
53+
# Align to reference
54+
offset = data[0, 0] - ref_data[0, 0]
55+
axs[1].plot(data[:, 0] - offset, data[:, 2] / ref_data[0, 2], label=label)
56+
57+
# Add axes labels
58+
axs[0].set_xlabel("Energy (eV)")
59+
axs[0].set_ylabel("Intensity")
60+
axs[1].set_xlabel("Energy (eV)")
61+
axs[1].set_ylabel("Intensity")
6262

6363
# Add legend
6464
axs[0].legend()
65-
axs[1].legend()
65+
axs[1].legend()
6666

6767
# Set axes limits
68-
axs[0].set_ylim(0, 1.1)
68+
axs[0].set_ylim(0, 1.1)
6969
axs[1].set_ylim(0, 1.1)
7070

7171
# Set number of ticks
72-
axs[0].locator_params(axis='x', nbins=5)
73-
axs[1].locator_params(axis='x', nbins=5)
72+
axs[0].locator_params(axis="x", nbins=5)
73+
axs[1].locator_params(axis="x", nbins=5)
7474

7575
# Save figure
7676
fig.tight_layout()
77-
fig.savefig('plot.png', dpi=300)
77+
fig.savefig("plot.png", dpi=300)

0 commit comments

Comments
 (0)