Skip to content

Commit

Permalink
Adding tests to check the override of structural paramters handling t…
Browse files Browse the repository at this point in the history
…he boundary and dimensionality of the structure.
  • Loading branch information
Jonathan Chico committed Apr 25, 2024
1 parent 1416d37 commit 4288e07
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 7 deletions.
11 changes: 9 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
initialise a test database and profile
"""

# pylint: disable=redefined-outer-name
from __future__ import annotations

Expand All @@ -13,7 +14,7 @@

from aiida import orm
from aiida.common import AttributeDict, CalcInfo, LinkType, exceptions
from aiida.engine import CalcJob
from aiida.engine import CalcJob, Process
from aiida.engine.utils import instantiate_process
from aiida.manage.manager import get_manager
from aiida.plugins import WorkflowFactory
Expand Down Expand Up @@ -67,6 +68,12 @@ def pytest_report_header(config):
]


@pytest.fixture
def structure_parameters() -> AttributeDict:
parameteters = AttributeDict({"dimension": 2, "boundary": ["p", "p", "f"]})
return parameteters


@pytest.fixture
def filepath_tests() -> pathlib.Path:
"""Return the path to the tests folder."""
Expand Down Expand Up @@ -567,7 +574,7 @@ def factory(
entry_point_name: str,
inputs: dict[str, Any] | None = None,
return_process: bool = False,
) -> tuple[pathlib.Path, CalcInfo] | CalcJob:
) -> tuple[pathlib.Path, CalcInfo] | Process:
"""Create a :class:`aiida.engine.CalcJob` instance with the given inputs.
:param entry_point_name: The entry point name of the calculation job plugin to run.
Expand Down
18 changes: 13 additions & 5 deletions tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to tests the input file generation"""

import os

import pytest
Expand All @@ -20,32 +21,39 @@ def validate_input_parameters(parameters: dict):


@pytest.mark.parametrize(
"potential_type",
["eam_alloy"],
"potential_type,override_parameters",
[("eam_alloy", True), ("eam_alloy", False)],
)
def test_input_generate_minimize(
db_test_app, # pylint: disable=unused-argument
parameters_minimize,
get_lammps_potential_data,
structure_parameters,
potential_type,
override_parameters,
file_regression,
):
"""Test the generation of the input file for minimize calculations"""
# pylint: disable=too-many-locals

validate_input_parameters(parameters_minimize)
if override_parameters:
_parameters = parameters_minimize
_parameters["structure"].update(structure_parameters)
else:
_parameters = parameters_minimize
validate_input_parameters(_parameters)
# Generate the potential
potential_information = get_lammps_potential_data(potential_type)
potential = LammpsPotentialData.get_or_create(
source=potential_information["filename"],
filename=potential_information["filename"],
**potential_information["parameters"],
)

# Generating the structure
structure = potential_information["structure"]
# Generating the input file
input_file = inputfile.generate_input_file(
parameters=parameters_minimize,
parameters=_parameters,
potential=potential,
structure=structure,
trajectory_filename="temp.dump",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#------------------------Start of the Control information------------------------#
clear
units metal
newton on
timestep 1e-05
#-------------------------End of the Control information-------------------------#
#-----------------------Start of the Structure information-----------------------#
box tilt small
dimension 3
boundary p p p
atom_style atomic
read_data structure.dat
#------------------------End of the Structure information------------------------#
#-------------------------Start of Potential information-------------------------#
pair_style eam/alloy
pair_coeff * * potential.dat Fe Fe
#--------------------------End of Potential information--------------------------#
#--------------------------Start of the Fix information--------------------------#
fix box_relax_all_aiida all box/relax iso 0.0 vmax 0.001
#---------------------------End of the Fix information---------------------------#
#------------------------Start of the Compute information------------------------#
compute pe_atom_all_aiida all pe/atom
compute ke_atom_all_aiida all ke/atom
compute stress_atom_all_aiida all stress/atom NULL
compute pressure_all_aiida all pressure thermo_temp
#-------------------------End of the Compute information-------------------------#
#------------------------Start of the Thermo information-------------------------#
thermo_style custom step pe ke press pxx pyy pzz etotal c_pressure_all_aiida c_pressure_all_aiida[1] c_pressure_all_aiida[2] c_pressure_all_aiida[3] c_pressure_all_aiida[4] c_pressure_all_aiida[5] c_pressure_all_aiida[6]
thermo 100
#-------------------------End of the Thermo information--------------------------#
#-------------------------Start of the Dump information--------------------------#
dump aiida all custom 1000 temp.dump id type element x y z c_pe_atom_all_aiida c_ke_atom_all_aiida c_stress_atom_all_aiida[1] c_stress_atom_all_aiida[2] c_stress_atom_all_aiida[3] c_stress_atom_all_aiida[4] c_stress_atom_all_aiida[5] c_stress_atom_all_aiida[6]
dump_modify aiida sort id
dump_modify aiida element Fe Fe
dump_modify aiida format line "%6d %4d %4s %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f"
#--------------------------End of the Dump information---------------------------#
#---------------------Start of the Minimization information----------------------#
min_style cg
minimize 1e-05 1e-05 5000 5000
#----------------------End of the Minimization information-----------------------#
#--------------------Start of the Final Variables information--------------------#
variable final_step equal step
variable final_pe equal pe
variable final_ke equal ke
variable final_press equal press
variable final_pxx equal pxx
variable final_pyy equal pyy
variable final_pzz equal pzz
variable final_etotal equal etotal
variable final_c_pressure_all_aiida equal c_pressure_all_aiida
variable final_c_pressure_all_aiida__1__ equal c_pressure_all_aiida[1]
variable final_c_pressure_all_aiida__2__ equal c_pressure_all_aiida[2]
variable final_c_pressure_all_aiida__3__ equal c_pressure_all_aiida[3]
variable final_c_pressure_all_aiida__4__ equal c_pressure_all_aiida[4]
variable final_c_pressure_all_aiida__5__ equal c_pressure_all_aiida[5]
variable final_c_pressure_all_aiida__6__ equal c_pressure_all_aiida[6]
#---------------------End of the Final Variables information---------------------#
#---------------Start of the Printing Final Variables information----------------#
print "#Final results" file aiida_lammps.yaml
print "final_step: ${final_step}" append aiida_lammps.yaml
print "final_pe: ${final_pe}" append aiida_lammps.yaml
print "final_ke: ${final_ke}" append aiida_lammps.yaml
print "final_press: ${final_press}" append aiida_lammps.yaml
print "final_pxx: ${final_pxx}" append aiida_lammps.yaml
print "final_pyy: ${final_pyy}" append aiida_lammps.yaml
print "final_pzz: ${final_pzz}" append aiida_lammps.yaml
print "final_etotal: ${final_etotal}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida: ${final_c_pressure_all_aiida}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__1__: ${final_c_pressure_all_aiida__1__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__2__: ${final_c_pressure_all_aiida__2__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__3__: ${final_c_pressure_all_aiida__3__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__4__: ${final_c_pressure_all_aiida__4__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__5__: ${final_c_pressure_all_aiida__5__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__6__: ${final_c_pressure_all_aiida__6__}" append aiida_lammps.yaml
#----------------End of the Printing Final Variables information-----------------#
#---------------------Start of the write restart information---------------------#
write_restart restart.aiida
#----------------------End of the write restart information----------------------#
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#------------------------Start of the Control information------------------------#
clear
units metal
newton on
timestep 1e-05
#-------------------------End of the Control information-------------------------#
#-----------------------Start of the Structure information-----------------------#
box tilt small
dimension 2
boundary p p f
atom_style atomic
read_data structure.dat
#------------------------End of the Structure information------------------------#
#-------------------------Start of Potential information-------------------------#
pair_style eam/alloy
pair_coeff * * potential.dat Fe Fe
#--------------------------End of Potential information--------------------------#
#--------------------------Start of the Fix information--------------------------#
fix box_relax_all_aiida all box/relax iso 0.0 vmax 0.001
#---------------------------End of the Fix information---------------------------#
#------------------------Start of the Compute information------------------------#
compute pe_atom_all_aiida all pe/atom
compute ke_atom_all_aiida all ke/atom
compute stress_atom_all_aiida all stress/atom NULL
compute pressure_all_aiida all pressure thermo_temp
#-------------------------End of the Compute information-------------------------#
#------------------------Start of the Thermo information-------------------------#
thermo_style custom step pe ke press pxx pyy pzz etotal c_pressure_all_aiida c_pressure_all_aiida[1] c_pressure_all_aiida[2] c_pressure_all_aiida[3] c_pressure_all_aiida[4] c_pressure_all_aiida[5] c_pressure_all_aiida[6]
thermo 100
#-------------------------End of the Thermo information--------------------------#
#-------------------------Start of the Dump information--------------------------#
dump aiida all custom 1000 temp.dump id type element x y z c_pe_atom_all_aiida c_ke_atom_all_aiida c_stress_atom_all_aiida[1] c_stress_atom_all_aiida[2] c_stress_atom_all_aiida[3] c_stress_atom_all_aiida[4] c_stress_atom_all_aiida[5] c_stress_atom_all_aiida[6]
dump_modify aiida sort id
dump_modify aiida element Fe Fe
dump_modify aiida format line "%6d %4d %4s %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f %16.10f"
#--------------------------End of the Dump information---------------------------#
#---------------------Start of the Minimization information----------------------#
min_style cg
minimize 1e-05 1e-05 5000 5000
#----------------------End of the Minimization information-----------------------#
#--------------------Start of the Final Variables information--------------------#
variable final_step equal step
variable final_pe equal pe
variable final_ke equal ke
variable final_press equal press
variable final_pxx equal pxx
variable final_pyy equal pyy
variable final_pzz equal pzz
variable final_etotal equal etotal
variable final_c_pressure_all_aiida equal c_pressure_all_aiida
variable final_c_pressure_all_aiida__1__ equal c_pressure_all_aiida[1]
variable final_c_pressure_all_aiida__2__ equal c_pressure_all_aiida[2]
variable final_c_pressure_all_aiida__3__ equal c_pressure_all_aiida[3]
variable final_c_pressure_all_aiida__4__ equal c_pressure_all_aiida[4]
variable final_c_pressure_all_aiida__5__ equal c_pressure_all_aiida[5]
variable final_c_pressure_all_aiida__6__ equal c_pressure_all_aiida[6]
#---------------------End of the Final Variables information---------------------#
#---------------Start of the Printing Final Variables information----------------#
print "#Final results" file aiida_lammps.yaml
print "final_step: ${final_step}" append aiida_lammps.yaml
print "final_pe: ${final_pe}" append aiida_lammps.yaml
print "final_ke: ${final_ke}" append aiida_lammps.yaml
print "final_press: ${final_press}" append aiida_lammps.yaml
print "final_pxx: ${final_pxx}" append aiida_lammps.yaml
print "final_pyy: ${final_pyy}" append aiida_lammps.yaml
print "final_pzz: ${final_pzz}" append aiida_lammps.yaml
print "final_etotal: ${final_etotal}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida: ${final_c_pressure_all_aiida}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__1__: ${final_c_pressure_all_aiida__1__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__2__: ${final_c_pressure_all_aiida__2__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__3__: ${final_c_pressure_all_aiida__3__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__4__: ${final_c_pressure_all_aiida__4__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__5__: ${final_c_pressure_all_aiida__5__}" append aiida_lammps.yaml
print "final_c_pressure_all_aiida__6__: ${final_c_pressure_all_aiida__6__}" append aiida_lammps.yaml
#----------------End of the Printing Final Variables information-----------------#
#---------------------Start of the write restart information---------------------#
write_restart restart.aiida
#----------------------End of the write restart information----------------------#

0 comments on commit 4288e07

Please sign in to comment.