diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 4609b18..5a8b51e 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -1,6 +1,10 @@ -name: Code quality +name: Code Quality -on: [push, pull_request] +on: + push: + branches: [master, main, development] + pull_request: + branches: [master, main, development] jobs: build: @@ -18,27 +22,13 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install black pylint pytest coverage coveralls - pip install -r requirements/requirements.txt - - - name: Run black - continue-on-error: true - run: black --check . + pip install black pylint - name: Run lint with pylint continue-on-error: true run: | - find qDNA tools -type f -name "*.py" ! -name "__init__.py" | xargs pylint - - - name: Run tests with pytest - run: python -m pytest + pylint --rcfile=.pylintrc $(git ls-files 'qDNA/*.py') - - name: Run tests with coverage - run: | - coverage run -m pytest - - - name: Upload coverage to Coveralls + - name: Run black continue-on-error: true - env: - COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} - run: coveralls + run: black --check . diff --git a/.gitignore b/.gitignore index 6102e88..cc1591d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,6 @@ docs/_templates/ __pycache__ .pytest_cache/ -# created for pylint -.pylintrc - # created by coverage .coverage htmlcov/ diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..a6a44dd --- /dev/null +++ b/.pylintrc @@ -0,0 +1,57 @@ +[MASTER] +ignore=tests +jobs=1 +load-plugins= +extension-pkg-whitelist= + +[MESSAGES CONTROL] +disable= + C0114, # missing-module-docstring + C0116, # missing-function-docstring + C0301, # line-too-long + R0903, # too-few-public-methods + R0801, # duplicate-code + W0511, # fixme + R0902, # too-many-instance-attributes + R0912, # too-many-branches + R0913, # too-many-arguments + R0914, # too-many-locals + R0915, # too-many-statements + R0917, # too-many-positional-arguments + R0401, # cyclic-import + E0401, # import-error + +[REPORTS] +output-format=colorized +reports=no +score=yes + +[BASIC] +good-names= +bad-names= +variable-rgx=.* +attr-rgx=.* +argument-rgx=.* +method-rgx=.* +module-rgx=.* +class-rgx=.* +function-rgx=.* + + +[TYPECHECK] +ignored-modules= +ignored-classes=optparse.Values,thread._local,_thread._local +generated-members=numpy.*,torch.* + +[FORMAT] +max-line-length=120 +indent-string=' ' + +[DESIGN] +max-args=7 +max-attributes=10 +max-locals=20 +max-returns=6 +max-branches=12 +max-statements=50 +max-line-length=100 diff --git a/docs/conf.py b/docs/conf.py index 791df14..c45416c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,9 +50,7 @@ # Do not add full module names add_module_names = False -numpydoc_show_inherited_class_members = ( - False # Show inherited class members in the documentation -) +numpydoc_show_inherited_class_members = False # Show inherited class members in the documentation numpydoc_show_property_with_doc = ( False # Show properties with documentation in the class documentation ) diff --git a/pyproject.toml b/pyproject.toml index 3982e6e..81a652b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,6 @@ requires = ["setuptools>=61.0", "wheel"] build-backend = "setuptools.build_meta" [tool.black] -line-length = 120 +line-length = 100 target-version = ['py311'] skip-string-normalization = true diff --git a/qDNA/__init__.py b/qDNA/__init__.py index b72e2c6..e40b7cc 100644 --- a/qDNA/__init__.py +++ b/qDNA/__init__.py @@ -18,5 +18,3 @@ from .evaluation import * from .visualization import * from .legacy import * - -# some nice comment... diff --git a/qDNA/environment/observables.py b/qDNA/environment/observables.py index 2b5d2de..d947ef3 100644 --- a/qDNA/environment/observables.py +++ b/qDNA/environment/observables.py @@ -124,15 +124,11 @@ def get_eh_observable(tb_basis, particle, start_state, end_state): # Create the electron observable if particle == "electron": - eh_observable = np.kron( - get_observable(tb_basis, start_state, end_state), np.eye(num_sites) - ) + eh_observable = np.kron(get_observable(tb_basis, start_state, end_state), np.eye(num_sites)) # Create the hole observable elif particle == "hole": - eh_observable = np.kron( - np.eye(num_sites), get_observable(tb_basis, start_state, end_state) - ) + eh_observable = np.kron(np.eye(num_sites), get_observable(tb_basis, start_state, end_state)) # Create the exciton observable elif particle == "exciton": diff --git a/qDNA/environment/therm_ops.py b/qDNA/environment/therm_ops.py index edd5a40..f7f1d1f 100644 --- a/qDNA/environment/therm_ops.py +++ b/qDNA/environment/therm_ops.py @@ -106,11 +106,7 @@ def get_loc_therm_op(eigv, eigs, unique, site_m, relaxation, matrix_dim): omega_i, omega_j = eigv[i], eigv[j] state_i, state_j = eigs[:, i], eigs[:, j] if omega_i - omega_j == unique: - op += ( - state_j[site_m].conjugate() - * state_i[site_m] - * np.outer(state_j, state_i) - ) + op += state_j[site_m].conjugate() * state_i[site_m] * np.outer(state_j, state_i) if relaxation: op = add_groundstate(op) diff --git a/qDNA/environment/therm_rates.py b/qDNA/environment/therm_rates.py index f7823fc..3ea4d5e 100644 --- a/qDNA/environment/therm_rates.py +++ b/qDNA/environment/therm_rates.py @@ -53,9 +53,7 @@ def ohmic_spectral_density(omega, cutoff_freq, reorg_energy, exponent): """ if omega <= 0: return 0 - return (np.pi * reorg_energy * omega**exponent / cutoff_freq) * np.exp( - -omega / cutoff_freq - ) + return (np.pi * reorg_energy * omega**exponent / cutoff_freq) * np.exp(-omega / cutoff_freq) # ---------------------------------------------------------------------- @@ -76,9 +74,7 @@ def bose_einstein_distrib(omega, temperature): float Bose-Einstein distribution. """ - assert ( - temperature != 0 and omega != 0 - ), "Temperature and frequency must be non-zero." + assert temperature != 0 and omega != 0, "Temperature and frequency must be non-zero." return 1.0 / (np.exp(c.hbar * omega * 1e12 / (c.k * temperature)) - 1) @@ -142,12 +138,8 @@ def rate_constant_redfield( spec_omega_ji = debye_spectral_density(-omega, cutoff_freq, reorg_energy) elif spectral_density == "ohmic": - spec_omega_ij = ohmic_spectral_density( - omega, cutoff_freq, reorg_energy, exponent - ) - spec_omega_ji = ohmic_spectral_density( - -omega, cutoff_freq, reorg_energy, exponent - ) + spec_omega_ij = ohmic_spectral_density(omega, cutoff_freq, reorg_energy, exponent) + spec_omega_ji = ohmic_spectral_density(-omega, cutoff_freq, reorg_energy, exponent) n_omega_ij = bose_einstein_distrib(omega, temperature) n_omega_ji = bose_einstein_distrib(-omega, temperature) diff --git a/qDNA/evaluation/evaluation.py b/qDNA/evaluation/evaluation.py index 7a37615..965fe44 100644 --- a/qDNA/evaluation/evaluation.py +++ b/qDNA/evaluation/evaluation.py @@ -78,9 +78,7 @@ def calc_lifetime(self): start_time = time.time() gs_pop = self.get_groundstate_pop()["groundstate"] try: - _, index = next( - (val, i) for i, val in enumerate(gs_pop) if val >= 1 - 1 / np.e - ) + _, index = next((val, i) for i, val in enumerate(gs_pop) if val >= 1 - 1 / np.e) self.lifetime = self.times[index] if self.t_unit == "ps": self.lifetime *= 1000 @@ -136,9 +134,7 @@ def calc_charge_separation(self, average=True): # Calculate the electron-hole distance distance_list = 3.4 * get_eh_distance(self.eh_basis) - self.charge_separation = [ - distance_list @ dm.diag()[1:] for dm in self.get_result() - ] + self.charge_separation = [distance_list @ dm.diag()[1:] for dm in self.get_result()] if average: self.charge_separation = np.mean(self.charge_separation).real return self.charge_separation @@ -203,9 +199,7 @@ def calc_backbone_transfer(self, average=True): If the backbone attribute is not set, indicating the model is not a Fishbone model. """ - assert ( - self.backbone - ), "Backbone population can only be calculated for Fishbone models" + assert self.backbone, "Backbone population can only be calculated for Fishbone models" self._back_to_unitary() upper_backbone_sites, lower_backbone_sites = [], [] @@ -250,9 +244,7 @@ def calc_exciton_transfer(self, average=True): assert ( self.double_stranded ), "Exciton transfer can only be calculated for double-stranded models" - assert ( - not self.backbone - ), "Exciton transfer can only be calculated for non-backbone models" + assert not self.backbone, "Exciton transfer can only be calculated for non-backbone models" self._back_to_unitary() upper_sites, lower_sites = [], [] @@ -334,10 +326,7 @@ def __init__(self, evaluation_list, **kwargs): "observables", ["lifetime", "charge_separation", "dipole_moment"] ) - self.args = [ - (i, self.observables, self.evaluation_list) - for i in range(self.num_sequences) - ] + self.args = [(i, self.observables, self.evaluation_list) for i in range(self.num_sequences)] def calc_results(self, filepath=None, save=True): """ diff --git a/qDNA/gui/advanced_frame.py b/qDNA/gui/advanced_frame.py index e8fb452..f889808 100644 --- a/qDNA/gui/advanced_frame.py +++ b/qDNA/gui/advanced_frame.py @@ -54,15 +54,11 @@ def __init__(self, master): super().__init__(master) # help label - self.help_label = ctk.CTkLabel( - self, text="Help", font=ctk.CTkFont(size=15, weight="bold") - ) + self.help_label = ctk.CTkLabel(self, text="Help", font=ctk.CTkFont(size=15, weight="bold")) self.help_label.grid(row=0, column=0, pady=10, padx=10) # github link - self.open_github_button = ctk.CTkButton( - self, text="GitHub", command=master.open_github - ) + self.open_github_button = ctk.CTkButton(self, text="GitHub", command=master.open_github) self.open_github_button.grid(row=1, column=0, pady=10, padx=10) # documentation link diff --git a/qDNA/gui/fasta_window.py b/qDNA/gui/fasta_window.py index a1289b9..b1bba36 100644 --- a/qDNA/gui/fasta_window.py +++ b/qDNA/gui/fasta_window.py @@ -98,9 +98,7 @@ def __init__(self, master): text="Calculate Exciton Population", variable=self.exciton_transfer_var, ) - self.exciton_transfer_checkbox.grid( - row=3, column=1, padx=10, pady=10, sticky="w" - ) + self.exciton_transfer_checkbox.grid(row=3, column=1, padx=10, pady=10, sticky="w") # -------------------------------------------------------------- @@ -113,12 +111,8 @@ def __init__(self, master): ) # submit button - self.submit_button = ctk.CTkButton( - self, text="Submit", command=self.process_files - ) - self.submit_button.grid( - row=5, column=0, columnspan=2, padx=10, pady=10, sticky="ew" - ) + self.submit_button = ctk.CTkButton(self, text="Submit", command=self.process_files) + self.submit_button.grid(row=5, column=0, columnspan=2, padx=10, pady=10, sticky="ew") # console frame self.scrollable_console_frame = ScrollableConsoleFrame(self) @@ -183,10 +177,7 @@ def estimate_comp_time(self): for upper_strand in self.upper_strands: comp_time += comp_time_dict[self.tb_model_name][len(upper_strand) - 2] comp_time /= min(self.num_cpu, len(self.upper_strands)) - print( - f"Estimated Computation Time {comp_time}" - + f"\nUsing {self.num_cpu} kernels" - ) + print(f"Estimated Computation Time {comp_time}" + f"\nUsing {self.num_cpu} kernels") # ------------------------------------------------------------------ @@ -213,9 +204,7 @@ def process_files(self): tb_sites = get_tb_sites(upper_strand, tb_model_name=self.tb_model_name) tb_sites_list.append(tb_sites) - evaluation_list = [ - Evaluation(tb_sites, **self.kwargs) for tb_sites in tb_sites_list - ] + evaluation_list = [Evaluation(tb_sites, **self.kwargs) for tb_sites in tb_sites_list] parallel = EvaluationParallel(evaluation_list, observables=observables) results = parallel.calc_results( filepath=os.path.join(DATA_DIR, "gui", "result.json"), save=True diff --git a/qDNA/gui/gui_utils.py b/qDNA/gui/gui_utils.py index 6fc2f9d..a5d93be 100644 --- a/qDNA/gui/gui_utils.py +++ b/qDNA/gui/gui_utils.py @@ -7,13 +7,9 @@ def change_state_all_widgets(frame, state): for widget in frame.winfo_children(): - if isinstance( - widget, ctk.CTkBaseClass - ): # Check if the widget is a customtkinter widget + if isinstance(widget, ctk.CTkBaseClass): # Check if the widget is a customtkinter widget widget.configure(state=state) - elif isinstance( - widget, ctk.CTkFrame - ): # Recursively disable widgets in nested frames + elif isinstance(widget, ctk.CTkFrame): # Recursively disable widgets in nested frames change_state_all_widgets(widget, state) diff --git a/qDNA/gui/initial_frame.py b/qDNA/gui/initial_frame.py index b051eab..d609af9 100644 --- a/qDNA/gui/initial_frame.py +++ b/qDNA/gui/initial_frame.py @@ -37,9 +37,7 @@ def __init__(self, master): # -------------------------------------------------------------- # upper strand label - self.upper_strand_label = ctk.CTkLabel( - self, text="Upper DNA Strand \n(5'-3' direction):" - ) + self.upper_strand_label = ctk.CTkLabel(self, text="Upper DNA Strand \n(5'-3' direction):") self.upper_strand_label.grid(row=2, column=0, pady=0, padx=10) # upper strand entry @@ -50,9 +48,7 @@ def __init__(self, master): # -------------------------------------------------------------- # lower strand label - self.lower_strand_label = ctk.CTkLabel( - self, text="Lower DNA Strand \n(3'-5' direction):" - ) + self.lower_strand_label = ctk.CTkLabel(self, text="Lower DNA Strand \n(3'-5' direction):") self.lower_strand_label.grid(row=4, column=0, pady=0, padx=10) # lower strand entry diff --git a/qDNA/gui/lind_diss_frame.py b/qDNA/gui/lind_diss_frame.py index cf428a1..1d55042 100644 --- a/qDNA/gui/lind_diss_frame.py +++ b/qDNA/gui/lind_diss_frame.py @@ -74,16 +74,12 @@ def __init__(self, master): # local thermalization checkbox self.loc_therm_var = ctk.BooleanVar(value=self.defaults["loc_therm"]) - self.loc_therm_check = ctk.CTkCheckBox( - self, text="Local", variable=self.loc_therm_var - ) + self.loc_therm_check = ctk.CTkCheckBox(self, text="Local", variable=self.loc_therm_var) self.loc_therm_check.grid(row=6, column=0, padx=10, pady=10) # global thermalization checkbox self.glob_therm_var = ctk.BooleanVar(value=self.defaults["glob_therm"]) - self.glob_therm_check = ctk.CTkCheckBox( - self, text="Global", variable=self.glob_therm_var - ) + self.glob_therm_check = ctk.CTkCheckBox(self, text="Global", variable=self.glob_therm_var) self.glob_therm_check.grid(row=6, column=1, padx=10, pady=10) # -------------------------------------------------------------- diff --git a/qDNA/gui/options_frame.py b/qDNA/gui/options_frame.py index 8ad36f3..c3529de 100644 --- a/qDNA/gui/options_frame.py +++ b/qDNA/gui/options_frame.py @@ -44,9 +44,7 @@ def __init__(self, master): super().__init__(master) # options label - self.label = ctk.CTkLabel( - self, text="Options", font=ctk.CTkFont(size=20, weight="bold") - ) + self.label = ctk.CTkLabel(self, text="Options", font=ctk.CTkFont(size=20, weight="bold")) self.label.grid(row=0, column=0, pady=10, padx=10, columnspan=2) # options tab @@ -54,9 +52,7 @@ def __init__(self, master): self.options_tab.grid(row=1, column=0, columnspan=2, pady=10, padx=10) # back button - self.back_button = ctk.CTkButton( - self, text="Back", command=master.enable_initial_frame - ) + self.back_button = ctk.CTkButton(self, text="Back", command=master.enable_initial_frame) self.back_button.grid(row=2, column=0, pady=10, padx=10) # second confirm button diff --git a/qDNA/gui/pdb_window.py b/qDNA/gui/pdb_window.py index d36f40a..7001b87 100644 --- a/qDNA/gui/pdb_window.py +++ b/qDNA/gui/pdb_window.py @@ -62,9 +62,7 @@ def __init__(self, master): self.save_button.grid(row=7, column=1, padx=10, pady=10) # plot label and particle combobox - self.plot_label = ctk.CTkLabel( - self, text="Plot TB parameters", font=ctk.CTkFont(size=15) - ) + self.plot_label = ctk.CTkLabel(self, text="Plot TB parameters", font=ctk.CTkFont(size=15)) self.plot_label.grid(row=8, column=0, columnspan=2, pady=10, padx=10) self.particle_combobox = ctk.CTkComboBox( @@ -92,9 +90,7 @@ def __init__(self, master): # add a instance of CustomFrame to the window self.custom_frame = PDBFrame(self) - self.custom_frame.grid( - row=0, column=0, columnspan=2, padx=10, pady=10, sticky="nsew" - ) + self.custom_frame.grid(row=0, column=0, columnspan=2, padx=10, pady=10, sticky="nsew") def open_pdb_file(self): pdb_file_path = filedialog.askopenfilename( diff --git a/qDNA/gui/plot_options_frame.py b/qDNA/gui/plot_options_frame.py index b1f72b0..d251474 100644 --- a/qDNA/gui/plot_options_frame.py +++ b/qDNA/gui/plot_options_frame.py @@ -56,9 +56,7 @@ def __init__(self, master): super().__init__(master) self.pack(fill="both", expand=True) - self.explain_label = ctk.CTkLabel( - self, text="Calculate the coherence of the DNA sequence." - ) + self.explain_label = ctk.CTkLabel(self, text="Calculate the coherence of the DNA sequence.") self.explain_label.grid(row=0, column=0, padx=10, pady=10) def get_coh_kwargs(self): @@ -87,16 +85,12 @@ def __init__(self, master, controller): # eigenenergies checkbox self.eigv_var = ctk.BooleanVar(value=False) - self.eigv_check = ctk.CTkCheckBox( - self, text="Eigenenergies", variable=self.eigv_var - ) + self.eigv_check = ctk.CTkCheckBox(self, text="Eigenenergies", variable=self.eigv_var) self.eigv_check.grid(row=1, column=0, columnspan=2, padx=10, pady=10) # eigenstates checkbox self.eigs_var = ctk.BooleanVar(value=False) - self.eigs_check = ctk.CTkCheckBox( - self, text="Eigenstates", variable=self.eigs_var - ) + self.eigs_check = ctk.CTkCheckBox(self, text="Eigenstates", variable=self.eigs_var) self.eigs_check.grid(row=2, column=0, columnspan=2, padx=10, pady=10) # tb site label and combo box @@ -208,25 +202,19 @@ def __init__(self, master, controller): text="Calculate Exciton Lifetime", command=self.controller._calc_lifetime, ) - self.lifetime_button.grid( - row=0, column=0, columnspan=2, padx=10, pady=10, sticky="ew" - ) + self.lifetime_button.grid(row=0, column=0, columnspan=2, padx=10, pady=10, sticky="ew") self.dipole_button = ctk.CTkButton( self, text="Calculate Charge Separation", command=self.controller._calc_charge_separation, ) - self.dipole_button.grid( - row=1, column=0, columnspan=2, padx=10, pady=10, sticky="ew" - ) + self.dipole_button.grid(row=1, column=0, columnspan=2, padx=10, pady=10, sticky="ew") self.dipole_moment_button = ctk.CTkButton( self, text="Calculate Dipole Moment", command=self.controller._calc_dipole_moment, ) - self.dipole_moment_button.grid( - row=2, column=0, columnspan=2, padx=10, pady=10, sticky="ew" - ) + self.dipole_moment_button.grid(row=2, column=0, columnspan=2, padx=10, pady=10, sticky="ew") self.exciton_transfer_button = ctk.CTkButton( self, text="Calculate Exciton Population", @@ -278,17 +266,13 @@ def __init__(self, master): super().__init__(master) controller = master - self.label = ctk.CTkLabel( - self, text="Plotting", font=ctk.CTkFont(size=20, weight="bold") - ) + self.label = ctk.CTkLabel(self, text="Plotting", font=ctk.CTkFont(size=20, weight="bold")) self.label.grid(row=0, column=0, columnspan=2, pady=10, padx=10) self.plot_options_tab = PlotOptionsTab(self, controller) self.plot_options_tab.grid(row=1, column=0, columnspan=2, pady=10, padx=10) - self.back_button = ctk.CTkButton( - self, text="Back", command=master.enable_options_frame - ) + self.back_button = ctk.CTkButton(self, text="Back", command=master.enable_options_frame) self.back_button.grid(row=2, column=0, pady=10, padx=10) self.submit_button = ctk.CTkButton(self, text="Submit", command=master.submit) diff --git a/qDNA/gui/plotting_window.py b/qDNA/gui/plotting_window.py index 4fb3202..185b10d 100644 --- a/qDNA/gui/plotting_window.py +++ b/qDNA/gui/plotting_window.py @@ -64,9 +64,7 @@ def __init__(self, master): self.title("Plotting") self.plotting_frame = PlottingFrame(self) - self.plotting_frame.grid( - row=0, column=0, columnspan=2, padx=10, pady=10, sticky="nsew" - ) + self.plotting_frame.grid(row=0, column=0, columnspan=2, padx=10, pady=10, sticky="nsew") self.plot_option = self.controller.plot_kwargs["plot_option"] @@ -126,9 +124,7 @@ def plot_fourier(self): init_state = self.controller.plot_kwargs["init_state"] end_state = self.controller.plot_kwargs["end_state"] x_axis = self.controller.plot_kwargs["x_axis"] - self.fig, self.ax = self.controller.vis.plot_fourier( - init_state, end_state, x_axis - ) + self.fig, self.ax = self.controller.vis.plot_fourier(init_state, end_state, x_axis) # ------------------------------------------------------------------ @@ -168,9 +164,7 @@ def __init__(self, master): self.controller = master self.plotting_frame = PlottingFrame(self) - self.plotting_frame.grid( - row=0, column=0, columnspan=2, padx=10, pady=10, sticky="nsew" - ) + self.plotting_frame.grid(row=0, column=0, columnspan=2, padx=10, pady=10, sticky="nsew") self.plot_couplings() self.plotting(self.fig) diff --git a/qDNA/gui/qdna_app.py b/qDNA/gui/qdna_app.py index 13efef9..b884828 100644 --- a/qDNA/gui/qdna_app.py +++ b/qDNA/gui/qdna_app.py @@ -65,9 +65,7 @@ def __init__(self): # middle frames self.options_frame = OptionsFrame(self) - self.options_frame.grid( - row=0, column=1, rowspan=3, padx=10, pady=10, sticky="nsew" - ) + self.options_frame.grid(row=0, column=1, rowspan=3, padx=10, pady=10, sticky="nsew") # -------------------------------------------------------------- @@ -140,9 +138,7 @@ def get_init_kwargs(self): def get_options_kwargs(self): # get the values from the options_frame - self.tb_ham_kwargs = ( - self.options_frame.options_tab.tb_ham_frame.get_tb_ham_kwargs() - ) + self.tb_ham_kwargs = self.options_frame.options_tab.tb_ham_frame.get_tb_ham_kwargs() self.lind_diss_kwargs = ( self.options_frame.options_tab.lind_diss_frame.get_lind_diss_kwargs() ) @@ -158,15 +154,9 @@ def get_options_kwargs(self): def get_plot_kwargs(self): # get the values from the plot_options_frame - self.plot_option = { - "plot_option": self.plot_options_frame.plot_options_tab.get() - } - self.pop_kwargs = ( - self.plot_options_frame.plot_options_tab.pop_frame.get_pop_kwargs() - ) - self.coh_kwargs = ( - self.plot_options_frame.plot_options_tab.coh_frame.get_coh_kwargs() - ) + self.plot_option = {"plot_option": self.plot_options_frame.plot_options_tab.get()} + self.pop_kwargs = self.plot_options_frame.plot_options_tab.pop_frame.get_pop_kwargs() + self.coh_kwargs = self.plot_options_frame.plot_options_tab.coh_frame.get_coh_kwargs() self.spectrum_kwargs = ( self.plot_options_frame.plot_options_tab.spectrum_frame.get_spectrum_kwargs() ) @@ -264,56 +254,33 @@ def enable_plotting_frame(self): # ---------------------------------------------------------------------- def _calc_lifetime(self): - assert ( - self.kwargs["description"] == "2P" - ), "2P description is required for the calculation." - assert ( - self.kwargs["relaxation"] == True - ), "Groundstate is required for the calculation." + assert self.kwargs["description"] == "2P", "2P description is required for the calculation." + assert self.kwargs["relaxation"] == True, "Groundstate is required for the calculation." lifetime = self.eva.calc_lifetime() if isinstance(lifetime, str): print(f"Exciton Lifetime: {lifetime}" "\n-------------------------------") else: - print( - f"Exciton Lifetime: {lifetime} fs" "\n-------------------------------" - ) + print(f"Exciton Lifetime: {lifetime} fs" "\n-------------------------------") def _calc_charge_separation(self): - assert ( - self.kwargs["description"] == "2P" - ), "2P description is required for the calculation." - assert ( - self.kwargs["relaxation"] == True - ), "Groundstate is required for the calculation." + assert self.kwargs["description"] == "2P", "2P description is required for the calculation." + assert self.kwargs["relaxation"] == True, "Groundstate is required for the calculation." charge_separation = self.eva.calc_charge_separation() - print( - f"Charge Separation: {charge_separation} A" - "\n-------------------------------" - ) + print(f"Charge Separation: {charge_separation} A" "\n-------------------------------") def _calc_dipole_moment(self): - assert ( - self.kwargs["description"] == "2P" - ), "2P description is required for the calculation." - assert ( - self.kwargs["relaxation"] == True - ), "Groundstate is required for the calculation." + assert self.kwargs["description"] == "2P", "2P description is required for the calculation." + assert self.kwargs["relaxation"] == True, "Groundstate is required for the calculation." dipole_moment = self.eva.calc_dipole_moment() print(f"Dipole Moment: {dipole_moment} D" "\n-------------------------------") def _calc_exciton_transfer(self): - assert ( - self.kwargs["description"] == "2P" - ), "2P description is required for the calculation." - assert ( - self.kwargs["relaxation"] == True - ), "Groundstate is required for the calculation." - assert ( - "exciton" in self.kwargs["particles"] - ), "Exciton must be selected in particles." + assert self.kwargs["description"] == "2P", "2P description is required for the calculation." + assert self.kwargs["relaxation"] == True, "Groundstate is required for the calculation." + assert "exciton" in self.kwargs["particles"], "Exciton must be selected in particles." avg_pop_upper, avg_pop_lower = self.eva.calc_exciton_transfer().values() avg_pop_upper, avg_pop_lower = ( diff --git a/qDNA/gui/scrollable_console_frame.py b/qDNA/gui/scrollable_console_frame.py index ea7045f..5724af9 100644 --- a/qDNA/gui/scrollable_console_frame.py +++ b/qDNA/gui/scrollable_console_frame.py @@ -27,9 +27,7 @@ def __init__(self, master=None, **kwargs): super().__init__(master, **kwargs) # Create a ScrolledText widget for the console output - self.console_output = ScrolledText( - self, wrap="word", state="disabled", height=10, width=35 - ) + self.console_output = ScrolledText(self, wrap="word", state="disabled", height=10, width=35) self.console_output.grid(row=0, column=0, sticky="nsew", padx=(10, 0), pady=10) scrollbar = ctk.CTkScrollbar(self, command=self.console_output.yview) diff --git a/qDNA/gui/tb_ham_frame.py b/qDNA/gui/tb_ham_frame.py index b21c9cc..2e9f0fa 100644 --- a/qDNA/gui/tb_ham_frame.py +++ b/qDNA/gui/tb_ham_frame.py @@ -38,9 +38,7 @@ def __init__(self, master): # Description label and combo box self.description_label = ctk.CTkLabel(self, text="Description:") self.description_label.grid(row=2, column=0, padx=10, pady=10) - self.description_combo = ctk.CTkComboBox( - self, values=self.options["descriptions"] - ) + self.description_combo = ctk.CTkComboBox(self, values=self.options["descriptions"]) self.description_combo.set(self.defaults["description"]) self.description_combo.grid(row=2, column=1, padx=10, pady=10) @@ -117,9 +115,7 @@ def get_tb_ham_kwargs(self): "source": self.source_combo.get(), "description": self.description_combo.get(), "particles": [ - particle - for particle, var in self.selected_particles.items() - if var.get() + particle for particle, var in self.selected_particles.items() if var.get() ], "unit": self.unit_combo.get(), "coulomb_param": float(self.coulomb_param_entry.get()), diff --git a/qDNA/hamiltonian/dna_seq.py b/qDNA/hamiltonian/dna_seq.py index 83fd7dd..72cbb49 100644 --- a/qDNA/hamiltonian/dna_seq.py +++ b/qDNA/hamiltonian/dna_seq.py @@ -58,9 +58,7 @@ def get_tb_sites(upper_strand, **kwargs): tb_sites = [B, *tb_sites, B] if tb_model.double_stranded and is_pdb: - assert ( - lower_strand != "auto complete" - ), "Please provide a lower strand for PDB files." + assert lower_strand != "auto complete", "Please provide a lower strand for PDB files." tb_sites = [list(upper_strand), list(lower_strand)] if tb_model.backbone: diff --git a/qDNA/hamiltonian/ham_analysis.py b/qDNA/hamiltonian/ham_analysis.py index 92e663a..cf0f5ab 100644 --- a/qDNA/hamiltonian/ham_analysis.py +++ b/qDNA/hamiltonian/ham_analysis.py @@ -54,11 +54,7 @@ def calc_amplitudes(eigs, init_state, end_state): """ matrix_dimension = eigs.shape[0] amplitudes = [ - 2 - * eigs[end_state, i] - * eigs[init_state, i] - * eigs[end_state, j] - * eigs[init_state, j] + 2 * eigs[end_state, i] * eigs[init_state, i] * eigs[end_state, j] * eigs[init_state, j] for i, j in product(range(matrix_dimension), repeat=2) if i < j ] @@ -80,9 +76,7 @@ def calc_frequencies(eigv): """ matrix_dimension = len(eigv) frequencies = [ - abs(eigv[i] - eigv[j]).real - for i, j in product(range(matrix_dimension), repeat=2) - if i < j + abs(eigv[i] - eigv[j]).real for i, j in product(range(matrix_dimension), repeat=2) if i < j ] return np.array(frequencies) diff --git a/qDNA/hamiltonian/tb_ham.py b/qDNA/hamiltonian/tb_ham.py index 448f6ae..3fdd41d 100644 --- a/qDNA/hamiltonian/tb_ham.py +++ b/qDNA/hamiltonian/tb_ham.py @@ -156,14 +156,10 @@ def coulomb_param(self): return self._coulomb_param @coulomb_param.setter - def coulomb_param( - self, new_coulomb_param - ): # pylint: disable=missing-function-docstring + def coulomb_param(self, new_coulomb_param): # pylint: disable=missing-function-docstring """Sets the Coulomb interaction parameter and updates the matrix if changed.""" - assert isinstance( - new_coulomb_param, float - ), "coulomb_param must be of type float" + assert isinstance(new_coulomb_param, float), "coulomb_param must be of type float" old_coulomb_param = self._coulomb_param self._coulomb_param = new_coulomb_param @@ -178,12 +174,8 @@ def exchange_param(self): return self._exchange_param @exchange_param.setter - def exchange_param( - self, new_exchange_param - ): # pylint: disable=missing-function-docstring - assert isinstance( - new_exchange_param, float - ), "exchange_param must be of type float" + def exchange_param(self, new_exchange_param): # pylint: disable=missing-function-docstring + assert isinstance(new_exchange_param, float), "exchange_param must be of type float" old_exchange_param = self._exchange_param self._coulomb_param = new_exchange_param @@ -218,9 +210,7 @@ def nn_cutoff(self): return self._nn_cutoff @nn_cutoff.setter - def nn_cutoff( - self, new_nearest_neighbor_cutoff - ): # pylint: disable=missing-function-docstring + def nn_cutoff(self, new_nearest_neighbor_cutoff): # pylint: disable=missing-function-docstring old_nn_cutoff = self._nn_cutoff self._nn_cutoff = new_nearest_neighbor_cutoff @@ -267,9 +257,7 @@ def source(self, new_source): # pylint: disable=missing-function-docstring # ------------------------------------------------------------------ def get_tb_params(self): - tb_params, metadata = load_tb_params( - self.source, self.tb_model_name, load_metadata=True - ) + tb_params, metadata = load_tb_params(self.source, self.tb_model_name, load_metadata=True) # convert the parameters to the expected unit if self.unit != metadata["unit"]: @@ -346,9 +334,7 @@ def get_eigensystem(self): def _get_fourier_1P(self, init_state, end_state, quantities): - assert ( - init_state in self.tb_basis - ), f"Initial state {init_state} must be in tb_basis." + assert init_state in self.tb_basis, f"Initial state {init_state} must be in tb_basis." eigv, eigs = self.get_eigensystem() init_state_idx = self.tb_basis.index(init_state) @@ -372,9 +358,7 @@ def _get_fourier_1P(self, init_state, end_state, quantities): def _get_fourier_2P(self, init_state, end_state, quantities): - assert ( - init_state in self.eh_basis - ), f"initial state {init_state} must be in tb_basis." + assert init_state in self.eh_basis, f"initial state {init_state} must be in tb_basis." eigv, eigs = self.get_eigensystem() init_state_idx = self.eh_basis.index(init_state) @@ -424,26 +408,18 @@ def get_fourier(self, init_state, end_state, quantities): if self.description == "2P": return self._get_fourier_2P(init_state, end_state, quantities) - def get_amplitudes( - self, init_state, end_state - ): # pylint: disable=missing-function-docstring + def get_amplitudes(self, init_state, end_state): # pylint: disable=missing-function-docstring return self.get_fourier(init_state, end_state, ["amplitude"])[0] - def get_frequencies( - self, init_state, end_state - ): # pylint: disable=missing-function-docstring + def get_frequencies(self, init_state, end_state): # pylint: disable=missing-function-docstring return self.get_fourier(init_state, end_state, ["frequency"])[1] - def get_average_pop( - self, init_state, end_state - ): # pylint: disable=missing-function-docstring + def get_average_pop(self, init_state, end_state): # pylint: disable=missing-function-docstring return self.get_fourier(init_state, end_state, ["average_pop"])[2] def get_backbone_average_pop(self, init_state): - assert ( - self.backbone - ), "Backbone population can only be calculated for Fishbone models" + assert self.backbone, "Backbone population can only be calculated for Fishbone models" # collect all backbone sites upper_backbone_sites, lower_backbone_sites = [], [] diff --git a/qDNA/hamiltonian/tb_matrices.py b/qDNA/hamiltonian/tb_matrices.py index c7d53aa..7129ea8 100644 --- a/qDNA/hamiltonian/tb_matrices.py +++ b/qDNA/hamiltonian/tb_matrices.py @@ -106,9 +106,7 @@ def tb_ham_1P( # for interstrand hopping the direction is not imporant if tb_str[0] in ["h", "r"] and tb_str not in tb_param_dict: - tb_str = ( - f"{tb_str.split('_')[0]}_{tb_str.split('_')[2]}_{tb_str.split('_')[1]}" - ) + tb_str = f"{tb_str.split('_')[0]}_{tb_str.split('_')[2]}_{tb_str.split('_')[1]}" if tb_str not in tb_param_dict: raise ValueError( @@ -152,9 +150,7 @@ def tb_ham_2P( matrix_electron = tb_ham_1P( tb_dims, tb_config, tb_basis, tb_params["electron"], tb_basis_sites_dict ) - matrix_hole = tb_ham_1P( - tb_dims, tb_config, tb_basis, tb_params["hole"], tb_basis_sites_dict - ) + matrix_hole = tb_ham_1P(tb_dims, tb_config, tb_basis, tb_params["hole"], tb_basis_sites_dict) dim = matrix_hole.shape[0] matrix = np.zeros((dim**2, dim**2)) @@ -284,9 +280,7 @@ def add_interaction( if interaction_type == "Coulomb": interaction_strength_list = interaction_param / (1 + 3.4 / 1 * distance_list) elif interaction_type == "Exchange": - interaction_strength_list = interaction_param * np.exp( - -3.4 / 0.5 * distance_list - ) + interaction_strength_list = interaction_param * np.exp(-3.4 / 0.5 * distance_list) # nearest neighbor cutoff if nn_cutoff: @@ -294,9 +288,7 @@ def add_interaction( interaction_strength_list[i] = 0 # add interaction terms on the diagonal for exciton states - for eh_basis_state_idx, interaction_strength in enumerate( - interaction_strength_list - ): + for eh_basis_state_idx, interaction_strength in enumerate(interaction_strength_list): eh_basis_state = eh_basis[eh_basis_state_idx] matrix = set_matrix_element( matrix, interaction_strength, eh_basis_state, eh_basis_state, eh_basis diff --git a/qDNA/io/io_pdb.py b/qDNA/io/io_pdb.py index cf5cf56..76f3e55 100644 --- a/qDNA/io/io_pdb.py +++ b/qDNA/io/io_pdb.py @@ -133,9 +133,7 @@ def pdb_to_xyz(filepath, **kwargs): if base_id != old_base_id and old_base_id is not None: write_xyz(directory, old_base_id, elements, coordinates) - write_xyz( - directory, old_backbone_id, elements_backbone, coordinates_backbone - ) + write_xyz(directory, old_backbone_id, elements_backbone, coordinates_backbone) elements, elements_backbone = [], [] coordinates, coordinates_backbone = [], [] diff --git a/qDNA/lcao/component.py b/qDNA/lcao/component.py index dcc7b67..bce72f1 100644 --- a/qDNA/lcao/component.py +++ b/qDNA/lcao/component.py @@ -75,9 +75,7 @@ def __init__(self, filepath, **kwargs): self.atoms = atoms self.atoms_coordinates = np.array(coordinates) - self.atoms_id = [ - f"{atom}_{atom_idx}" for atom_idx, atom in enumerate(self.atoms) - ] + self.atoms_id = [f"{atom}_{atom_idx}" for atom_idx, atom in enumerate(self.atoms)] self.num_atoms = len(self.atoms) self.num_electrons = sum(self.num_atom_electrons[atom] for atom in self.atoms) @@ -115,9 +113,7 @@ def get_orbital_distance_matrix(self): def get_orbital_bond_matrix(self, cutoff=1.59): orbital_distance_matrix = self.get_orbital_distance_matrix() - orbital_bond_matrix = (orbital_distance_matrix > 0) & ( - orbital_distance_matrix < cutoff - ) + orbital_bond_matrix = (orbital_distance_matrix > 0) & (orbital_distance_matrix < cutoff) return orbital_bond_matrix.astype(int) diff --git a/qDNA/lcao/monomer.py b/qDNA/lcao/monomer.py index 18a0174..a12a04a 100644 --- a/qDNA/lcao/monomer.py +++ b/qDNA/lcao/monomer.py @@ -173,15 +173,9 @@ def _calc_dipole_moment(self, unit="Coulomb*Angstrom"): MO_1, MO_2 = self.HOMO, self.LUMO - dipole_x = ( - -c.e * np.abs(MO_1) * self.rel_orbitals_coordinates[:, 0] * np.abs(MO_2) - ) - dipole_y = ( - -c.e * np.abs(MO_1) * self.rel_orbitals_coordinates[:, 1] * np.abs(MO_2) - ) - dipole_z = ( - -c.e * np.abs(MO_1) * self.rel_orbitals_coordinates[:, 2] * np.abs(MO_2) - ) + dipole_x = -c.e * np.abs(MO_1) * self.rel_orbitals_coordinates[:, 0] * np.abs(MO_2) + dipole_y = -c.e * np.abs(MO_1) * self.rel_orbitals_coordinates[:, 1] * np.abs(MO_2) + dipole_z = -c.e * np.abs(MO_1) * self.rel_orbitals_coordinates[:, 2] * np.abs(MO_2) dipole = np.array([np.sum(dipole_x), np.sum(dipole_y), np.sum(dipole_z)]) if unit == "Coulomb*Angstrom": diff --git a/qDNA/lcao/oligomer.py b/qDNA/lcao/oligomer.py index 30c58b2..1ee701b 100644 --- a/qDNA/lcao/oligomer.py +++ b/qDNA/lcao/oligomer.py @@ -45,10 +45,7 @@ def calc_dipolar_coupling(monomer1, monomer2): prefactor = 1 / (4 * np.pi * c.epsilon_0) * 1 / np.linalg.norm(R1 - R2) ** 3 return ( prefactor - * ( - mu1 @ mu2 - - 3 / np.linalg.norm(R1 - R2) ** 2 * (mu1 @ (R2 - R1)) * (mu2 @ (R2 - R1)) - ) + * (mu1 @ mu2 - 3 / np.linalg.norm(R1 - R2) ** 2 * (mu1 @ (R2 - R1)) * (mu2 @ (R2 - R1))) * 1e10 / c.e ) @@ -148,9 +145,7 @@ def __init__(self, filepath_pdb, **kwargs): self.filepaths = self._get_filepaths() self.num_sites = self.num_channels * self.num_sites_per_strand - self.monomers = [ - Monomer(filepaths, **self.kwargs) for filepaths in self.filepaths - ] + self.monomers = [Monomer(filepaths, **self.kwargs) for filepaths in self.filepaths] self.monomers = np.array(self.monomers).reshape(self.tb_dims) self.couplings = get_tb_couplings(self.tb_model_name, self.num_sites_per_strand) @@ -169,10 +164,7 @@ def __repr__(self): def _get_filepaths(self): """Generate file paths for each site in the directory based on the sites matrix.""" - return [ - [os.path.join(self.directory, site + ".xyz") for site in row] - for row in self.sites - ] + return [[os.path.join(self.directory, site + ".xyz") for site in row] for row in self.sites] def _get_sites_all(self): """Categorizes and returns filenames into base sites and backbone sites.""" @@ -255,11 +247,7 @@ def calc_tb_params(self): for coupling in self.couplings: key, monomer1_idx, monomer2_idx = coupling coupling_id = ( - key - + "_" - + self.sites_id[monomer1_idx] - + "_" - + self.sites_id[monomer2_idx] + key + "_" + self.sites_id[monomer1_idx] + "_" + self.sites_id[monomer2_idx] ) monomer1 = self.monomers[monomer1_idx] @@ -337,9 +325,7 @@ def plot_couplings( labels = [site_id[2] for site_id in self.sites_id.flatten()] tb_basis = [str_to_tuple(element) for element in self.tb_basis] - positions = [ - (element[1], self.num_strands - 1 - element[0]) for element in tb_basis - ] + positions = [(element[1], self.num_strands - 1 - element[0]) for element in tb_basis] # x_coords, y_coords = zip(*positions) # x_margin = 0.3 # y_margin = 0.3 @@ -350,7 +336,9 @@ def plot_couplings( for tb_str, old_state, new_state in self.couplings: tb_str = f"{tb_str}_{self.sites_id[old_state]}_{self.sites_id[new_state]}" if tb_str[0] in ["h", "r"] and tb_str not in tb_params: - tb_str = f"{tb_str.split('_')[0]}_{self.sites_id[new_state]}_{self.sites_id[old_state]}" + tb_str = ( + f"{tb_str.split('_')[0]}_{self.sites_id[new_state]}_{self.sites_id[old_state]}" + ) tb_val = 1e3 * abs(tb_params[tb_str]) # convert to meV old_idx = tuple_to_int(self.tb_dims, old_state) diff --git a/qDNA/lcao/slater_koster.py b/qDNA/lcao/slater_koster.py index d4d2cf5..667b379 100644 --- a/qDNA/lcao/slater_koster.py +++ b/qDNA/lcao/slater_koster.py @@ -107,9 +107,7 @@ def _get_overlap(lcao_param, vector, orbital_types): return overlap -def calc_orbital_interaction( - lcao_param, orbitals, orbitals_coordinates, connection_type -): +def calc_orbital_interaction(lcao_param, orbitals, orbitals_coordinates, connection_type): """ Calculate the interaction between two orbitals based on LCAO parameters. diff --git a/qDNA/legacy.py b/qDNA/legacy.py index ccb30cd..1c53ada 100644 --- a/qDNA/legacy.py +++ b/qDNA/legacy.py @@ -20,9 +20,7 @@ def convert_pdb_to_xyz(filepath_pdb): def calc_tb_params(directories, tb_model, double_stranded=True): HOMO_dict, LUMO_dict = {}, {} for directory in directories: - oligomer = Oligomer( - directory + ".pdb", tb_model_name=tb_model, auto_clean=False - ) + oligomer = Oligomer(directory + ".pdb", tb_model_name=tb_model, auto_clean=False) tb_params = oligomer.calc_tb_params() HOMO_dict_new, LUMO_dict_new = tb_params["hole"], tb_params["electron"] HOMO_dict.update(HOMO_dict_new) @@ -30,9 +28,7 @@ def calc_tb_params(directories, tb_model, double_stranded=True): return HOMO_dict, LUMO_dict -def wrap_save_tb_params( - tb_params, source, particle, tb_model_name, unit=None, notes=None -): +def wrap_save_tb_params(tb_params, source, particle, tb_model_name, unit=None, notes=None): unit = "eV" tb_params = {particle: tb_params} directory = os.path.join(DATA_DIR, "tb_params") @@ -54,9 +50,7 @@ def wrap_save_tb_params( class DNA_Seq: - def __init__( - self, upper_strand, tb_model_name, methylated=True, lower_strand="auto_complete" - ): + def __init__(self, upper_strand, tb_model_name, methylated=True, lower_strand="auto_complete"): if lower_strand == "auto_complete": lower_strand = "auto complete" self.tb_sites = get_tb_sites( diff --git a/qDNA/utils/check_input.py b/qDNA/utils/check_input.py index 5167532..45f8214 100644 --- a/qDNA/utils/check_input.py +++ b/qDNA/utils/check_input.py @@ -152,9 +152,7 @@ def check_lind_diss_kwargs(**diss_kwargs): assert isinstance(kwargs.get(key), str), f"{key} must be of type str" for key in float_keys: - assert isinstance( - kwargs.get(key), (float, int) - ), f"{key} must be of type float or int" + assert isinstance(kwargs.get(key), (float, int)), f"{key} must be of type float or int" for key in bool_keys: assert isinstance(kwargs.get(key), bool), f"{key} must be of type bool" @@ -179,9 +177,7 @@ def check_lind_diss_kwargs(**diss_kwargs): assert not ( loc_deph_rate != 0 and glob_deph_rate != 0 ), "Dephasing must either be local or global, not both" - assert not ( - loc_therm and glob_therm - ), "Thermalization must either be local or global, not both" + assert not (loc_therm and glob_therm), "Thermalization must either be local or global, not both" # ---------------------------------------------------------------------- diff --git a/qDNA/visualization/visualization.py b/qDNA/visualization/visualization.py index e952dfe..94e6092 100644 --- a/qDNA/visualization/visualization.py +++ b/qDNA/visualization/visualization.py @@ -130,11 +130,7 @@ def plot_heatmap( for j in range(y_num): particle = self.particles[i + j] particle_pop = np.array( - [ - value - for key, value in pop_dict.items() - if key.startswith(particle) - ] + [value for key, value in pop_dict.items() if key.startswith(particle)] ) if vmax_list is not None: @@ -181,36 +177,24 @@ def plot_heatmap( ax[i, j].set_yticks([]) y_len, x_len = particle_pop.shape xticks = np.linspace(0, x_len, 4) - ax[i, j].set_xticks( - xticks, labels=[int(x) for x in np.linspace(0, self.t_end, 4)] - ) + ax[i, j].set_xticks(xticks, labels=[int(x) for x in np.linspace(0, self.t_end, 4)]) yticks = np.arange(y_len) + 0.5 # ax[i, j].set_yticks(yticks, labels=self.tb_sites_flattened) if number == 0: - ax[i, j].set_yticks( - yticks, labels=["01C", "02G", "03G", "06G", "05C", "04C"] - ) + ax[i, j].set_yticks(yticks, labels=["01C", "02G", "03G", "06G", "05C", "04C"]) if number == 1: - ax[i, j].set_yticks( - yticks, labels=["01M", "02G", "03G", "06G", "05M", "04C"] - ) + ax[i, j].set_yticks(yticks, labels=["01M", "02G", "03G", "06G", "05M", "04C"]) if number == 2: - ax[i, j].set_yticks( - yticks, labels=["01C", "02G", "03G", "06G", "05C", "04C"] - ) + ax[i, j].set_yticks(yticks, labels=["01C", "02G", "03G", "06G", "05C", "04C"]) if number == 3: - ax[i, j].set_yticks( - yticks, labels=["01M", "02G", "03G", "06G", "05M", "04C"] - ) + ax[i, j].set_yticks(yticks, labels=["01M", "02G", "03G", "06G", "05M", "04C"]) # for j in range(y_num): # ax[-1, j].set_xlabel("Time [" + self.t_unit + "]") return fig, ax - def plot_pop( - self, tb_site, fig=None, ax=None, dpi=None, add_legend=True, **plot_kwargs - ): + def plot_pop(self, tb_site, fig=None, ax=None, dpi=None, add_legend=True, **plot_kwargs): if plot_kwargs in [None, {}]: plot_kwargs = {} @@ -303,9 +287,7 @@ def plot_pops(self, fig=None, ax=None, dpi=None, **plot_kwargs): tb_site = f"({j}, {i})" else: tb_site = f"({i}, {j})" - _, ax[i, j] = self.plot_pop( - tb_site, fig, ax[i, j], dpi, add_legend=False - ) + _, ax[i, j] = self.plot_pop(tb_site, fig, ax[i, j], dpi, add_legend=False) ax[0, 0].legend(self.particles, loc="upper right") @@ -490,9 +472,7 @@ def plot_fourier(self, init_state, end_state, x_axis, fig=None, ax=None, dpi=Non markers = {"electron": "^", "hole": "v", "exciton": "*"} for particle in self.particles: conversion = get_conversion(self.unit, "rad/ps") / (2 * np.pi) - frequencies_dict[particle] = ( - np.array(frequencies_dict[particle]) * conversion - ) + frequencies_dict[particle] = np.array(frequencies_dict[particle]) * conversion amplitudes = amplitudes_dict[particle] frequencies = frequencies_dict[particle] @@ -566,9 +546,7 @@ def _get_cumulative_average_pop(self, J_list, J_unit): return np.array(cumulative_pop_list) # cumulative_average_pop = get_cumulative_average_pop(tb_ham, J_list) - def plot_average_pop( - self, J_list, J_unit="100meV", fig=None, ax=None, dpi=None, **plot_kwargs - ): + def plot_average_pop(self, J_list, J_unit="100meV", fig=None, ax=None, dpi=None, **plot_kwargs): if plot_kwargs is None: plot_kwargs = {} diff --git a/tests/test_hamiltonian/test_ham_analysis.py b/tests/test_hamiltonian/test_ham_analysis.py index bfc0d0b..035e95f 100644 --- a/tests/test_hamiltonian/test_ham_analysis.py +++ b/tests/test_hamiltonian/test_ham_analysis.py @@ -17,9 +17,7 @@ def test_calc_average_pop(eigs, state1, state2, expected): assert np.allclose(calc_average_pop(eigs, state1, state2), expected) -@pytest.mark.parametrize( - "eigs, state1, state2, expected", [(eigs, 0, 0, np.array([0.5]))] -) +@pytest.mark.parametrize("eigs, state1, state2, expected", [(eigs, 0, 0, np.array([0.5]))]) def test_calc_amplitudes(eigs, state1, state2, expected): assert np.allclose(calc_amplitudes(eigs, state1, state2), expected) diff --git a/tests/test_model/test_tb_basis.py b/tests/test_model/test_tb_basis.py index f124735..dcf1433 100644 --- a/tests/test_model/test_tb_basis.py +++ b/tests/test_model/test_tb_basis.py @@ -12,9 +12,7 @@ ) -@pytest.mark.parametrize( - "input, expected", [((2, 2), ["(0, 0)", "(0, 1)", "(1, 0)", "(1, 1)"])] -) +@pytest.mark.parametrize("input, expected", [((2, 2), ["(0, 0)", "(0, 1)", "(1, 0)", "(1, 1)"])]) def test_get_tb_basis(input, expected): assert get_tb_basis(input) == expected