diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 215a24a..d068e81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,6 @@ on: tags: - "v*" pull_request: - branches: - - "*" jobs: @@ -18,15 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out app - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - cache: "pip" - cache-dependency-path: | - **/setup.cfg - **/pyproject.toml + uses: actions/checkout@v4 - name: Run pre-commit uses: pre-commit/action@v3.0.0 @@ -60,7 +50,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Check out app - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d8cfad7..52da39d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,27 @@ +default_language_version: + # all hooks should run with python 3.6+ + python: python3 repos: - - repo: https://github.com/psf/black - rev: 23.3.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 hooks: - - id: black - language_version: python3 # Should be a command that runs python3.6+ + - id: no-commit-to-branch + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + - id: check-added-large-files + args: ['--maxkb=500', '--enforce-all'] + - id: end-of-file-fixer + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: check-yaml + - id: check-toml - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.270 + rev: v0.1.1 hooks: - id: ruff - args: [--show-source] + args: [--show-source, --fix] + - id: ruff-format - repo: https://github.com/kynan/nbstripout rev: 0.6.1 diff --git a/README.md b/README.md index 1de2ed0..a46e4f7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![CI](https://github.com/ispg-group/aiidalab-ispg/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/ispg-group/aiidalab-ispg/actions?query=workflow%3ACI) +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) + # AiiDAlab ISPG applications ATMOSPEC - ab initio workflow for UV/VIS spectroscopy of organic molecules. diff --git a/aiidalab_ispg/app/experimental_spectra/acrolein.yaml b/aiidalab_ispg/app/experimental_spectra/acrolein.yaml index 857a01c..76425d1 100644 --- a/aiidalab_ispg/app/experimental_spectra/acrolein.yaml +++ b/aiidalab_ispg/app/experimental_spectra/acrolein.yaml @@ -15,7 +15,7 @@ metadata: - "G.K. Moortgat" - "K. Wirtz" title: "A study of the photolysis and OH-initiated oxidation of acrolein and trans-crotonaldehyde" - journal: "J. Phys. Chem. A" + journal: "J. Phys. Chem. A" issue: "106" pages: "2526-2537" year: "2002" diff --git a/aiidalab_ispg/app/experimental_spectra/glycolaldehyde.yaml b/aiidalab_ispg/app/experimental_spectra/glycolaldehyde.yaml index f6ca6e0..41fc897 100644 --- a/aiidalab_ispg/app/experimental_spectra/glycolaldehyde.yaml +++ b/aiidalab_ispg/app/experimental_spectra/glycolaldehyde.yaml @@ -1,5 +1,5 @@ --- -molecule: glycolaldehyde +molecule: glycolaldehyde smiles: "O=CCO" source_file: glycolaldehyde.txt metadata: @@ -11,7 +11,7 @@ metadata: - "Tyndall, G.S." - "Orlando, J.J." title: "The Atmospheric Chemistry of Glycolaldehyde" - journal: "J. Atmos. Chem." + journal: "J. Atmos. Chem." issue: "39" pages: "171-189" year: "2001" diff --git a/aiidalab_ispg/app/experimental_spectra/methylhydroperoxide.yaml b/aiidalab_ispg/app/experimental_spectra/methylhydroperoxide.yaml index c7ce51e..c74f026 100644 --- a/aiidalab_ispg/app/experimental_spectra/methylhydroperoxide.yaml +++ b/aiidalab_ispg/app/experimental_spectra/methylhydroperoxide.yaml @@ -4,7 +4,7 @@ smiles: "COO" source_file: methylhydroperoxide.txt y_axis_scaling: 1e-20 metadata: - description: 'H3OOH absorption spectrum from IUPAC97, originally from Vaghjiani and Ravishankara (1989)' + description: 'H3OOH absorption spectrum from IUPAC97, originally from Vaghjiani and Ravishankara (1989)' license: '?' source: db_name: 'Andrew`s data' diff --git a/aiidalab_ispg/app/qeapp/process.py b/aiidalab_ispg/app/qeapp/process.py index d4c68f1..8e4b49f 100644 --- a/aiidalab_ispg/app/qeapp/process.py +++ b/aiidalab_ispg/app/qeapp/process.py @@ -31,8 +31,8 @@ class WorkChainSelector(ipw.HBox): BASE_FMT_WORKCHAIN = "{wc.pk:6}{wc.ctime:>10}\t{wc.state:<16}" - BASE_FIELDS = [("pk", int), ("ctime", str), ("state", str)] - extra_fields: Optional[list] = None + _BASE_FIELDS = (("pk", int), ("ctime", str), ("state", str)) + extra_fields: Optional[tuple] = None def __init__(self, process_label, **kwargs): self.process_label = process_label @@ -48,7 +48,7 @@ def __init__(self, process_label, **kwargs): ) if self.extra_fields is not None: - fmt_extra = "".join([f"{{wc.{field[0]}}}\t" for field in self.extra_fields]) + fmt_extra = "\t".join(f"{{wc.{field[0]}}}" for field in self.extra_fields) self.fmt_workchain = self.BASE_FMT_WORKCHAIN + "\t" + fmt_extra else: self.fmt_workchain = self.BASE_FMT_WORKCHAIN @@ -95,11 +95,11 @@ def find_work_chains(self): pk = process_info["pk"] extra_info = self.parse_extra_info(pk) - yield make_dataclass("WorkChain", self.BASE_FIELDS + self.extra_fields)( - **process_info, **extra_info - ) + yield make_dataclass( + "WorkChain", self._BASE_FIELDS + self.extra_fields + )(**process_info, **extra_info) else: - yield make_dataclass("WorkChain", self.BASE_FIELDS)(**process_info) + yield make_dataclass("WorkChain", self._BASE_FIELDS)(**process_info) @tl.default("busy") def _default_busy(self): diff --git a/aiidalab_ispg/app/qeapp/structures.py b/aiidalab_ispg/app/qeapp/structures.py index 4ab8925..5bd27b1 100644 --- a/aiidalab_ispg/app/qeapp/structures.py +++ b/aiidalab_ispg/app/qeapp/structures.py @@ -60,7 +60,7 @@ def __init__(self, manager, description=None, **kwargs): self.message_area, self.confirm_button, ], - **kwargs + **kwargs, ) @traitlets.default("state") diff --git a/aiidalab_ispg/app/spectrum.py b/aiidalab_ispg/app/spectrum.py index 1c2b4c8..e27ecb4 100644 --- a/aiidalab_ispg/app/spectrum.py +++ b/aiidalab_ispg/app/spectrum.py @@ -196,7 +196,7 @@ class SpectrumWidget(ipw.VBox): # https://docs.bokeh.org/en/latest/docs/user_guide/tools.html?highlight=tools#specifying-tools _TOOLS = "pan,wheel_zoom,box_zoom,reset,save" # https://docs.bokeh.org/en/latest/docs/user_guide/tools.html?highlight#hovertool - _TOOLTIPS = [("(energy, cross_section)", "($x,$y)")] + _TOOLTIPS = (("(energy, cross_section)", "($x,$y)"),) def __init__(self, **kwargs): self.width_slider = ipw.FloatSlider( @@ -279,7 +279,7 @@ def __init__(self, **kwargs): "width": 500, } self.figure = self._init_figure( - tools=self._TOOLS, tooltips=self._TOOLTIPS, **figure_size + tools=self._TOOLS, tooltips=list(self._TOOLTIPS), **figure_size ) self.figure.layout = ipw.Layout(overflow="initial") diff --git a/aiidalab_ispg/app/static/StandardActinicFluxes2.csv b/aiidalab_ispg/app/static/StandardActinicFluxes2.csv index e676b1b..dfedc24 100644 --- a/aiidalab_ispg/app/static/StandardActinicFluxes2.csv +++ b/aiidalab_ispg/app/static/StandardActinicFluxes2.csv @@ -468,4 +468,4 @@ WL,WU,wc,L90_500,M60_350,H0_200 746,747,746.5,1.754E+14,5.176E+14,5.836E+14 747,748,747.5,1.774E+14,5.213E+14,5.876E+14 748,749,748.5,1.787E+14,5.222E+14,5.885E+14 -749,750,749.5,1.762E+14,5.116E+14,5.764E+14 \ No newline at end of file +749,750,749.5,1.762E+14,5.116E+14,5.764E+14 diff --git a/aiidalab_ispg/app/widgets.py b/aiidalab_ispg/app/widgets.py index 321a291..2acdbc9 100644 --- a/aiidalab_ispg/app/widgets.py +++ b/aiidalab_ispg/app/widgets.py @@ -46,12 +46,12 @@ class ISPGWorkChainSelector(WorkChainSelector): - extra_fields = [ + extra_fields = ( ("formula", str), ("method", str), ("label", str), ("description", str), - ] + ) def __init__(self, process_label: str, **kwargs): super().__init__(process_label=process_label, **kwargs) @@ -170,7 +170,8 @@ class TrajectoryDataViewer(StructureDataViewer): trajectory = traitlets.Instance(Node, allow_none=True) selected_structure_id = traitlets.Int(allow_none=True) - _structures: list[StructureData] = [] + # TODO: Should probably be tuple instead + _structures: list[StructureData] = [] # noqa: RUF012 _energies: Optional[np.ndarray] = None _boltzmann_weights: Optional[np.ndarray] = None @@ -285,9 +286,7 @@ def _update_trajectory(self, change): def _update_structure_viewer(self, change): """Update the view if displayed_structure trait was modified.""" with self.hold_trait_notifications(): - for ( - comp_id - ) in self._viewer._ngl_component_ids: # pylint: disable=protected-access + for comp_id in self._viewer._ngl_component_ids: # pylint: disable=protected-access self._viewer.remove_component(comp_id) self.selection = [] if change["new"] is not None: @@ -316,7 +315,7 @@ def _prepare_payload(self, file_format=None): # NOTE: TrajectoryManagerWidget will hopefully note be necessary once # the trajectory viewer is merged to AWB class TrajectoryManagerWidget(StructureManagerWidget): - SUPPORTED_DATA_FORMATS = { + SUPPORTED_DATA_FORMATS = { # noqa: RUF012 "CifData": "core.cif", "StructureData": "core.structure", "TrajectoryData": "core.array.trajectory", @@ -398,9 +397,7 @@ def _convert_to_structure_node(self, structure): """Convert structure of any type to the StructureNode object.""" if structure is None: return None - structure_node_type = DataFactory( - self.SUPPORTED_DATA_FORMATS[self.node_class] - ) # pylint: disable=invalid-name + structure_node_type = DataFactory(self.SUPPORTED_DATA_FORMATS[self.node_class]) # pylint: disable=invalid-name # If the input_structure trait is set to Atoms object, structure node must be created from it. if isinstance(structure, Atoms): diff --git a/aiidalab_ispg/workflows/utils.py b/aiidalab_ispg/workflows/utils.py index 451a6fd..908217b 100644 --- a/aiidalab_ispg/workflows/utils.py +++ b/aiidalab_ispg/workflows/utils.py @@ -118,7 +118,7 @@ def extract_trajectory_arrays(**orca_output_parameters) -> ArrayData: en0 = min(gibbs_energies) relative_gibbs_energies_kj = AUtoKJ * (gibbs_energies - en0) - temperature = list(orca_output_parameters.values())[0]["temperature"] + temperature = next(iter(orca_output_parameters.values()))["temperature"] boltzmann_weights = calc_boltzmann_weights(relative_gibbs_energies_kj, temperature) diff --git a/pyproject.toml b/pyproject.toml index b755f2c..d14b5b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,31 +8,35 @@ requires = [ build-backend = "setuptools.build_meta" [tool.ruff] -# Enable pyflakes and pyf-builtins, pyflakes, f=bugbear +line-length = 88 +# TODO: Enable ruff for notebooks +src = ["aiidalab_ispg", "tests"] +target-version = "py39" + +# Enable pyflakes and pyf-builtins, pyflakes, f=bugbear select = [ - "A", # flake8-builtins - "B", # flake8-bugbear - "E", # pycodestyle - "F", # pyflakes - "C90", # McCabe code complexity - "UP", # pyupgrade - "S", # bandit - "C4", # comprehensiosn - "EM", # errormsg - "ISC", # implicit concatenation - "ICN", # import convention - "INP", # no implicite namespace package - "PIE", # - "PT", # pytest style + "A", # flake8-builtins + "B", # flake8-bugbear + "E", # pycodestyle + "F", # pyflakes + "C90", # McCabe code complexity + "UP", # pyupgrade + "S", # bandit + "C4", # comprehensions + "EM", # errormsg + "ISC", # implicit concatenation + "ICN", # import convention + "INP", # no implicite namespace package + "PIE", # + "PT", # pytest style "PTH", - # "PL", # pylint, for now disabled + "PLC", + "PLE", + "PLW", + "RUF", + # "PL", # pylint, disabled for now # "PLR", # pylint refactor - "PLC", "PLE", "PLW", - "RUF", # ruff ] -line-length = 120 -src = ["aiidalab_ispg", "tests"] -target-version = "py39" # Never enforce `E501` (line length violations). # TODO: Remove all asserts from the codebase and enable this rule diff --git a/tests/app/test_app.py b/tests/app/test_app.py old mode 100755 new mode 100644 diff --git a/tests/wigner/wigner_test/freq_g09.molden b/tests/wigner/wigner_test/freq_g09.molden index 03a75cc..847a370 100644 --- a/tests/wigner/wigner_test/freq_g09.molden +++ b/tests/wigner/wigner_test/freq_g09.molden @@ -15,7 +15,7 @@ scf-first 1 THROUGH 12 -108.933430 [GEOMETRIES] XYZ 7 - + C -1.115872 -0.220612 0.023971 O 0.021884 0.600791 -0.024280 O 1.147735 -0.274299 -0.097254 diff --git a/tests/wigner/wigner_test/opt_anfreq_mp2_avdz_orca_nofrozencore.hess b/tests/wigner/wigner_test/opt_anfreq_mp2_avdz_orca_nofrozencore.hess index 52a0481..1304562 100644 --- a/tests/wigner/wigner_test/opt_anfreq_mp2_avdz_orca_nofrozencore.hess +++ b/tests/wigner/wigner_test/opt_anfreq_mp2_avdz_orca_nofrozencore.hess @@ -12,7 +12,7 @@ $act_energy $hessian 21 - 0 1 2 3 4 + 0 1 2 3 4 0 4.5413444392E-01 2.4395394216E-03 -2.9287653060E-02 -2.1108843975E-01 1.0700866009E-02 1 2.4395394216E-03 6.1833166438E-01 -1.8849553667E-02 5.3856058764E-02 -7.5021588166E-02 2 -2.9287653060E-02 -1.8849553667E-02 6.0028628629E-01 -6.8087102569E-02 1.4117945114E-02 @@ -34,7 +34,7 @@ $hessian 18 -3.6895431162E-03 -1.7453976336E-03 3.6659325698E-03 -9.4886779316E-03 8.7405818533E-03 19 -6.8216802513E-04 -3.4021604609E-03 3.9706353803E-03 -3.5742971816E-02 -1.7333071829E-03 20 7.0134778447E-04 1.3055938157E-03 3.1814448981E-04 1.2187737487E-02 -3.1437270961E-03 - 5 6 7 8 9 + 5 6 7 8 9 0 -3.6920825870E-02 -2.1970425467E-02 -6.3608778740E-03 1.4381303835E-04 -7.4703654681E-02 1 1.8804981201E-02 -4.6117682267E-02 -9.9228780141E-03 2.7552235152E-03 7.5030661653E-02 2 -8.2773793600E-02 2.7928767413E-02 4.6658433538E-03 -1.6877153473E-03 2.9590219473E-02 @@ -56,7 +56,7 @@ $hessian 18 6.6197338734E-03 -1.8591202932E-01 1.3101520470E-01 1.8591384351E-01 5.3534038623E-04 19 3.2733622147E-02 1.7487179180E-01 -1.6981932975E-01 -1.7075496464E-01 -2.2769058183E-04 20 -1.1840718448E-02 1.8324054123E-01 -1.3277195959E-01 -1.8209313572E-01 -3.8589624443E-04 - 10 11 12 13 14 + 10 11 12 13 14 0 8.3738502123E-02 2.9415124487E-02 -4.8234045118E-02 -1.0725797769E-03 -2.4590450658E-02 1 -2.6586277439E-01 -7.8342739081E-02 -3.7804835463E-03 -5.7280436110E-02 -3.4016421665E-02 2 -7.6013043021E-02 -8.0306559762E-02 -1.7176457607E-02 -3.4191613468E-02 -3.1343519814E-01 @@ -78,7 +78,7 @@ $hessian 18 -5.5506022435E-04 -1.1947021052E-04 -3.7443410177E-04 -5.3465657909E-05 -1.1162422396E-04 19 3.0751846160E-05 5.2146254474E-05 2.7552449688E-04 4.4024830939E-04 -8.3322705151E-04 20 1.3181228982E-04 -4.2703784795E-04 -3.7025974162E-04 -4.2323726002E-04 -4.1284789382E-04 - 15 16 17 18 19 + 15 16 17 18 19 0 -9.4454548904E-02 -8.8765114358E-02 6.0534220137E-02 -3.6895431162E-03 -6.8216802513E-04 1 -7.9679388031E-02 -2.0683855256E-01 1.0834115557E-01 -1.7453976336E-03 -3.4021604609E-03 2 5.3367283689E-02 1.0630516958E-01 -1.2240292229E-01 3.6659325698E-03 3.9706353803E-03 @@ -100,7 +100,7 @@ $hessian 18 -7.5353761268E-04 -4.2665398629E-04 -7.0785653919E-04 1.9968006572E-01 -1.3698543003E-01 19 -1.5107681033E-03 -4.8367526738E-05 -4.7382250527E-04 -1.3698543003E-01 1.7452895523E-01 20 -1.0862629199E-04 -3.9795114482E-04 2.1011193602E-04 -1.9526262447E-01 1.3530742797E-01 - 20 + 20 0 7.0134778447E-04 1 1.3055938157E-03 2 3.1814448981E-04 @@ -149,7 +149,7 @@ $vibrational_frequencies $normal_modes 21 21 - 0 1 2 3 4 + 0 1 2 3 4 0 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 1 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 2 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 @@ -171,7 +171,7 @@ $normal_modes 18 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 19 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 20 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 - 5 6 7 8 9 + 5 6 7 8 9 0 0.0000000000E+00 -9.0517680241E-05 -1.7008429136E-03 -1.8089321139E-01 -1.9396889596E-01 1 0.0000000000E+00 -1.8687870901E-02 -6.9515055360E-03 -1.4125730219E-01 -5.4596225568E-02 2 0.0000000000E+00 -2.7678957699E-02 -3.2876660583E-03 7.3969571809E-02 -2.6991731124E-03 @@ -193,7 +193,7 @@ $normal_modes 18 0.0000000000E+00 -6.9824363703E-01 -3.0970522908E-02 2.3736136984E-01 -7.7804365460E-03 19 0.0000000000E+00 -1.9784339574E-02 -1.3113482787E-01 -1.0032098323E-01 -2.1878421024E-02 20 0.0000000000E+00 -6.9542480903E-01 -2.5372387444E-02 1.2651791762E-01 -1.4835304893E-01 - 10 11 12 13 14 + 10 11 12 13 14 0 -3.9446540143E-01 2.1731893330E-02 -3.8424394412E-02 -2.2017154458E-02 -1.0915784733E-01 1 -4.2310273307E-02 -9.0205114952E-02 1.1935418777E-01 2.8519173621E-02 -1.3570628807E-02 2 -3.8271673905E-02 -9.4618902579E-02 -1.1936741489E-01 -9.6150907406E-03 -7.6444861749E-03 @@ -215,7 +215,7 @@ $normal_modes 18 1.6496210167E-01 -5.8201597705E-02 6.1942156930E-02 -3.8648404741E-01 -3.2282768531E-03 19 2.9360931863E-01 -1.2353833845E-01 1.7595322803E-01 -8.2007876522E-01 8.6918142646E-04 20 -7.2062470616E-02 5.2053241879E-02 -8.3528887694E-02 3.8059542235E-01 -4.3548205318E-03 - 15 16 17 18 19 + 15 16 17 18 19 0 -4.8612886089E-03 2.5277972771E-02 3.9364258515E-02 -1.8333515485E-02 -1.5998430628E-02 1 3.7596117697E-02 -4.0753775599E-02 -5.3215303195E-03 4.9461889999E-02 -8.0391542401E-02 2 4.5939358809E-02 3.9920230464E-02 1.7827648284E-02 7.9394027874E-02 4.5526258794E-02 @@ -237,7 +237,7 @@ $normal_modes 18 1.7893939152E-02 4.2462940255E-03 4.1972371288E-03 2.5808308980E-03 5.2485327589E-04 19 2.4489224474E-02 6.5356789171E-03 -1.6166009793E-03 1.5492862558E-03 2.7491316736E-04 20 -3.0581429429E-03 -2.3990721063E-03 -2.9834716827E-03 3.5494820887E-04 -1.7151336161E-03 - 20 + 20 0 4.3950320207E-04 1 -3.0952423163E-04 2 2.7575313062E-04 @@ -333,4 +333,3 @@ $ir_spectrum $end - diff --git a/tests/wigner/wigner_test/orcahess2molden.awk b/tests/wigner/wigner_test/orcahess2molden.awk old mode 100644 new mode 100755 index 96256d9..37fd54c --- a/tests/wigner/wigner_test/orcahess2molden.awk +++ b/tests/wigner/wigner_test/orcahess2molden.awk @@ -9,7 +9,7 @@ BEGIN { nmode_total=0 row=-1 print "[Molden Format]" -} +} $1 == "$vibrational_frequencies" { print "[FREQ]"