Skip to content

Commit

Permalink
⬆️ Upgrade to aiida-core v1.4.0
Browse files Browse the repository at this point in the history
- drop support for python<3.5
- remove six dependency
- fix deprecation warnings
- impore pre-commit code style
- add tox.ini and docker-compose.yml for improved test infrastructure
  • Loading branch information
chrisjsewell committed Sep 29, 2020
1 parent 24df362 commit de95642
Show file tree
Hide file tree
Showing 50 changed files with 388 additions and 383 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dist/
*.egg*
.DS_Store
.idea/
.tox/
.pytest_cache/
.idea/vcs.xml
postgres*.log
Expand Down
47 changes: 24 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,50 @@ exclude: >
repos:

- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
rev: v3.2.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/timothycrosley/isort
rev: 5.5.3
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
# additional_dependencies:
# - flake8-bugbear==20.1.4
# - flake8-builtins==1.5.3
# - flake8-comprehensions==3.2.3
exclude: >
(?x)^(
aiida_lammps/calculations/dynaphopy.py
)$
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black

- repo: local
hooks:

- id: version-number
name: Check version numbers
entry: python ./.travis-data/check_version.py
language: system
entry: python ./.pre-commit/check_version.py version
language: python
files: >-
(?x)^(
setup.json|
.travis-data/check_version.py|
.pre-commit/check_version.py|
aiida_lammps/__init__.py
)$
pass_filenames: false

# - id: travis-linter
# name: Travis Lint
# entry: travis lint
# files: .travis.yml
# language: ruby
# additional_dependencies: ['travis']

# - id: doc8
# entry: doc8
# language: system
# types: [rst]
# name: doc8 - Lint the documentation.
additional_dependencies:
- click

