Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (aiidaplugins#106)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](pre-commit/pre-commit-hooks@v4.5.0...v4.6.0)
- [github.com/astral-sh/ruff-pre-commit: v0.1.7 → v0.4.2](astral-sh/ruff-pre-commit@v0.1.7...v0.4.2)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Apr 30, 2024
1 parent cd9870b commit aa6c69d
Show file tree
Hide file tree
Showing 33 changed files with 67 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ exclude: >
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
rev: v0.4.2
hooks:
- id: ruff
args: [--fix]
Expand Down
1 change: 1 addition & 0 deletions docs/source/tutorials/include/scripts/run_raw_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
the official benchmarks of LAMMPS. It is a simple MD simulation of a protein. It requires an additional input file in
the working directory ``data.rhodo``. This example shows how to add such additional input files.
"""

import io
import textwrap

Expand Down
1 change: 1 addition & 0 deletions examples/calculations/launch_lammps_md.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Sets up an example for the calculation of bcc Fe using ``aiida-lammps``.
"""

from aiida import orm
from aiida.common.extendeddicts import AttributeDict
from aiida.engine import run_get_node
Expand Down
1 change: 1 addition & 0 deletions examples/calculations/launch_lammps_minimize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Sets up an example for the calculation of bcc Fe using ``aiida-lammps``.
"""

from aiida import orm
from aiida.common.extendeddicts import AttributeDict
from aiida.engine import run_get_node
Expand Down
1 change: 1 addition & 0 deletions examples/launch_lammps_base_restart_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Sets up an example for the calculation of bcc Fe using ``aiida-lammps``.
"""

from aiida import orm
from aiida.common.extendeddicts import AttributeDict
from aiida.engine import run_get_node
Expand Down
1 change: 1 addition & 0 deletions examples/launch_lammps_base_restart_folder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Sets up an example for the calculation of bcc Fe using ``aiida-lammps``.
"""

from aiida import orm
from aiida.common.extendeddicts import AttributeDict
from aiida.engine import run_get_node
Expand Down
1 change: 1 addition & 0 deletions examples/launch_lammps_base_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
script for the ``script`` input of the ``LammpsBaseCalculation``, other inputs, such as ``structure`` and ``potential``
no longer have to be specified.
"""

import io
import textwrap

Expand Down
1 change: 1 addition & 0 deletions examples/launch_lammps_raw_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
the official benchmarks of LAMMPS. It is a simple MD simulation of a protein. It requires an additional input file in
the working directory ``data.rhodo``. This example shows how to add such additional input files.
"""

import io
import textwrap

Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/calculations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
is generated depending on the parameters provided, the type of potential,
the input structure and whether or not a restart file is provided.
"""

import os
from typing import ClassVar, Union

Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/calculations/raw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plugin with minimal interface to run LAMMPS."""

import shutil
from typing import Union

Expand Down
3 changes: 2 additions & 1 deletion src/aiida_lammps/data/potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class written by Sebastiaan Huber.
`schema <https://openkim.org/doc/schema/kimspec/>`_, as to make them more easy
to track and as compatible as possible to the KIM schema.
"""

import datetime

# pylint: disable=arguments-differ, too-many-public-methods
Expand Down Expand Up @@ -421,7 +422,7 @@ def validate_extra_tags(self, extra_tags: dict):
:raises ValueError: If the value of the entry does not match the possible values
"""
for key, value in self._extra_keys.items():
_value = extra_tags.get(key, None)
_value = extra_tags.get(key)
_accepted_values = value.get("values", None)
_validator = value.get("validator", None)
if _value is not None and _validator is not None:
Expand Down
40 changes: 24 additions & 16 deletions src/aiida_lammps/data/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The idea is that each of the steps of the simulation are stored as ZIP files
which can then be easily accessed by the user.
"""

# pylint: disable=too-many-ancestors
import io
import tempfile
Expand Down Expand Up @@ -195,14 +196,18 @@ def get_step_string(self, step_idx):
"""Return the content string, for a specific trajectory step."""
step_idx = list(range(self.number_steps))[step_idx]
zip_name = f'{self.base.attributes.get("zip_prefix")}{step_idx}'
with self.base.repository.open(
self.base.attributes.get("trajectory_filename"),
mode="rb",
) as handle, ZipFile(
handle,
"r",
self.base.attributes.get("compression_method"),
) as zip_file, zip_file.open(zip_name, "r") as step_file:
with (
self.base.repository.open(
self.base.attributes.get("trajectory_filename"),
mode="rb",
) as handle,
ZipFile(
handle,
"r",
self.base.attributes.get("compression_method"),
) as zip_file,
zip_file.open(zip_name, "r") as step_file,
):
content = step_file.read()
return content.decode("utf8")

Expand All @@ -218,14 +223,17 @@ def iter_step_strings(self, steps=None):
elif isinstance(steps, int):
steps = range(0, self.number_steps, steps)

with self.base.repository.open(
self.base.attributes.get("trajectory_filename"),
mode="rb",
) as handle, ZipFile(
handle,
"r",
self.base.attributes.get("compression_method"),
) as zip_file:
with (
self.base.repository.open(
self.base.attributes.get("trajectory_filename"),
mode="rb",
) as handle,
ZipFile(
handle,
"r",
self.base.attributes.get("compression_method"),
) as zip_file,
):
for step_idx in steps:
zip_name = f'{self.base.attributes.get("zip_prefix")}{step_idx}'
with zip_file.open(zip_name) as step_file:
Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
It takes care of parsing the lammps.out file, the trajectory file and the
yaml file with the final value of the variables printed in the ``thermo_style``.
"""

import glob
import os
import time
Expand Down
15 changes: 6 additions & 9 deletions src/aiida_lammps/parsers/inputfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ def write_thermo_block(
)
)

computes_printing = parameters_thermo.get("thermo_printing", None)
computes_printing = parameters_thermo.get("thermo_printing")

if computes_printing is None or not computes_printing:
fixed_thermo = ["step", "temp", "epair", "emol", "etotal", "press"]
Expand Down Expand Up @@ -879,7 +879,7 @@ def write_restart_block(

restart_block = {"final": "", "intermediate": ""}

if "print_final" in parameters_restart and parameters_restart["print_final"]:
if parameters_restart.get("print_final"):
restart_block["final"] += generate_header(
"Start of the write restart information"
)
Expand All @@ -888,16 +888,13 @@ def write_restart_block(
"End of the write restart information"
)

if (
"print_intermediate" in parameters_restart
and parameters_restart["print_intermediate"]
):
if parameters_restart.get("print_intermediate"):
restart_block["intermediate"] += generate_header(
"Start of the intermediate write restart information"
)
restart_block[
"intermediate"
] += f"restart {parameters_restart.get('num_steps', int(max_number_steps/10))} {restart_filename}\n"
restart_block["intermediate"] += (
f"restart {parameters_restart.get('num_steps', int(max_number_steps/10))} {restart_filename}\n"
)
restart_block["intermediate"] += generate_header(
"End of the intermediate write restart information"
)
Expand Down
7 changes: 4 additions & 3 deletions src/aiida_lammps/parsers/parse_raw/lammps_output.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Set of functions to parse the unformatted output file from LAMMPS"""

# pylint: disable=fixme
import ast
import re
Expand Down Expand Up @@ -96,9 +97,9 @@ def parse_outputfile(
line.strip().split("=")[-1].strip()
)
if "Energy initial, next-to-last, final" in line:
global_parsed_data["minimization"][
"energy_relative_difference"
] = _calculate_energy_tolerance(data[index + 1])
global_parsed_data["minimization"]["energy_relative_difference"] = (
_calculate_energy_tolerance(data[index + 1])
)
if "Force two-norm initial, final" in line:
global_parsed_data["minimization"]["force_two_norm"] = float(
line.strip().split("=")[-1].split()[-1].strip()
Expand Down
4 changes: 2 additions & 2 deletions src/aiida_lammps/parsers/parse_raw/trajectory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Set of functions to parse the LAMMPS dump output.
"""
"""Set of functions to parse the LAMMPS dump output."""

# pylint: disable=fixme
from collections import namedtuple
import re
Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/parsers/raw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base parser for LAMMPS output."""

import time

from aiida import orm
Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""General utility functions for aiida-lammps"""

import enum

from aiida import __version__ as aiida_version_
Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/validation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Package for validating JSON objects against schemas."""

from aiida_lammps.validation.utils import validate_against_schema # noqa: F401
1 change: 1 addition & 0 deletions src/aiida_lammps/validation/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Utility functions for validating JSON objects against schemas."""

import json
import os
from typing import Union
Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/workflows/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Workchain to run a LAMMPS calculation with automated error handling and restarts."""

import re

from aiida import orm
Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/workflows/md.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Workflow for a molecular dynamics simulation in LAMMPS."""

import os
from typing import Union

Expand Down
1 change: 1 addition & 0 deletions src/aiida_lammps/workflows/relax.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Workflow for the relaxation of a structure using the minimization procedure in LAMMPS."""

from itertools import groupby
import os
from typing import Union
Expand Down
3 changes: 1 addition & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
""" tests for the plugin that does not pollute your profiles/databases.
"""
"""tests for the plugin that does not pollute your profiles/databases."""
1 change: 1 addition & 0 deletions tests/calculations/test_raw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the `LammpsRawCalculation`"""

import io
import textwrap

Expand Down
1 change: 1 addition & 0 deletions tests/parsers/test_raw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the :mod:`aiida_lammps.parsers.raw` module."""

# pylint: disable=redefined-outer-name
from aiida.plugins import ParserFactory

Expand Down
1 change: 1 addition & 0 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the aiida-lammps calculations."""

import copy

from aiida import orm
Expand Down
1 change: 1 addition & 0 deletions tests/test_generate_structure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the structure generation in aiida-lammps"""

from aiida_lammps.parsers.utils import generate_lammps_structure
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests to aiida-lammps parsers.
"""

import os

from aiida.plugins import ParserFactory
Expand Down
1 change: 1 addition & 0 deletions tests/test_potential_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the functionality of the lammps potential data object"""

import os

from aiida_lammps.data.potential import LammpsPotentialData
Expand Down
1 change: 1 addition & 0 deletions tests/test_trajectory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the aiida-lammps trajectory data type"""

import os

from aiida_lammps.data.trajectory import LammpsTrajectory
Expand Down
1 change: 1 addition & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the workflows in aiida-lammps"""

# pylint: disable=redefined-outer-name
from aiida import orm
from aiida.common import AttributeDict, LinkType
Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Set of functions to test the aiida-lammps functionality."""

from collections.abc import Mapping
from contextlib import contextmanager
import distutils.spawn
Expand Down

0 comments on commit aa6c69d

Please sign in to comment.