From ed2e49040f5028c5d2e90dc434046ae6a97f814c Mon Sep 17 00:00:00 2001 From: Jonathan Chico Date: Fri, 19 Apr 2024 15:57:48 +0200 Subject: [PATCH] (WIP) Adding override parameters for the structure dimension and boundary conditions when creating structure inputs. --- src/aiida_lammps/parsers/inputfile.py | 27 +++++++---- src/aiida_lammps/parsers/utils.py | 15 +++--- .../validation/schemas/lammps_schema.json | 47 +++++++++++++++++++ 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/aiida_lammps/parsers/inputfile.py b/src/aiida_lammps/parsers/inputfile.py index 78d09279..deba90c5 100644 --- a/src/aiida_lammps/parsers/inputfile.py +++ b/src/aiida_lammps/parsers/inputfile.py @@ -14,7 +14,7 @@ import json import os import re -from typing import Union +from typing import Any, Dict, Optional, Union from aiida import orm import numpy as np @@ -24,7 +24,7 @@ def generate_input_file( - parameters: dict, + parameters: Dict[str, Any], potential: LammpsPotentialData, structure: orm.StructureData, trajectory_filename: str = "aiida_lammps.trajectory.dump", @@ -32,7 +32,7 @@ def generate_input_file( potential_filename: str = "potential.dat", structure_filename: str = "structure.dat", variables_filename: str = "aiida_lammps.yaml", - read_restart_filename: str = None, + read_restart_filename: Optional[str] = None, ) -> str: """ Generate the text for the lammps input file. @@ -271,7 +271,7 @@ def write_potential_block( def write_structure_block( - parameters_structure: dict, + parameters_structure: Dict[str, Any], structure: orm.StructureData, structure_filename: str, ) -> Union[str, list]: @@ -305,12 +305,21 @@ def write_structure_block( structure_block = generate_header("Start of the Structure information") structure_block += f'box tilt {parameters_structure.get("box_tilt", "small")}\n' - structure_block += f'dimension {structure.get_dimensionality()["dim"]}\n' - structure_block += "boundary " - for _bound in ["pbc1", "pbc2", "pbc3"]: - structure_block += f'{"p" if structure.base.attributes.all[_bound] else "f"} ' - structure_block += "\n" + # Set the dimensions of the structure + if "dimension" in parameters_structure: + structure_block += f"dimension {parameters_structure['dimension']}\n" + else: + structure_block += f"dimension {structure.get_dimensionality()['dim']}\n" + + # Set the boundary conditions of the structure + if "boundary" in parameters_structure: + structure_block += f"boundary {' '.join(parameters_structure['boundary'])} \n" + else: + structure_block += f"boundary {' '.join(['p' if entry else 'f' for entry in structure.pbc])} \n" + + # Set the atom style for the structure structure_block += f'atom_style {parameters_structure["atom_style"]}\n' + # Write the command to read the structure from a file structure_block += f"read_data {structure_filename}\n" # Set the groups which will be used for the calculations if "groups" in parameters_structure: diff --git a/src/aiida_lammps/parsers/utils.py b/src/aiida_lammps/parsers/utils.py index 335483ae..c2e01e79 100644 --- a/src/aiida_lammps/parsers/utils.py +++ b/src/aiida_lammps/parsers/utils.py @@ -1,7 +1,8 @@ """Utility functions for the handling of the input files""" from collections.abc import Iterable -from typing import Union +from typing import Dict, Optional, Union +from aiida import orm import numpy as np @@ -34,10 +35,10 @@ def _transform_cell(cell) -> Union[np.array, np.array]: def generate_lammps_structure( - structure, + structure: orm.StructureData, atom_style: str = "atomic", - charge_dict: dict = None, - round_dp: float = None, + charge_dict: Optional[Dict[str, float]] = None, + round_dp: Optional[float] = None, docstring: str = "generated by aiida_lammps", ) -> Union[str, np.array]: """Creation of the structure file content. @@ -155,7 +156,7 @@ def flatten(full_list: list) -> list: yield element -def convert_to_str(value): +def convert_to_str(value) -> str: """convert True/False to yes/no and all values to strings""" if isinstance(value, bool): if value: @@ -164,13 +165,13 @@ def convert_to_str(value): return str(value) -def _convert_values(value): +def _convert_values(value) -> str: if isinstance(value, (tuple, list)): return " ".join([convert_to_str(v) for v in value]) return convert_to_str(value) -def join_keywords(dct, ignore=None): +def join_keywords(dct, ignore=None) -> str: """join a dict of {keyword: value, ...} into a string 'keyword value ...' value can be a single value or a list/tuple of values diff --git a/src/aiida_lammps/validation/schemas/lammps_schema.json b/src/aiida_lammps/validation/schemas/lammps_schema.json index 49c20f80..a37737a7 100644 --- a/src/aiida_lammps/validation/schemas/lammps_schema.json +++ b/src/aiida_lammps/validation/schemas/lammps_schema.json @@ -122,6 +122,53 @@ "large" ] } + }, + "dimension":{ + "type": "integer", + "propertyNames":{ + "enum": [1,2,3] + } + }, + "boundary":{ + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": [ + { + "description": "boundary conditions along the a-direction", + "type": "string", + "enum": [ + "p", + "f", + "s", + "m", + "pp", + "pf", + "ps", + "pm", + "fp", + "ff", + "fs", + "fm", + "sp", + "sf", + "ss", + "sm", + "mp", + "mf", + "ms", + "mm" + ] + }, + { + "description": "boundary conditions along the b-direction", + "type": "string" + }, + { + "description": "boundary conditions along the c-direction", + "type": "string" + } + ] } } },