Skip to content

Commit

Permalink
(WIP) Adding override parameters for the structure dimension and boun…
Browse files Browse the repository at this point in the history
…dary conditions when creating structure inputs.
  • Loading branch information
Jonathan Chico committed Apr 19, 2024
1 parent b2f119b commit ed2e490
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 16 deletions.
27 changes: 18 additions & 9 deletions src/aiida_lammps/parsers/inputfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,15 +24,15 @@


def generate_input_file(
parameters: dict,
parameters: Dict[str, Any],
potential: LammpsPotentialData,
structure: orm.StructureData,
trajectory_filename: str = "aiida_lammps.trajectory.dump",
restart_filename: str = "lammps.restart",
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.
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions src/aiida_lammps/parsers/utils.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
47 changes: 47 additions & 0 deletions src/aiida_lammps/validation/schemas/lammps_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
},
Expand Down

0 comments on commit ed2e490

Please sign in to comment.