# TODO could also add check-manifest
71 changes: 71 additions & 0 deletions .pre-commit/check_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Validate consistency of versions and dependencies.
Validates consistency of setup.json and
* environment.yml
* version in aiida_lammps/__init__.py
"""
import json
import os
import sys

import click

FILENAME_SETUP_JSON = "setup.json"
SCRIPT_PATH = os.path.split(os.path.realpath(__file__))[0]
ROOT_DIR = os.path.join(SCRIPT_PATH, os.pardir)
FILEPATH_SETUP_JSON = os.path.join(ROOT_DIR, FILENAME_SETUP_JSON)


def get_setup_json():
"""Return the `setup.json` as a python dictionary."""
with open(FILEPATH_SETUP_JSON, "r") as handle:
setup_json = json.load(handle) # , object_pairs_hook=OrderedDict)

return setup_json


@click.group()
def cli():
"""Command line interface for pre-commit checks."""
pass


@cli.command("version")
def validate_version():
"""Check that version numbers match.
Check version number in setup.json and aiida_lammos/__init__.py and make sure
they match.
"""
# Get version from python package
sys.path.insert(0, ROOT_DIR)
import aiida_lammps # pylint: disable=wrong-import-position

version = aiida_lammps.__version__

setup_content = get_setup_json()
if version != setup_content["version"]:
click.echo("Version number mismatch detected:")
click.echo(
"Version number in '{}': {}".format(
FILENAME_SETUP_JSON, setup_content["version"]
)
)
click.echo(
"Version number in '{}/__init__.py': {}".format("aiida_lammps", version)
)
click.echo(
"Updating version in '{}' to: {}".format(FILENAME_SETUP_JSON, version)
)

setup_content["version"] = version
with open(FILEPATH_SETUP_JSON, "w") as fil:
# Write with indentation of two spaces and explicitly define separators to not have spaces at end of lines
json.dump(setup_content, fil, indent=2, separators=(",", ": "))

sys.exit(1)


if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter
33 changes: 0 additions & 33 deletions .travis-data/check_version.py

This file was deleted.

8 changes: 4 additions & 4 deletions aiida_lammps/calculations/dynaphopy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from aiida.engine import CalcJob
from aiida.orm import ArrayData, StructureData, TrajectoryData
from aiida.common.exceptions import InputValidationError
from aiida.common.datastructures import CalcInfo, CodeInfo
from aiida.common.exceptions import InputValidationError
from aiida.common.utils import classproperty

from aiida.engine import CalcJob
from aiida.orm import ArrayData, StructureData, TrajectoryData
from aiida_phonopy.common.raw_parsers import get_force_constants, get_poscar_txt

from aiida_lammps.common.generate_input_files import (
get_trajectory_txt,
parameters_to_input_file,
Expand Down
21 changes: 10 additions & 11 deletions aiida_lammps/calculations/lammps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from aiida.engine import CalcJob
from aiida.common.exceptions import ValidationError
from aiida.common import CalcInfo, CodeInfo
from aiida.orm import StructureData, Dict
from aiida.common.exceptions import ValidationError
from aiida.engine import CalcJob
from aiida.orm import Dict, StructureData
from aiida.plugins import DataFactory
import numpy as np

from aiida_lammps.common.generate_structure import generate_lammps_structure
from aiida_lammps.data.potential import EmpiricalPotential
import six

import numpy as np


def get_supercell(structure, supercell_shape):
Expand Down Expand Up @@ -111,27 +110,27 @@ def define(cls, spec):
spec.input("parameters", valid_type=Dict, help="the parameters", required=False)
spec.input(
"metadata.options.cell_transform_filename",
valid_type=six.string_types,
valid_type=str,
default="cell_transform.npy",
)
spec.input(
"metadata.options.output_filename",
valid_type=six.string_types,
valid_type=str,
default=cls._DEFAULT_OUTPUT_FILE_NAME,
)
spec.input(
"metadata.options.trajectory_suffix",
valid_type=six.string_types,
valid_type=str,
default=cls._DEFAULT_TRAJECTORY_FILE_NAME,
)
spec.input(
"metadata.options.system_suffix",
valid_type=six.string_types,
valid_type=str,
default=cls._DEFAULT_SYSTEM_FILE_NAME,
)
spec.input(
"metadata.options.restart_filename",
valid_type=six.string_types,
valid_type=str,
default=cls._DEFAULT_RESTART_FILE_NAME,
)

Expand Down
18 changes: 10 additions & 8 deletions aiida_lammps/calculations/lammps/combinate.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Not working with Aiida 1.0

from aiida.common.exceptions import InputValidationError
from aiida.orm import ArrayData, Dict
from aiida_phonopy.common.raw_parsers import (
get_force_constants,
get_poscar_txt,
get_FORCE_SETS_txt,
get_poscar_txt,
)
from aiida_lammps.calculations.lammps import BaseLammpsCalculation
from aiida.orm import Dict, ArrayData
import numpy as np
import six

from aiida_lammps.calculations.lammps import BaseLammpsCalculation


def generate_dynaphopy_input(
Expand Down Expand Up @@ -59,7 +59,7 @@ def define(cls, spec):
super(CombinateCalculation, cls).define(spec)
spec.input(
"metadata.options.parser_name",
valid_type=six.string_types,
valid_type=str,
default="dynaphopy",
)
spec.input("parameters_dynaphopy", valid_type=Dict, help="dynaphopy parameters")
Expand All @@ -68,7 +68,7 @@ def define(cls, spec):
)
spec.input("force_sets", valid_type=ArrayData, help="phonopy force sets")

# spec.input('settings', valid_type=six.string_types, default='lammps.optimize')
# spec.input('settings', valid_type=str, default='lammps.optimize')

@staticmethod
def create_main_input_content(
Expand All @@ -94,8 +94,10 @@ def create_main_input_content(
lammps_input_file += "neighbor 0.3 bin\n"
lammps_input_file += "neigh_modify every 1 delay 0 check no\n"

lammps_input_file += "velocity all create {0} {1} dist gaussian mom yes\n".format(
parameter_data.dict.temperature, random_number
lammps_input_file += (
"velocity all create {0} {1} dist gaussian mom yes\n".format(
parameter_data.dict.temperature, random_number
)
)
lammps_input_file += "velocity all scale {}\n".format(
parameter_data.dict.temperature
Expand Down
8 changes: 4 additions & 4 deletions aiida_lammps/calculations/lammps/force.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from aiida.plugins import DataFactory

from aiida_lammps.calculations.lammps import BaseLammpsCalculation
from aiida_lammps.validation import validate_against_schema
from aiida_lammps.common.utils import convert_date_string
import six
from aiida_lammps.validation import validate_against_schema


class ForceCalculation(BaseLammpsCalculation):
Expand All @@ -12,11 +12,11 @@ def define(cls, spec):

spec.input(
"metadata.options.parser_name",
valid_type=six.string_types,
valid_type=str,
default="lammps.force",
)

# spec.input('settings', valid_type=six.string_types, default='lammps.optimize')
# spec.input('settings', valid_type=str, default='lammps.optimize')

spec.output(
"arrays",
Expand Down
14 changes: 8 additions & 6 deletions aiida_lammps/calculations/lammps/md.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np
from aiida.common.exceptions import InputValidationError
from aiida.plugins import DataFactory
import numpy as np

from aiida_lammps.calculations.lammps import BaseLammpsCalculation
from aiida_lammps.common.utils import convert_date_string, join_keywords, get_path
from aiida_lammps.common.utils import convert_date_string, get_path, join_keywords
from aiida_lammps.validation import validate_against_schema
import six


class MdCalculation(BaseLammpsCalculation):
Expand All @@ -14,7 +14,7 @@ def define(cls, spec):

spec.input(
"metadata.options.parser_name",
valid_type=six.string_types,
valid_type=str,
default="lammps.md",
)
spec.default_output_port = "results"
Expand Down Expand Up @@ -96,8 +96,10 @@ def create_main_input_content(
raise_error=False,
)
if initial_temp is not None:
lammps_input_file += "velocity all create {0} {1} dist gaussian mom yes\n".format(
initial_temp, pdict.get("rand_seed", np.random.randint(10000000))
lammps_input_file += (
"velocity all create {0} {1} dist gaussian mom yes\n".format(
initial_temp, pdict.get("rand_seed", np.random.randint(10000000))
)
)
lammps_input_file += "velocity all scale {}\n".format(initial_temp)

Expand Down
6 changes: 3 additions & 3 deletions aiida_lammps/calculations/lammps/md_multi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from aiida.common.exceptions import InputValidationError
from aiida.plugins import DataFactory

from aiida_lammps.calculations.lammps import BaseLammpsCalculation
from aiida_lammps.common.utils import convert_date_string, join_keywords, get_path
from aiida_lammps.common.utils import convert_date_string, get_path, join_keywords
from aiida_lammps.validation import validate_against_schema
import six


class MdMultiCalculation(BaseLammpsCalculation):
Expand All @@ -15,7 +15,7 @@ def define(cls, spec):

spec.input(
"metadata.options.parser_name",
valid_type=six.string_types,
valid_type=str,
default="lammps.md.multi",
)
spec.default_output_port = "results"
Expand Down
Loading

0 comments on commit de95642

Please sign in to comment.