From d3aff97d1446f47fe61478f763092bac4870ecad Mon Sep 17 00:00:00 2001 From: Manuel Carrer Date: Tue, 16 Nov 2021 16:06:42 +0100 Subject: [PATCH] Move to tomli (#130) * Move to tomli, drop nested lists in config.toml * Update test * Update requirements * Update conftest * Update nesting for bonds, angles and chi --- config.toml | 38 ++--- examples/config.toml | 38 ++--- hymd/input_parser.py | 40 ++--- requirements.txt | 11 +- test/conftest.py | 38 ++--- test/test_input_parser.py | 311 ++++++++++++++++++++------------------ 6 files changed, 247 insertions(+), 229 deletions(-) diff --git a/config.toml b/config.toml index dde1905e..9e4b880d 100644 --- a/config.toml +++ b/config.toml @@ -70,33 +70,33 @@ sigma = 0.5 # Interaction matrix, chi, ((atom name 1, atom name 2), (mixing energy in # [kJ/mol])). chi = [ - [["C", "W"], [42.24]], - [["G", "C"], [10.47]], - [["N", "W"], [-3.77]], - [["G", "W"], [4.53]], - [["N", "P"], [-9.34]], - [["P", "G"], [8.04]], - [["N", "G"], [1.97]], - [["P", "C"], [14.72]], - [["P", "W"], [-1.51]], - [["N", "C"], [13.56]], + ["C", "W", 42.24], + ["G", "C", 10.47], + ["N", "W", -3.77], + ["G", "W", 4.53], + ["N", "P", -9.34], + ["P", "G", 8.04], + ["N", "G", 1.97], + ["P", "C", 14.72], + ["P", "W", -1.51], + ["N", "C", 13.56], ] [bonds] # Two-particle bonds, ((atom name 1, atom name 2), (equilibrium length in # [nanometers], bond strenght in [kJ/mol])). Note the two bonds = [ - [["N", "P"], [0.47, 1250.0]], - [["P", "G"], [0.47, 1250.0]], - [["G", "G"], [0.37, 1250.0]], - [["G", "C"], [0.47, 1250.0]], - [["C", "C"], [0.47, 1250.0]], + ["N", "P", 0.47, 1250.0], + ["P", "G", 0.47, 1250.0], + ["G", "G", 0.37, 1250.0], + ["G", "C", 0.47, 1250.0], + ["C", "C", 0.47, 1250.0], ] # Three-particle angular bonds, ((atom name 1, atom name 2, atom name 3), # (equilibrium angle in [degrees], bond strenght in [kJ/mol])). angle_bonds = [ - [["P", "G", "G"], [120.0, 25.0]], - [["P", "G", "C"], [180.0, 25.0]], - [["G", "C", "C"], [180.0, 25.0]], - [["C", "C", "C"], [180.0, 25.0]], + ["P", "G", "G", 120.0, 25.0], + ["P", "G", "C", 180.0, 25.0], + ["G", "C", "C", 180.0, 25.0], + ["C", "C", "C", 180.0, 25.0], ] diff --git a/examples/config.toml b/examples/config.toml index a94ee77c..b8d806ce 100644 --- a/examples/config.toml +++ b/examples/config.toml @@ -81,33 +81,33 @@ sigma = 0.5 # Interaction matrix, chi, ((atom name 1, atom name 2), (mixing energy in # [kJ/mol])). chi = [ - [["C", "W"], [42.24]], - [["G", "C"], [10.47]], - [["N", "W"], [-3.77]], - [["G", "W"], [4.53]], - [["N", "P"], [-9.34]], - [["P", "G"], [8.04]], - [["N", "G"], [1.97]], - [["P", "C"], [14.72]], - [["P", "W"], [-1.51]], - [["N", "C"], [13.56]], + ["C", "W", 42.24], + ["G", "C", 10.47], + ["N", "W", -3.77], + ["G", "W", 4.53], + ["N", "P", -9.34], + ["P", "G", 8.04], + ["N", "G", 1.97], + ["P", "C", 14.72], + ["P", "W", -1.51], + ["N", "C", 13.56], ] [bonds] # Two-particle bonds, ((atom name 1, atom name 2), (equilibrium length in # [nanometers], bond strength in [kJ/mol])). Note the two bonds = [ - [["N", "P"], [0.47, 1250.0]], - [["P", "G"], [0.47, 1250.0]], - [["G", "G"], [0.37, 1250.0]], - [["G", "C"], [0.47, 1250.0]], - [["C", "C"], [0.47, 1250.0]], + ["N", "P", 0.47, 1250.0], + ["P", "G", 0.47, 1250.0], + ["G", "G", 0.37, 1250.0], + ["G", "C", 0.47, 1250.0], + ["C", "C", 0.47, 1250.0], ] # Three-particle angular bonds, ((atom name 1, atom name 2, atom name 3), # (equilibrium angle in [degrees], bond strength in [kJ/mol])). angle_bonds = [ - [["P", "G", "G"], [120.0, 25.0]], - [["P", "G", "C"], [180.0, 25.0]], - [["G", "C", "C"], [180.0, 25.0]], - [["C", "C", "C"], [180.0, 25.0]], + ["P", "G", "G", 120.0, 25.0], + ["P", "G", "C", 180.0, 25.0], + ["G", "C", "C", 180.0, 25.0], + ["C", "C", "C", 180.0, 25.0], ] diff --git a/hymd/input_parser.py b/hymd/input_parser.py index 863cad17..c956be0f 100644 --- a/hymd/input_parser.py +++ b/hymd/input_parser.py @@ -1,5 +1,5 @@ import copy -import toml +import tomli import datetime import logging import warnings @@ -69,12 +69,14 @@ def __str__(self): ) thermostat_coupling_groups_str = "" if any(self.thermostat_coupling_groups): - thermostat_coupling_groups_str = "\tthermostat_coupling_groups:\n" + "".join( - [ - "\t\t" + ", ".join( - [f"{n}" for n in ng] - ) + "\n" for ng in self.thermostat_coupling_groups - ] + thermostat_coupling_groups_str = ( + "\tthermostat_coupling_groups:\n" + + "".join( + [ + "\t\t" + ", ".join([f"{n}" for n in ng]) + "\n" + for ng in self.thermostat_coupling_groups + ] + ) ) ret_str = f'\n\n\tConfig: {self.file_name}\n\t{50 * "-"}\n' @@ -200,7 +202,7 @@ def read_config_toml(file_path): def parse_config_toml(toml_content, file_path=None, comm=MPI.COMM_WORLD): - parsed_toml = toml.loads(toml_content) + parsed_toml = tomli.loads(toml_content) config_dict = {} # Defaults = None @@ -236,27 +238,27 @@ def parse_config_toml(toml_content, file_path=None, comm=MPI.COMM_WORLD): config_dict["bonds"] = [None] * len(v) for i, b in enumerate(v): config_dict["bonds"][i] = Bond( - atom_1=b[0][0], - atom_2=b[0][1], - equilibrium=b[1][0], - strength=b[1][1], + atom_1=b[0], + atom_2=b[1], + equilibrium=b[2], + strength=b[3], ) if k == "angle_bonds": config_dict["angle_bonds"] = [None] * len(v) for i, b in enumerate(v): config_dict["angle_bonds"][i] = Angle( - atom_1=b[0][0], - atom_2=b[0][1], - atom_3=b[0][2], - equilibrium=b[1][0], - strength=b[1][1], + atom_1=b[0], + atom_2=b[1], + atom_3=b[2], + equilibrium=b[3], + strength=b[4], ) if k == "chi": config_dict["chi"] = [None] * len(v) for i, c in enumerate(v): - c_ = sorted([c[0][0], c[0][1]]) + c_ = sorted([c[0], c[1]]) config_dict["chi"][i] = Chi( - atom_1=c_[0], atom_2=c_[1], interaction_energy=c[1][0] + atom_1=c_[0], atom_2=c_[1], interaction_energy=c[2] ) if file_path is not None: diff --git a/requirements.txt b/requirements.txt index d9d2fe48..9a32bc33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,11 @@ -networkx cython -numpy -sympy +h5py mpi4py mpsort +networkx +numba +numpy pfft-python pmesh -h5py -numba +sympy +tomli diff --git a/test/conftest.py b/test/conftest.py index 824c23c4..71b91dc2 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -173,31 +173,31 @@ def config_toml(mpi_file_name): kappa = 0.05 sigma = 0.5 chi = [ - [["C", "W"], [42.24]], - [["G", "C"], [10.47]], - [["N", "W"], [-3.77]], - [["G", "W"], [4.53]], - [["N", "P"], [-9.34]], - [["P", "G"], [8.04]], - [["N", "G"], [1.97]], - [["P", "C"], [14.72]], - [["P", "W"], [-1.51]], - [["N", "C"], [13.56]], + ["C", "W", 42.24], + ["G", "C", 10.47], + ["N", "W", -3.77], + ["G", "W", 4.53], + ["N", "P", -9.34], + ["P", "G", 8.04], + ["N", "G", 1.97], + ["P", "C", 14.72], + ["P", "W", -1.51], + ["N", "C", 13.56], ] [bonds] bonds = [ - [["N", "P"], [0.47, 1250.0]], - [["P", "G"], [0.47, 1250.0]], - [["G", "G"], [0.37, 1250.0]], - [["G", "C"], [0.47, 1250.0]], - [["C", "C"], [0.47, 1250.0]], + ["N", "P", 0.47, 1250.0], + ["P", "G", 0.47, 1250.0], + ["G", "G", 0.37, 1250.0], + ["G", "C", 0.47, 1250.0], + ["C", "C", 0.47, 1250.0], ] angle_bonds = [ - [["P", "G", "G"], [120.0, 25.0]], - [["P", "G", "C"], [180.0, 25.0]], - [["G", "C", "C"], [180.0, 25.0]], - [["C", "C", "C"], [180.0, 25.0]], + ["P", "G", "G", 120.0, 25.0], + ["P", "G", "C", 180.0, 25.0], + ["G", "C", "C", 180.0, 25.0], + ["C", "C", "C", 180.0, 25.0], ] """ if MPI.COMM_WORLD.Get_rank() == 0: diff --git a/test/test_input_parser.py b/test/test_input_parser.py index 8ec800c5..6c210b38 100644 --- a/test/test_input_parser.py +++ b/test/test_input_parser.py @@ -5,13 +5,21 @@ from types import ModuleType import numpy as np from mpi4py import MPI -from input_parser import (Config, read_config_toml, parse_config_toml, - check_n_particles, check_max_molecule_size, - check_bonds, check_angles, check_chi, - check_box_size, check_integrator, - convert_CONF_to_config, - check_thermostat_coupling_groups, - check_cancel_com_momentum) +from input_parser import ( + Config, + read_config_toml, + parse_config_toml, + check_n_particles, + check_max_molecule_size, + check_bonds, + check_angles, + check_chi, + check_box_size, + check_integrator, + convert_CONF_to_config, + check_thermostat_coupling_groups, + check_cancel_com_momentum, +) def test_input_parser_read_config_toml(config_toml): @@ -47,8 +55,8 @@ def test_input_parser_file_check_n_particles(config_toml, caplog): if MPI.COMM_WORLD.Get_rank() == 0: message = recorded_warning[0].message.args[0] log = caplog.text - assert all([(s in message) for s in ('10000', 'not', '10001')]) - assert all([(s in log) for s in ('10000', 'not', '10001')]) + assert all([(s in message) for s in ("10000", "not", "10001")]) + assert all([(s in log) for s in ("10000", "not", "10001")]) caplog.clear() indices = np.empty((n_particles_config,)) @@ -67,7 +75,7 @@ def test_input_parser_check_optionals(config_toml, caplog): caplog.set_level(logging.INFO) _, config_toml_str = config_toml config_toml_no_n_particles = re.sub( - 'n_particles[ \t]*=[ \t]*[0-9]+', '', config_toml_str + "n_particles[ \t]*=[ \t]*[0-9]+", "", config_toml_str ) config = parse_config_toml(config_toml_no_n_particles) assert config.n_particles is None @@ -78,24 +86,21 @@ def test_input_parser_check_optionals(config_toml, caplog): config = check_n_particles(config, indices_take) assert config.n_particles == 100 if MPI.COMM_WORLD.Get_rank() == 0: - assert all([(s in caplog.text) for s in - ('No', 'n_particles', '100')]) + assert all([(s in caplog.text) for s in ("No", "n_particles", "100")]) caplog.clear() config_toml_no_max_molecule_size = re.sub( - 'max_molecule_size[ \t]*=[ \t]*[0-9]+', '', config_toml_str + "max_molecule_size[ \t]*=[ \t]*[0-9]+", "", config_toml_str ) config = parse_config_toml(config_toml_no_max_molecule_size) assert config.max_molecule_size is None config = check_max_molecule_size(config) if MPI.COMM_WORLD.Get_rank() == 0: - assert all([(s in caplog.text) for s in - ('No', 'max_molecule_size', '201')]) + assert all([(s in caplog.text) for s in ("No", "max_molecule_size", "201")]) caplog.clear() config_toml_wrong_max_molecule_size = re.sub( - 'max_molecule_size[ \t]*=[ \t]*[0-9]+', - 'max_molecule_size = 0', config_toml_str + "max_molecule_size[ \t]*=[ \t]*[0-9]+", "max_molecule_size = 0", config_toml_str ) if MPI.COMM_WORLD.Get_rank() == 0: @@ -109,8 +114,8 @@ def test_input_parser_check_optionals(config_toml, caplog): if MPI.COMM_WORLD.Get_rank() == 0: message = recorded_warning[0].message.args[0] log = caplog.text - assert all([(s in message) for s in ('must be', 'integer', '201')]) - assert all([(s in log) for s in ('must be', 'integer', '201')]) + assert all([(s in message) for s in ("must be", "integer", "201")]) + assert all([(s in log) for s in ("must be", "integer", "201")]) MPI.COMM_WORLD.Barrier() @@ -119,13 +124,13 @@ def _add_to_config(config_str, new_str, header_str): sio_new = [] header_flag = False for line in sio: - if line.strip().startswith(f'{header_str} ='): + if line.strip().startswith(f"{header_str} ="): header_flag = True - if header_flag and line.strip() == ']': + if header_flag and line.strip() == "]": header_flag = False sio_new.append(new_str) sio_new.append(line.rstrip()) - return '\n'.join(s for s in sio_new) + return "\n".join(s for s in sio_new) def _remove_from_config(config_str, remove_str): @@ -134,7 +139,7 @@ def _remove_from_config(config_str, remove_str): for line in sio: if remove_str not in line.strip(): sio_new.append(line.rstrip()) - return '\n'.join(s for s in sio_new) + return "\n".join(s for s in sio_new) def _change_in_config(config_str, old_line, new_line): @@ -145,7 +150,7 @@ def _change_in_config(config_str, old_line, new_line): sio_new.append(new_line.rstrip()) else: sio_new.append(line.rstrip()) - return '\n'.join(s for s in sio_new) + return "\n".join(s for s in sio_new) @pytest.mark.mpi() @@ -153,26 +158,30 @@ def test_input_parser_check_bonds(config_toml, dppc_single, caplog): caplog.set_level(logging.INFO) _, config_toml_str = config_toml _, _, names, _, _, _ = dppc_single - solvent_names = np.empty((8), dtype='a5') - solvent_names.fill('W') + solvent_names = np.empty((8), dtype="a5") + solvent_names.fill("W") names = np.concatenate((names, solvent_names)) name_slices = np.array_split(names, MPI.COMM_WORLD.Get_size()) names_take = name_slices[MPI.COMM_WORLD.Get_rank()] - add_bonds = [' [["A", "C"], [0.47, 1250.0]],', - ' [["A", "A"], [0.47, 1250.0]],', - ' [["P", "B"], [0.47, 1250.0]],', - ' [["A", "A"], [0.47, 1250.0]],', - ' [["A", "B"], [0.47, 1250.0]],'] - warn_strs = [['A--C', 'no A'], - ['A--A', 'no A'], - ['P--B', 'no B'], - ['A--A', 'no A'], - ['A--B', 'neither A, nor B']] + add_bonds = [ + ' ["A", "C", 0.47, 1250.0],', + ' ["A", "A", 0.47, 1250.0],', + ' ["P", "B", 0.47, 1250.0],', + ' ["A", "A", 0.47, 1250.0],', + ' ["A", "B", 0.47, 1250.0],', + ] + warn_strs = [ + ["A--C", "no A"], + ["A--A", "no A"], + ["P--B", "no B"], + ["A--A", "no A"], + ["A--B", "neither A, nor B"], + ] for a, w in zip(add_bonds, warn_strs): - added_bonds_toml_str = _add_to_config(config_toml_str, a, 'bonds') + added_bonds_toml_str = _add_to_config(config_toml_str, a, "bonds") config = parse_config_toml(added_bonds_toml_str) if MPI.COMM_WORLD.Get_rank() == 0: @@ -195,27 +204,30 @@ def test_input_parser_check_angles(config_toml, dppc_single, caplog): caplog.set_level(logging.INFO) _, config_toml_str = config_toml _, _, names, _, _, _ = dppc_single - solvent_names = np.empty((8), dtype='a5') - solvent_names.fill('W') + solvent_names = np.empty((8), dtype="a5") + solvent_names.fill("W") names = np.concatenate((names, solvent_names)) name_slices = np.array_split(names, MPI.COMM_WORLD.Get_size()) names_take = name_slices[MPI.COMM_WORLD.Get_rank()] - add_angles = [' [["A", "C", "C"], [115.9, 25.0]],', - ' [["A", "A", "A"], [158.5, 25.0]],', - ' [["P", "B", "C"], [ 1.5, 25.0]],', - ' [["A", "A", "B"], [ 99.8, 25.0]],', - ' [["A", "B", "K"], [119.8, 25.0]],'] - warn_strs = [['A--C--C', 'no A'], - ['A--A--A', 'no A'], - ['P--B--C', 'no B'], - ['A--A--B', 'no A, B'], - ['A--B--K', 'no A, B, K']] + add_angles = [ + ' ["A", "C", "C", 115.9, 25.0],', + ' ["A", "A", "A", 158.5, 25.0],', + ' ["P", "B", "C", 1.5, 25.0],', + ' ["A", "A", "B", 99.8, 25.0],', + ' ["A", "B", "K", 119.8, 25.0],', + ] + warn_strs = [ + ["A--C--C", "no A"], + ["A--A--A", "no A"], + ["P--B--C", "no B"], + ["A--A--B", "no A, B"], + ["A--B--K", "no A, B, K"], + ] for a, w in zip(add_angles, warn_strs): - added_angles_toml_str = _add_to_config(config_toml_str, a, - 'angle_bonds') + added_angles_toml_str = _add_to_config(config_toml_str, a, "angle_bonds") config = parse_config_toml(added_angles_toml_str) if MPI.COMM_WORLD.Get_rank() == 0: @@ -245,26 +257,30 @@ def test_input_parser_check_chi(config_toml, dppc_single, caplog): assert c.interaction_energy == pytest.approx(14.72, abs=1e-2) _, _, names, _, _, _ = dppc_single - solvent_names = np.empty((8), dtype='a5') - solvent_names.fill('W') + solvent_names = np.empty((8), dtype="a5") + solvent_names.fill("W") names = np.concatenate((names, solvent_names)) name_slices = np.array_split(names, MPI.COMM_WORLD.Get_size()) names_take = name_slices[MPI.COMM_WORLD.Get_rank()] - add_chi = [' [["A", "C"], [1.2398]],', - ' [["A", "A"], [-9.0582]],', - ' [["P", "B"], [-8.8481]],', - ' [["A", "A"], [3.1002]],', - ' [["A", "B"], [2.7815]],'] - warn_strs = [['A--C', 'no A'], - ['A--A', 'no A'], - ['B--P', 'no B'], - ['A--A', 'no A'], - ['A--B', 'neither A, nor B']] + add_chi = [ + ' ["A", "C", 1.2398],', + ' ["A", "A", -9.0582],', + ' ["P", "B", -8.8481],', + ' ["A", "A", 3.1002],', + ' ["A", "B", 2.7815],', + ] + warn_strs = [ + ["A--C", "no A"], + ["A--A", "no A"], + ["B--P", "no B"], + ["A--A", "no A"], + ["A--B", "neither A, nor B"], + ] for a, w in zip(add_chi, warn_strs): - added_chi_toml_str = _add_to_config(config_toml_str, a, 'chi') + added_chi_toml_str = _add_to_config(config_toml_str, a, "chi") config = parse_config_toml(added_chi_toml_str) if MPI.COMM_WORLD.Get_rank() == 0: @@ -280,14 +296,18 @@ def test_input_parser_check_chi(config_toml, dppc_single, caplog): assert all([(s in log) for s in w]) caplog.clear() - remove_chi = ['[["C", "W"], [42.24]],', - '[["N", "P"], [-9.34]],', - '[["N", "C"], [13.56]],', - '[["P", "C"], [14.72]],'] - warn_strs = [['C and W', 'no chi interaction C--W', 'Defaulting'], - ['N and P', 'no chi interaction N--P', 'Defaulting'], - ['C and N', 'no chi interaction C--N', 'Defaulting'], - ['C and P', 'no chi interaction C--P', 'Defaulting']] + remove_chi = [ + '["C", "W", 42.24],', + '["N", "P", -9.34],', + '["N", "C", 13.56],', + '["P", "C", 14.72],', + ] + warn_strs = [ + ["C and W", "no chi interaction C--W", "Defaulting"], + ["N and P", "no chi interaction N--P", "Defaulting"], + ["C and N", "no chi interaction C--N", "Defaulting"], + ["C and P", "no chi interaction C--P", "Defaulting"], + ] for r, w in zip(remove_chi, warn_strs): removed_chi_toml_str = _remove_from_config(config_toml_str, r) @@ -312,20 +332,19 @@ def test_input_parser_check_box_size(config_toml, caplog): caplog.set_level(logging.INFO) _, config_toml_str = config_toml config = parse_config_toml(config_toml_str) - assert np.allclose(np.array([2.1598, 11.2498, 5.1009]), config.box_size, - atol=1e-4) + assert np.allclose(np.array([2.1598, 11.2498, 5.1009]), config.box_size, atol=1e-4) - changed_box_toml_str = _change_in_config(config_toml_str, - 'box_size = [', - 'box_size = [2.25, -3.91, 4.11]') + changed_box_toml_str = _change_in_config( + config_toml_str, "box_size = [", "box_size = [2.25, -3.91, 4.11]" + ) config = parse_config_toml(changed_box_toml_str) with pytest.raises(ValueError) as recorded_error: _ = check_box_size(config) log = caplog.text - assert all([(s in log) for s in ('Invalid', 'box')]) + assert all([(s in log) for s in ("Invalid", "box")]) message = str(recorded_error.value) - assert all([(s in message) for s in ('Invalid', 'box')]) + assert all([(s in message) for s in ("Invalid", "box")]) caplog.clear() @@ -333,21 +352,21 @@ def test_input_parser_check_integrator(config_toml, caplog): caplog.set_level(logging.INFO) _, config_toml_str = config_toml config = parse_config_toml(config_toml_str) - assert config.integrator == 'respa' + assert config.integrator == "respa" assert config.respa_inner == 5 - changed_integrator_toml_str = _change_in_config(config_toml_str, - 'integrator = ', - 'integrator = "rsjgyu"') + changed_integrator_toml_str = _change_in_config( + config_toml_str, "integrator = ", 'integrator = "rsjgyu"' + ) config = parse_config_toml(changed_integrator_toml_str) with pytest.raises(ValueError) as recorded_error: _ = check_integrator(config) if MPI.COMM_WORLD.Get_rank() == 0: log = caplog.text - assert all([(s in log) for s in ('Invalid', 'integrator')]) + assert all([(s in log) for s in ("Invalid", "integrator")]) message = str(recorded_error.value) - assert all([(s in message) for s in ('Invalid', 'integrator')]) + assert all([(s in message) for s in ("Invalid", "integrator")]) caplog.clear() @@ -358,54 +377,62 @@ def test_input_parser_convert_CONF_to_config(config_CONF, caplog): CONF_ = {} exec(open(file_name).read(), CONF) exec(open(file_name).read(), CONF_) - CONF = {k: v for k, v in CONF.items() if (not k.startswith('_') and - not isinstance(v, ModuleType))} - CONF_ = {k: v for k, v in CONF_.items() if (not k.startswith('_') and - not isinstance(v, ModuleType))} + CONF = { + k: v + for k, v in CONF.items() + if (not k.startswith("_") and not isinstance(v, ModuleType)) + } + CONF_ = { + k: v + for k, v in CONF_.items() + if (not k.startswith("_") and not isinstance(v, ModuleType)) + } with pytest.warns(Warning) as recorded_warning: config = convert_CONF_to_config(CONF_, file_path=file_name) assert recorded_warning[0].message.args[0] assert caplog.text - convert_names = [('mass', 'mass'), - ('NSTEPS', 'n_steps'), - ('nprint', 'n_print'), - ('dt', 'time_step'), - ('L', 'box_size'), - ('Nv', 'mesh_size'), - ('Np', 'n_particles'), - ('domain_decomp', 'domain_decomposition'), - ('sigma', 'sigma'), - ('T_start', 'start_temperature'), - ('T0', 'target_temperature')] + convert_names = [ + ("mass", "mass"), + ("NSTEPS", "n_steps"), + ("nprint", "n_print"), + ("dt", "time_step"), + ("L", "box_size"), + ("Nv", "mesh_size"), + ("Np", "n_particles"), + ("domain_decomp", "domain_decomposition"), + ("sigma", "sigma"), + ("T_start", "start_temperature"), + ("T0", "target_temperature"), + ] for names in convert_names: assert CONF[names[0]] == getattr(config, names[1]) caplog.clear() def test_input_parser_check_n_print(): - ... ##### <<<< FIX ME + ... ##### <<<< FIX ME -def test_input_parser_check_tau(): ##### <<<< FIX ME +def test_input_parser_check_tau(): ##### <<<< FIX ME ... -def test_input_parser_check_start_and_target_temperature(): ##### <<<< FIX ME +def test_input_parser_check_start_and_target_temperature(): ##### <<<< FIX ME ... -def test_input_parser_check_mass(): ##### <<<< FIX ME +def test_input_parser_check_mass(): ##### <<<< FIX ME ... -def test_input_parser_check_domain_decomposition(): ##### <<<< FIX ME +def test_input_parser_check_domain_decomposition(): ##### <<<< FIX ME ... @pytest.mark.mpi() -def test_input_parser_check_name(): ##### <<<< FIX ME +def test_input_parser_check_name(): ##### <<<< FIX ME ... @@ -418,33 +445,24 @@ def test_input_parser_thermostat_coupling_groups(config_toml, caplog): for n in nn[i]: assert n in config.thermostat_coupling_groups[i] - thermostat_coupling_groups_toml_str = ( - _remove_from_config( - config_toml_str, - '["N", "P"],' - ) + thermostat_coupling_groups_toml_str = _remove_from_config( + config_toml_str, '["N", "P"],' ) - thermostat_coupling_groups_toml_str = ( - _remove_from_config( - thermostat_coupling_groups_toml_str, - '["G", "C"],' - ) + thermostat_coupling_groups_toml_str = _remove_from_config( + thermostat_coupling_groups_toml_str, '["G", "C"],' ) - thermostat_coupling_groups_toml_str = ( - _remove_from_config( - thermostat_coupling_groups_toml_str, - '["W"],' - ) + thermostat_coupling_groups_toml_str = _remove_from_config( + thermostat_coupling_groups_toml_str, '["W"],' ) thermostat_coupling_groups_toml_str = _add_to_config( thermostat_coupling_groups_toml_str, ' ["N", "P", "G", "C"],', - 'thermostat_coupling_groups' + "thermostat_coupling_groups", ) thermostat_coupling_groups_toml_str = _add_to_config( thermostat_coupling_groups_toml_str, ' ["W"],', - 'thermostat_coupling_groups' + "thermostat_coupling_groups", ) config = parse_config_toml(thermostat_coupling_groups_toml_str) nn = (("N", "P", "G", "C"), ("W")) @@ -452,16 +470,13 @@ def test_input_parser_thermostat_coupling_groups(config_toml, caplog): for n in nn[i]: assert n in config.thermostat_coupling_groups[i] - thermostat_coupling_groups_toml_str = ( - _remove_from_config( - thermostat_coupling_groups_toml_str, - '["N", "P", "G", "C"],' - ) + thermostat_coupling_groups_toml_str = _remove_from_config( + thermostat_coupling_groups_toml_str, '["N", "P", "G", "C"],' ) thermostat_coupling_groups_toml_str = _add_to_config( thermostat_coupling_groups_toml_str, ' ["N", "P", "G"],', - 'thermostat_coupling_groups' + "thermostat_coupling_groups", ) config = parse_config_toml(thermostat_coupling_groups_toml_str) @@ -469,44 +484,38 @@ def test_input_parser_thermostat_coupling_groups(config_toml, caplog): with pytest.raises(ValueError) as recorded_error: _ = check_thermostat_coupling_groups(config) log = caplog.text - assert all([(s in log) for s in ('species C', 'not specified')]) + assert all([(s in log) for s in ("species C", "not specified")]) message = str(recorded_error.value) - assert all([(s in message) for s in ('species C', 'not specified')]) + assert all([(s in message) for s in ("species C", "not specified")]) caplog.clear() - thermostat_coupling_groups_toml_str = ( - _remove_from_config( - thermostat_coupling_groups_toml_str, - '["N", "P", "G"],' - ) + thermostat_coupling_groups_toml_str = _remove_from_config( + thermostat_coupling_groups_toml_str, '["N", "P", "G"],' ) - thermostat_coupling_groups_toml_str = ( - _remove_from_config( - thermostat_coupling_groups_toml_str, - '["W"],' - ) + thermostat_coupling_groups_toml_str = _remove_from_config( + thermostat_coupling_groups_toml_str, '["W"],' ) thermostat_coupling_groups_toml_str = _add_to_config( thermostat_coupling_groups_toml_str, ' ["N", "P", "G", "C"],', - 'thermostat_coupling_groups' + "thermostat_coupling_groups", ) thermostat_coupling_groups_toml_str = _add_to_config( thermostat_coupling_groups_toml_str, ' ["W", "P"],', - 'thermostat_coupling_groups' + "thermostat_coupling_groups", ) config = parse_config_toml(thermostat_coupling_groups_toml_str) config.unique_names = sorted(["N", "P", "G", "C", "W"]) with pytest.raises(ValueError) as recorded_error: _ = check_thermostat_coupling_groups(config) log = caplog.text - assert all([(s in log) for s in ('species P', 'specified', 'multiple')]) + assert all([(s in log) for s in ("species P", "specified", "multiple")]) message = str(recorded_error.value) print(message) - assert all([(s in message) for s in ('species P', 'specified', 'multiple')]) + assert all([(s in message) for s in ("species P", "specified", "multiple")]) caplog.clear() @@ -514,15 +523,21 @@ def test_input_parser_check_cancel_com_momentum(config_toml, caplog): caplog.set_level(logging.INFO) _, config_toml_str = config_toml config = parse_config_toml(config_toml_str) - for t in (1.1, "hello", MPI.COMM_WORLD, config_toml, [1],): + for t in ( + 1.1, + "hello", + MPI.COMM_WORLD, + config_toml, + [1], + ): config.cancel_com_momentum = t with pytest.raises(ValueError) as recorded_error: _ = check_cancel_com_momentum(config) log = caplog.text - assert all([(s in log) for s in ('not interpret', 'an integer')]) + assert all([(s in log) for s in ("not interpret", "an integer")]) message = str(recorded_error.value) - assert all([(s in message) for s in ('not interpret', 'an integer')]) + assert all([(s in message) for s in ("not interpret", "an integer")]) caplog.clear() for t in (-1, -100, 0, False):