Skip to content

Commit

Permalink
cleaning settings - using disable_print decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Nov 29, 2024
1 parent 9524fbc commit 54035b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 49 deletions.
21 changes: 21 additions & 0 deletions src/aiidalab_qe_vibroscopy/app/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from aiida_phonopy.data.preprocess import PreProcessData
from aiida.plugins import DataFactory
import sys
import os

HubbardStructureData = DataFactory("quantumespresso.hubbard_structure")
from aiida_vibroscopy.calculations.spectra_utils import get_supercells_for_hubbard
Expand Down Expand Up @@ -40,6 +42,24 @@
"""


def disable_print(func):
def wrapper(*args, **kwargs):
# Save the current standard output
original_stdout = sys.stdout
# Redirect standard output to os.devnull
sys.stdout = open(os.devnull, "w")
try:
# Call the function
result = func(*args, **kwargs)
finally:
# Restore the original standard output
sys.stdout.close()
sys.stdout = original_stdout
return result

return wrapper


class VibroConfigurationSettingsModel(ConfigurationSettingsModel, HasInputStructure):
dependencies = [
"input_structure",
Expand Down Expand Up @@ -163,6 +183,7 @@ def reset_symprec(self, _=None):
"supercell_number_estimator"
)

@disable_print
def _estimate_supercells(self, _=None):
if self.input_structure:
self.supercell_number_estimator = spinner_html
Expand Down
49 changes: 0 additions & 49 deletions src/aiidalab_qe_vibroscopy/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,10 @@
from aiidalab_qe.common.panel import ConfigurationSettingsPanel
from aiidalab_qe_vibroscopy.app.model import VibroConfigurationSettingsModel

import sys
import os

from aiida.plugins import DataFactory

HubbardStructureData = DataFactory("quantumespresso.hubbard_structure")

# spinner for waiting time (supercell estimations)
spinner_html = """
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
display: inline-block;
width: 15px;
height: 15px;
}
.spinner div {
width: 100%;
height: 100%;
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
</style>
<div class="spinner">
<div></div>
</div>
"""


def disable_print(func):
def wrapper(*args, **kwargs):
# Save the current standard output
original_stdout = sys.stdout
# Redirect standard output to os.devnull
sys.stdout = open(os.devnull, "w")
try:
# Call the function
result = func(*args, **kwargs)
finally:
# Restore the original standard output
sys.stdout.close()
sys.stdout = original_stdout
return result

return wrapper


class VibroConfigurationSettingPanel(
ConfigurationSettingsPanel[VibroConfigurationSettingsModel],
Expand Down

0 comments on commit 54035b7

Please sign in to comment.