Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiida-core 2.x compatibility changes #48

Merged
merged 4 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ jobs:
- name: Installation
run: |
pip install -e .[testing,pre-commit]
reentry scan

- name: Run pytest
run: |
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [master, develop]
branches: [master, develop, workchains]
pull_request:

jobs:
Expand Down Expand Up @@ -32,25 +32,23 @@ jobs:
matrix:
include:
- python-version: "3.8"
lammps-version: "2020.12.24"
backend: django
lammps-version: "2020.03.03"
- python-version: "3.8"
lammps-version: "2020.12.24"
backend: sqlalchemy
- python-version: "3.9"
lammps-version: "2020.12.24"
backend: django
- python-version: "3.9"
lammps-version: "2020.03.03"
- python-version: "3.10"
lammps-version: "2021.09.29"
backend: django

runs-on: ubuntu-latest

services:
postgres:
image: postgres:10
env:
POSTGRES_DB: test_${{ matrix.backend }}
POSTGRES_DB: test_lammps
POSTGRES_PASSWORD: ''
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
Expand Down Expand Up @@ -86,7 +84,6 @@ jobs:
- name: Installation
run: |
pip install -e .[testing,pre-commit]
reentry scan

- name: Run pytest
run: |
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ the test suite can be run in an isolated, virtual environment using `tox` (see `
or directly:

```shell
>> pip install -e .[testing]
>> reentry scan -r aiida
>> pip install .[testing]
>> pytest -v
```

Expand Down
12 changes: 5 additions & 7 deletions aiida_lammps/calculations/lammps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from aiida.common import CalcInfo, CodeInfo
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
Expand All @@ -34,7 +32,7 @@ def get_supercell(

supercell_array = np.dot(cell, np.diag(supercell_shape))

supercell = StructureData(cell=supercell_array)
supercell = orm.StructureData(cell=supercell_array)
for k in range(positions.shape[0]):
for entry in itertools.product(*[range(i) for i in supercell_shape[::-1]]):
position = positions[k, :] + np.dot(np.array(entry[::-1]), cell)
Expand Down Expand Up @@ -118,7 +116,7 @@ def define(cls, spec):
super().define(spec)
spec.input(
"structure",
valid_type=StructureData,
valid_type=orm.StructureData,
help="the structure",
)
spec.input(
Expand All @@ -128,7 +126,7 @@ def define(cls, spec):
)
spec.input(
"parameters",
valid_type=Dict,
valid_type=orm.Dict,
help="the parameters",
required=False,
)
Expand Down Expand Up @@ -160,7 +158,7 @@ def define(cls, spec):

spec.output(
"results",
valid_type=DataFactory("dict"),
valid_type=orm.Dict,
required=True,
help="the data extracted from the main output file",
)
Expand Down Expand Up @@ -331,7 +329,7 @@ def prepare_for_submission(self, tempfolder): # pylint: disable=arguments-diffe
if "parameters" in self.inputs:
parameters = self.inputs.parameters
else:
parameters = Dict()
parameters = orm.Dict()

# Setup input parameters
input_txt = self.create_main_input_content(
Expand Down
10 changes: 5 additions & 5 deletions aiida_lammps/calculations/lammps/force.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Single point calculation of the energy in LAMMPS."""
# pylint: disable=fixme, duplicate-code, useless-super-delegation
from aiida.plugins import DataFactory
from aiida import orm

from aiida_lammps.calculations.lammps import BaseLammpsCalculation
from aiida_lammps.common.utils import convert_date_string
Expand All @@ -22,7 +22,7 @@ def define(cls, spec):

spec.output(
"arrays",
valid_type=DataFactory("array"),
valid_type=orm.ArrayData,
required=True,
help="force data per atom",
)
Expand All @@ -39,7 +39,7 @@ def create_main_input_content(
):
# pylint: disable=too-many-arguments, too-many-locals
version_date = convert_date_string(
parameter_data.get_attribute("lammps_version", "11 Aug 2017")
parameter_data.base.attributes.get("lammps_version", "11 Aug 2017")
)

lammps_input_file = f"units {potential_data.default_units}\n"
Expand All @@ -55,7 +55,7 @@ def create_main_input_content(
lammps_input_file += "neigh_modify every 1 delay 0 check no\n"

thermo_keywords = ["step", "temp", "epair", "emol", "etotal", "press"]
for kwd in parameter_data.get_attribute("thermo_keywords", []):
for kwd in parameter_data.base.attributes.get("thermo_keywords", []):
if kwd not in thermo_keywords:
thermo_keywords.append(kwd)
lammps_input_file += f'thermo_style custom {" ".join(thermo_keywords)}\n'
Expand Down Expand Up @@ -85,7 +85,7 @@ def create_main_input_content(

lammps_input_file += "run 0\n"

variables = parameter_data.get_attribute("output_variables", [])
variables = parameter_data.base.attributes.get("output_variables", [])
for var in variables:
var_alias = var.replace("[", "_").replace("]", "_")
lammps_input_file += f"variable {var_alias} equal {var}\n"
Expand Down
7 changes: 4 additions & 3 deletions aiida_lammps/calculations/lammps/md.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Single stage MD calculation in LAMMPS."""
# pylint: disable=fixme, useless-super-delegation, duplicate-code
from aiida import orm
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, get_path, join_keywords
from aiida_lammps.data.trajectory import LammpsTrajectory
from aiida_lammps.validation import validate_against_schema


Expand All @@ -25,13 +26,13 @@ def define(cls, spec):

spec.output(
"trajectory_data",
valid_type=DataFactory("lammps.trajectory"),
valid_type=LammpsTrajectory,
required=True,
help="atomic configuration data per dump step",
)
spec.output(
"system_data",
valid_type=DataFactory("array"),
valid_type=orm.ArrayData,
required=False,
help="selected system data per dump step",
)
Expand Down
7 changes: 4 additions & 3 deletions aiida_lammps/calculations/lammps/md_multi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Run a multi-stage molecular dynamic simulation."""
# pylint: disable=fixme
from aiida import orm
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, get_path, join_keywords
from aiida_lammps.data.trajectory import LammpsTrajectory
from aiida_lammps.validation import validate_against_schema


Expand All @@ -25,14 +26,14 @@ def define(cls, spec):
spec.output_namespace(
"system",
dynamic=True,
valid_type=DataFactory("array"),
valid_type=orm.ArrayData,
help="selected system data per dump step of a stage",
)

spec.output_namespace(
"trajectory",
dynamic=True,
valid_type=DataFactory("lammps.trajectory"),
valid_type=LammpsTrajectory,
help="atomic configuration data per dump step of a stage",
)

Expand Down
10 changes: 6 additions & 4 deletions aiida_lammps/calculations/lammps/optimize.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Class describing the calculation of the optimization of a structure
using LAMMPS (minimize method).
"""
from aiida import orm

# pylint: disable=fixme, duplicate-code, useless-super-delegation
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
from aiida_lammps.data.trajectory import LammpsTrajectory
from aiida_lammps.validation import validate_against_schema


Expand All @@ -25,13 +27,13 @@ def define(cls, spec):

spec.output(
"structure",
valid_type=DataFactory("structure"),
valid_type=orm.StructureData,
required=True,
help="the structure output from the calculation",
)
spec.output(
"trajectory_data",
valid_type=DataFactory("lammps.trajectory"),
valid_type=LammpsTrajectory,
required=True,
help="forces, stresses and positions data per step",
)
Expand Down Expand Up @@ -160,7 +162,7 @@ def validate_parameters(param_data, potential_object) -> bool:
raise InputValidationError("parameter data not set")
validate_against_schema(param_data.get_dict(), "optimize.schema.json")

# ensure the potential and paramters are in the same unit systems
# ensure the potential and parameters are in the same unit systems
# TODO convert between unit systems (e.g. using https://pint.readthedocs.io)
if "units" in param_data.get_dict():
punits = param_data.get_dict()["units"]
Expand Down
2 changes: 1 addition & 1 deletion aiida_lammps/common/input_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def write_structure_block(
structure_block += f'dimension {structure.get_dimensionality()["dim"]}\n'
structure_block += "boundary "
for _bound in ["pbc1", "pbc2", "pbc3"]:
structure_block += f'{"p" if structure.attributes[_bound] else "f"} '
structure_block += f'{"p" if structure.base.attributes.all[_bound] else "f"} '
structure_block += "\n"
structure_block += f'atom_style {parameters_structure["atom_style"]}\n'
structure_block += f"read_data {structure_filename}\n"
Expand Down
1 change: 1 addition & 0 deletions aiida_lammps/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def convert_date_string(string):
"""converts date string e.g. '10 Nov 2017' to datetime object
if None, return todays date
'"""

if string is None:
date = datetime.today()
else:
Expand Down
Loading