diff --git a/MDANSE/Src/MDANSE/Framework/Configurators/IConfigurator.py b/MDANSE/Src/MDANSE/Framework/Configurators/IConfigurator.py index d948574ee1..4f3671491e 100644 --- a/MDANSE/Src/MDANSE/Framework/Configurators/IConfigurator.py +++ b/MDANSE/Src/MDANSE/Framework/Configurators/IConfigurator.py @@ -112,9 +112,11 @@ def __init__(self, name, **kwargs): self._label = kwargs.get( "label", - self.__class__._label - if hasattr(self.__class__, "_label") - else " ".join(name.split("_")).strip(), + ( + self.__class__._label + if hasattr(self.__class__, "_label") + else " ".join(name.split("_")).strip() + ), ) self._widget = kwargs.get("widget", self.__class__) diff --git a/MDANSE/Src/MDANSE/Framework/QVectors/SphericalLatticeQVectors.py b/MDANSE/Src/MDANSE/Framework/QVectors/SphericalLatticeQVectors.py index 4924922504..df93a21ec8 100644 --- a/MDANSE/Src/MDANSE/Framework/QVectors/SphericalLatticeQVectors.py +++ b/MDANSE/Src/MDANSE/Framework/QVectors/SphericalLatticeQVectors.py @@ -49,8 +49,7 @@ def _generate(self): ) hklMax = ( - np.ceil([qMax / np.sqrt(np.sum(v**2)) for v in self._inverseUnitCell.T]) - + 1 + np.ceil([qMax / np.sqrt(np.sum(v**2)) for v in self._inverseUnitCell.T]) + 1 ) vects = np.mgrid[ diff --git a/MDANSE/Src/MDANSE/IO/FortranFormat.py b/MDANSE/Src/MDANSE/IO/FortranFormat.py index c1321fb7c5..974084dee6 100644 --- a/MDANSE/Src/MDANSE/IO/FortranFormat.py +++ b/MDANSE/Src/MDANSE/IO/FortranFormat.py @@ -61,7 +61,6 @@ # which can be accessed as text or as a list of items. # class FortranLine: - """Fortran-style record in formatted files FortranLine objects represent the content of one record of a @@ -244,7 +243,6 @@ def _output(self): # little error checking. # class FortranFormat: - """ Parsed Fortran-style format string diff --git a/MDANSE/Src/MDANSE/IO/PDB.py b/MDANSE/Src/MDANSE/IO/PDB.py index 538d6e9285..76847d059f 100644 --- a/MDANSE/Src/MDANSE/IO/PDB.py +++ b/MDANSE/Src/MDANSE/IO/PDB.py @@ -100,7 +100,6 @@ def cmp(a, b): # for everything. # class PDBFile: - """ X{PDB} file with access at the record level @@ -551,7 +550,6 @@ def __del__(self): # Representation of objects. # class PDBAtom: - """ Atom in a PDB structure """ @@ -638,7 +636,6 @@ def writeToFile(self, file): class PDBHetAtom(PDBAtom): - """ HetAtom in a PDB structure @@ -651,7 +648,6 @@ def type(self): class PDBGroup: - """ Atom group (residue or molecule) in a PDB file @@ -771,7 +767,6 @@ def writeToFile(self, file): class PDBMolecule(PDBGroup): - """ Molecule in a PDB file @@ -789,7 +784,6 @@ class PDBResidue(PDBGroup): class PDBAminoAcidResidue(PDBResidue): - """ Amino acid residue in a PDB file """ @@ -850,7 +844,6 @@ def writeToFile(self, file): class PDBNucleotideResidue(PDBResidue): - """ Nucleotide residue in a PDB file """ @@ -922,7 +915,6 @@ def writeToFile(self, file): class PDBChain: - """Chain of PDB residues This is an abstract base class. Instances can be created using @@ -1035,7 +1027,6 @@ def writeToFile(self, file): class PDBPeptideChain(PDBChain): - """ Peptide chain in a PDB file """ @@ -1056,7 +1047,6 @@ def isCompatible(self, chain_data, residue_data): class PDBNucleotideChain(PDBChain): - """ Nucleotide chain in a PDB file """ @@ -1105,7 +1095,6 @@ def isCompatible(self, chain_data, residue_data): # Residue number class for dealing with insertion codes # class ResidueNumber: - """ PDB residue number @@ -1145,7 +1134,6 @@ def __str__(self): # The configuration class. # class Structure: - """ A high-level representation of the contents of a PDB file diff --git a/MDANSE/Src/MDANSE/IO/TextFile.py b/MDANSE/Src/MDANSE/IO/TextFile.py index fc1d43f202..f19049d73c 100644 --- a/MDANSE/Src/MDANSE/IO/TextFile.py +++ b/MDANSE/Src/MDANSE/IO/TextFile.py @@ -25,7 +25,6 @@ class TextFile: - """ Text files with line iteration and transparent compression diff --git a/MDANSE/Src/MDANSE/Mathematics/LinearAlgebra.py b/MDANSE/Src/MDANSE/Mathematics/LinearAlgebra.py index 22c07cc5a8..7741fc4b96 100644 --- a/MDANSE/Src/MDANSE/Mathematics/LinearAlgebra.py +++ b/MDANSE/Src/MDANSE/Mathematics/LinearAlgebra.py @@ -6,7 +6,6 @@ def cmp(a, b): class Vector: - """Vector in 3D space Constructor: @@ -228,7 +227,6 @@ def angle(self, other): class Quaternion: - """ Quaternion (hypercomplex number) @@ -387,7 +385,6 @@ def asRotation(self): class Tensor: - """Tensor in 3D space Tensors support the usual arithmetic operations diff --git a/MDANSE/Src/MDANSE/Mathematics/Transformation.py b/MDANSE/Src/MDANSE/Mathematics/Transformation.py index 73072c1c58..8ed6c5d8c7 100644 --- a/MDANSE/Src/MDANSE/Mathematics/Transformation.py +++ b/MDANSE/Src/MDANSE/Mathematics/Transformation.py @@ -32,7 +32,6 @@ # Abstract base classes # class Transformation: - """ Linear coordinate transformation. @@ -70,7 +69,6 @@ def inverse(self): # Rigid body transformations # class RigidBodyTransformation(Transformation): - """ Combination of translations and rotations """ @@ -110,7 +108,6 @@ def screwMotion(self): # Pure translation # class Translation(RigidBodyTransformation): - """ Translational transformation """ @@ -167,7 +164,6 @@ def screwMotion(self): # Pure rotation # class Rotation(RigidBodyTransformation): - """ Rotational transformation """ @@ -383,7 +379,6 @@ def screwMotion(self): # Combined translation and rotation # class RotationTranslation(RigidBodyTransformation): - """ Combined translational and rotational transformation. @@ -448,7 +443,6 @@ def screwMotion(self): # Scaling # class Scaling(Transformation): - """ Scaling """ @@ -524,7 +518,6 @@ def inverse(self): # General linear transformation # class LinearTransformation(Transformation): - """ General linear transformation. diff --git a/MDANSE/Tests/UnitTests/test_databases.py b/MDANSE/Tests/UnitTests/test_databases.py index d87b16ddcf..7715861a62 100644 --- a/MDANSE/Tests/UnitTests/test_databases.py +++ b/MDANSE/Tests/UnitTests/test_databases.py @@ -161,9 +161,10 @@ def test_add_atom_existing_atom(self): ATOMS_DATABASE.add_atom("H") def test_add_atom_valid(self): - with patch("json.dump") as m, patch( - "MDANSE.Chemistry.Databases.AtomsDatabase.save" - ) as n: + with ( + patch("json.dump") as m, + patch("MDANSE.Chemistry.Databases.AtomsDatabase.save") as n, + ): ATOMS_DATABASE.add_atom("new_atom") self.assertDictEqual({}, ATOMS_DATABASE["new_atom"]) assert not m.called @@ -334,9 +335,10 @@ def test__reset(self): self.assertDictEqual({}, ATOMS_DATABASE._properties) def test_save(self): - with patch("builtins.open", new_callable=mock_open) as op, patch( - "json.dump" - ) as dump: + with ( + patch("builtins.open", new_callable=mock_open) as op, + patch("json.dump") as dump, + ): ATOMS_DATABASE.save() op.assert_called_with(ATOMS_DATABASE._USER_DATABASE, "w") dump.assert_called_with( @@ -383,9 +385,12 @@ def test__load_default_database(self): self.assertDictEqual(self.data, MOLECULES_DATABASE._data) def test__load_user_database(self): - with patch( - "builtins.open", new_callable=mock_open, read_data=json.dumps(self.data) - ) as m, patch("os.path.exists", spec=True): + with ( + patch( + "builtins.open", new_callable=mock_open, read_data=json.dumps(self.data) + ) as m, + patch("os.path.exists", spec=True), + ): MOLECULES_DATABASE._load("user.json", "default.json") m.assert_called_with("user.json", "r") self.assertDictEqual(self.data, MOLECULES_DATABASE._data) @@ -410,9 +415,10 @@ def test_add_molecule_existing_molecule(self): MOLECULES_DATABASE.add_molecule("WAT") def test_add_molecule_valid(self): - with patch("json.dump") as m, patch( - "MDANSE.Chemistry.Databases.MoleculesDatabase.save" - ) as n: + with ( + patch("json.dump") as m, + patch("MDANSE.Chemistry.Databases.MoleculesDatabase.save") as n, + ): MOLECULES_DATABASE.add_molecule("new_molecule") self.assertDictEqual( {"alternatives": [], "atoms": {}}, MOLECULES_DATABASE["new_molecule"] @@ -438,9 +444,10 @@ def test__reset(self): self.assertDictEqual({}, MOLECULES_DATABASE._data) def test_save(self): - with patch("builtins.open", new_callable=mock_open) as op, patch( - "json.dump" - ) as dump: + with ( + patch("builtins.open", new_callable=mock_open) as op, + patch("json.dump") as dump, + ): MOLECULES_DATABASE.save() op.assert_called_with(MOLECULES_DATABASE._USER_DATABASE, "w") dump.assert_called_with(self.data, ANY) @@ -489,9 +496,12 @@ def test__load_default_database(self): ) def test__load_user_database(self): - with patch( - "builtins.open", new_callable=mock_open, read_data=json.dumps(self.data) - ) as m, patch("os.path.exists", spec=True): + with ( + patch( + "builtins.open", new_callable=mock_open, read_data=json.dumps(self.data) + ) as m, + patch("os.path.exists", spec=True), + ): NUCLEOTIDES_DATABASE._load("user.json", "default.json") m.assert_called_with("user.json", "r") self.assertDictEqual(self.data, NUCLEOTIDES_DATABASE._data) @@ -521,9 +531,10 @@ def test_add_nucleotide_existing_nucleotide(self): NUCLEOTIDES_DATABASE.add_nucleotide("5T") def test_add_nucleotide_valid(self): - with patch("json.dump") as m, patch( - "MDANSE.Chemistry.Databases.NucleotidesDatabase.save" - ) as n: + with ( + patch("json.dump") as m, + patch("MDANSE.Chemistry.Databases.NucleotidesDatabase.save") as n, + ): NUCLEOTIDES_DATABASE.add_nucleotide("new_nucleotide", True, True) self.assertDictEqual( { @@ -555,9 +566,10 @@ def test__reset(self): self.assertDictEqual({}, NUCLEOTIDES_DATABASE._data) def test_save(self): - with patch("builtins.open", new_callable=mock_open) as op, patch( - "json.dump" - ) as dump: + with ( + patch("builtins.open", new_callable=mock_open) as op, + patch("json.dump") as dump, + ): NUCLEOTIDES_DATABASE.save() op.assert_called_with(NUCLEOTIDES_DATABASE._USER_DATABASE, "w") dump.assert_called_with(self.data, ANY) @@ -612,9 +624,12 @@ def test__load_default_database(self): ) def test__load_user_database(self): - with patch( - "builtins.open", new_callable=mock_open, read_data=json.dumps(self.data) - ) as m, patch("os.path.exists", spec=True): + with ( + patch( + "builtins.open", new_callable=mock_open, read_data=json.dumps(self.data) + ) as m, + patch("os.path.exists", spec=True), + ): RESIDUES_DATABASE._load("user.json", "default.json") m.assert_called_with("user.json", "r") self.assertDictEqual(self.data, RESIDUES_DATABASE._data) @@ -644,9 +659,10 @@ def test_add_residue_existing_nucleotide(self): RESIDUES_DATABASE.add_residue("G") def test_add_residue_valid(self): - with patch("json.dump") as m, patch( - "MDANSE.Chemistry.Databases.ResiduesDatabase.save" - ) as n: + with ( + patch("json.dump") as m, + patch("MDANSE.Chemistry.Databases.ResiduesDatabase.save") as n, + ): RESIDUES_DATABASE.add_residue("new_residues", True, True) self.assertDictEqual( { @@ -678,9 +694,10 @@ def test__reset(self): self.assertDictEqual({}, RESIDUES_DATABASE._data) def test_save(self): - with patch("builtins.open", new_callable=mock_open) as op, patch( - "json.dump" - ) as dump: + with ( + patch("builtins.open", new_callable=mock_open) as op, + patch("json.dump") as dump, + ): RESIDUES_DATABASE.save() op.assert_called_with(RESIDUES_DATABASE._USER_DATABASE, "w") dump.assert_called_with(self.data, ANY) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/GUI/JobControllerPanel.py b/MDANSE_GUI/Src/MDANSE_GUI/GUI/JobControllerPanel.py index 7141b02eda..287cdc04c6 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/GUI/JobControllerPanel.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/GUI/JobControllerPanel.py @@ -126,10 +126,9 @@ def update(self, init=False): start = datetime.datetime.strptime( self._runningJobs[job]["start"], "%d-%m-%Y %H:%M:%S" ) - self._runningJobs[job][ - "elapsed" - ] = "%02d:%02dh:%02dm:%02ds" % convert_duration( - total_seconds(datetime.datetime.today() - start) + self._runningJobs[job]["elapsed"] = ( + "%02d:%02dh:%02dm:%02ds" + % convert_duration(total_seconds(datetime.datetime.today() - start)) ) # Loop over the job whose temporary files are still present diff --git a/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/ActionDialog.py b/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/ActionDialog.py index b7d2268420..0a741af079 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/ActionDialog.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/ActionDialog.py @@ -132,9 +132,9 @@ def __init__(self, *args, converter: IJob = "Dummy", **kwargs): ddict["configurator"] = configurator ddict["source_object"] = self.source if not dtype in widget_lookup.keys(): - ddict[ - "tooltip" - ] = "This is not implemented in the MDANSE GUI at the moment, and it MUST BE!" + ddict["tooltip"] = ( + "This is not implemented in the MDANSE GUI at the moment, and it MUST BE!" + ) placeholder = BackupWidget(parent=self, **ddict) layout.addWidget(placeholder._base) self._widgets.append(placeholder) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/TrajectoryViewer.py b/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/TrajectoryViewer.py index 2b15d33171..5ccd3f2b58 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/TrajectoryViewer.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Widgets/TrajectoryViewer.py @@ -24,7 +24,6 @@ class TrajectoryViewer(QTreeView): - """A modified QTreeView which enables context menus to pop up for different elements of the workflow. """ diff --git a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_ColourManager.py b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_ColourManager.py index c0202e9ad5..c2d601cf12 100644 --- a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_ColourManager.py +++ b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_ColourManager.py @@ -1,4 +1,3 @@ - import pytest import tempfile @@ -8,18 +7,19 @@ from MDANSE_GUI.PyQtGUI.MolecularViewer.database import CHEMICAL_ELEMENTS -@pytest.fixture(scope='function', params=[None, RGB_COLOURS]) +@pytest.fixture(scope="function", params=[None, RGB_COLOURS]) def colour_manager(request): - temp = ColourManager(init_colours = request.param) + temp = ColourManager(init_colours=request.param) yield temp temp.clear_table() + def test_ColourList(colour_manager: ColourManager): lut_size = colour_manager._lut.GetSize() - assert(lut_size==2) # we initialised with 2 colours - indices = colour_manager.initialise_from_database(['O', 'C', 'Fe'], CHEMICAL_ELEMENTS) - assert(np.all(np.array(indices) == [2,3,4])) + assert lut_size == 2 # we initialised with 2 colours + indices = colour_manager.initialise_from_database( + ["O", "C", "Fe"], CHEMICAL_ELEMENTS + ) + assert np.all(np.array(indices) == [2, 3, 4]) lut_size = colour_manager._lut.GetSize() - assert(lut_size==5) # we added 3 colours, so it should be 5 now. - - + assert lut_size == 5 # we added 3 colours, so it should be 5 now. diff --git a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_FileObject.py b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_FileObject.py index 2248007d13..fb9476f228 100644 --- a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_FileObject.py +++ b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_FileObject.py @@ -1,21 +1,22 @@ - import pytest import tempfile from MDANSE_GUI.PyQtGUI.DataViewModel.TrajectoryHolder import FileObject -reference_bytes = b'TeStCaSeFoRtHeCaChEfuNcTiOn' +reference_bytes = b"TeStCaSeFoRtHeCaChEfuNcTiOn" reference_hash = "7105425fa73f3e6a31b72ae2ee36235bcf1f4883b16e674b80a04d6587d995ec" -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def temporary_fileobject(): fdesc, fname = tempfile.mkstemp() - with open(fname,'wb') as target: + with open(fname, "wb") as target: target.write(reference_bytes) fob = FileObject() fob.setFilename(fname) return fob + def test_hash_value(temporary_fileobject): hash = temporary_fileobject.hash print(hash) diff --git a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_HDF5Trajectory.py b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_HDF5Trajectory.py index 6eae6458a9..d7eb5e9834 100644 --- a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_HDF5Trajectory.py +++ b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_HDF5Trajectory.py @@ -13,37 +13,37 @@ # # ************************************************************************** -#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments -#------------------------------------------------------------------------------------------ -#Copyright (C) -#2015- Eric C. Pellegrini Institut Laue-Langevin -#BP 156 -#6, rue Jules Horowitz -#38042 Grenoble Cedex 9 -#France -#pellegrini[at]ill.fr -#goret[at]ill.fr -#aoun[at]ill.fr +# MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments +# ------------------------------------------------------------------------------------------ +# Copyright (C) +# 2015- Eric C. Pellegrini Institut Laue-Langevin +# BP 156 +# 6, rue Jules Horowitz +# 38042 Grenoble Cedex 9 +# France +# pellegrini[at]ill.fr +# goret[at]ill.fr +# aoun[at]ill.fr # -#This library is free software; you can redistribute it and/or -#modify it under the terms of the GNU Lesser General Public -#License as published by the Free Software Foundation; either -#version 2.1 of the License, or (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. # -#This library is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -#Lesser General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # -#You should have received a copy of the GNU Lesser General Public -#License along with this library; if not, write to the Free Software -#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -''' +""" Created on Feb 17, 2023 @author: Maciej Bartkowiak -''' +""" import pytest import tempfile @@ -55,95 +55,102 @@ from MDANSE.MolecularDynamics.Configuration import RealConfiguration from MDANSE.MolecularDynamics.Trajectory import Trajectory, TrajectoryWriter -N_ATOMS=4 -N_TIMESTEPS=150 +N_ATOMS = 4 +N_TIMESTEPS = 150 -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def chemical_system(): - temp = ChemicalSystem('Dummy test system') + temp = ChemicalSystem("Dummy test system") nAtoms = N_ATOMS for i in range(nAtoms): temp.add_chemical_entity(Atom(symbol="H")) return temp -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def sample_configuration(chemical_system): - unit_cell = 15.0*np.eye(3) - coords = np.empty((N_ATOMS,3), dtype=float) + unit_cell = 15.0 * np.eye(3) + coords = np.empty((N_ATOMS, 3), dtype=float) coords[0] = [1.0, 1.0, 1.0] coords[1] = [1.0, 2.0, 1.0] coords[2] = [10.0, 1.0, 5.11] coords[3] = [10.0, 2.0, 5.09] - temp = RealConfiguration(chemical_system, - coords, - # unit_cell - ) + temp = RealConfiguration( + chemical_system, + coords, + # unit_cell + ) return temp -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def sample_trajectory(chemical_system, sample_configuration): # here we write to a file fdesc, fname = tempfile.mkstemp() os.close(fdesc) - writer = TrajectoryWriter(fname,chemical_system, n_steps = N_TIMESTEPS) + writer = TrajectoryWriter(fname, chemical_system, n_steps=N_TIMESTEPS) for n, ts in enumerate(np.arange(N_TIMESTEPS)): writer.chemical_system.configuration = sample_configuration writer.dump_configuration(ts) return fname -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def gzipped_trajectory(chemical_system, sample_configuration): # here we write to a file fdesc, fname = tempfile.mkstemp() os.close(fdesc) - writer = TrajectoryWriter(fname,chemical_system, n_steps = N_TIMESTEPS, - compression='gzip') + writer = TrajectoryWriter( + fname, chemical_system, n_steps=N_TIMESTEPS, compression="gzip" + ) for n, ts in enumerate(np.arange(N_TIMESTEPS)): writer.chemical_system.configuration = sample_configuration writer.dump_configuration(ts) return fname -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def lzffed_trajectory(chemical_system, sample_configuration): # here we write to a file fdesc, fname = tempfile.mkstemp() os.close(fdesc) - writer = TrajectoryWriter(fname,chemical_system, n_steps = N_TIMESTEPS, - compression='lzf') + writer = TrajectoryWriter( + fname, chemical_system, n_steps=N_TIMESTEPS, compression="lzf" + ) for n, ts in enumerate(np.arange(N_TIMESTEPS)): writer.chemical_system.configuration = sample_configuration writer.dump_configuration(ts) return fname + def test_identity(chemical_system): - temp = ChemicalSystem('Dummy test system') + temp = ChemicalSystem("Dummy test system") nAtoms = N_ATOMS for i in range(nAtoms): temp.add_chemical_entity(Atom(symbol="H")) - assert(temp == chemical_system) - assert(chemical_system == chemical_system) + assert temp == chemical_system + assert chemical_system == chemical_system + -def test_compression(sample_trajectory, - gzipped_trajectory, - lzffed_trajectory): +def test_compression(sample_trajectory, gzipped_trajectory, lzffed_trajectory): size_uncompressed = os.stat(sample_trajectory).st_size size_gzipped = os.stat(gzipped_trajectory).st_size size_lzffed = os.stat(lzffed_trajectory).st_size - assert(size_gzipped < size_uncompressed) - assert(size_lzffed < size_uncompressed) + assert size_gzipped < size_uncompressed + assert size_lzffed < size_uncompressed -def test_losslessness(sample_trajectory, - gzipped_trajectory, - lzffed_trajectory): + +def test_losslessness(sample_trajectory, gzipped_trajectory, lzffed_trajectory): traj = Trajectory(sample_trajectory) traj_gz = Trajectory(gzipped_trajectory) traj_lzf = Trajectory(lzffed_trajectory) - assert(len(traj) == len(traj_gz)) - assert(len(traj) == len(traj_lzf)) + assert len(traj) == len(traj_gz) + assert len(traj) == len(traj_lzf) for step_number in range(len(traj)): - assert(np.allclose(traj.coordinates(step_number), - traj_gz.coordinates(step_number))) - assert(np.allclose(traj.coordinates(step_number), - traj_lzf.coordinates(step_number))) - - + assert np.allclose( + traj.coordinates(step_number), traj_gz.coordinates(step_number) + ) + assert np.allclose( + traj.coordinates(step_number), traj_lzf.coordinates(step_number) + ) diff --git a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_hdf5wrapper.py b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_hdf5wrapper.py index 175691dcf4..be3140920e 100644 --- a/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_hdf5wrapper.py +++ b/MDANSE_GUI/Tests/UnitTests/PyQtGUI/test_hdf5wrapper.py @@ -13,37 +13,37 @@ # # ************************************************************************** -#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments -#------------------------------------------------------------------------------------------ -#Copyright (C) -#2015- Eric C. Pellegrini Institut Laue-Langevin -#BP 156 -#6, rue Jules Horowitz -#38042 Grenoble Cedex 9 -#France -#pellegrini[at]ill.fr -#goret[at]ill.fr -#aoun[at]ill.fr +# MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments +# ------------------------------------------------------------------------------------------ +# Copyright (C) +# 2015- Eric C. Pellegrini Institut Laue-Langevin +# BP 156 +# 6, rue Jules Horowitz +# 38042 Grenoble Cedex 9 +# France +# pellegrini[at]ill.fr +# goret[at]ill.fr +# aoun[at]ill.fr # -#This library is free software; you can redistribute it and/or -#modify it under the terms of the GNU Lesser General Public -#License as published by the Free Software Foundation; either -#version 2.1 of the License, or (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. # -#This library is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -#Lesser General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # -#You should have received a copy of the GNU Lesser General Public -#License along with this library; if not, write to the Free Software -#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -''' +""" Created on Feb 17, 2023 @author: Maciej Bartkowiak -''' +""" import pytest import tempfile @@ -58,48 +58,56 @@ from MDANSE_GUI.PyQtGUI.MolecularViewer.readers.hdf5wrapper import HDF5Wrapper -N_ATOMS=4 -N_TIMESTEPS=150 +N_ATOMS = 4 +N_TIMESTEPS = 150 -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def chemical_system(): - temp = ChemicalSystem('Dummy test system') + temp = ChemicalSystem("Dummy test system") nAtoms = N_ATOMS for i in range(nAtoms): temp.add_chemical_entity(Atom(symbol="H")) return temp -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def sample_configuration(chemical_system): - unit_cell = 15.0*np.eye(3) - coords = np.empty((N_ATOMS,3), dtype=float) + unit_cell = 15.0 * np.eye(3) + coords = np.empty((N_ATOMS, 3), dtype=float) coords[0] = [1.0, 1.0, 1.0] coords[1] = [1.0, 2.0, 1.0] coords[2] = [10.0, 1.0, 5.11] coords[3] = [10.0, 2.0, 5.09] - temp = RealConfiguration(chemical_system, - coords, - # unit_cell - ) + temp = RealConfiguration( + chemical_system, + coords, + # unit_cell + ) return temp -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def sample_trajectory(chemical_system, sample_configuration): # here we write to a file fdesc, fname = tempfile.mkstemp() os.close(fdesc) - writer = TrajectoryWriter(fname,chemical_system, n_steps = N_TIMESTEPS) + writer = TrajectoryWriter(fname, chemical_system, n_steps=N_TIMESTEPS) for n, ts in enumerate(np.arange(N_TIMESTEPS)): writer.chemical_system.configuration = sample_configuration writer.dump_configuration(ts) return fname -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def wrapper(sample_trajectory): traj_object = HDFTrajectoryInputData(sample_trajectory) - wrapper = HDF5Wrapper(sample_trajectory, traj_object.trajectory, traj_object.chemical_system) + wrapper = HDF5Wrapper( + sample_trajectory, traj_object.trajectory, traj_object.chemical_system + ) return wrapper + def test_frame_read(wrapper: HDF5Wrapper): coords = wrapper.read_frame(0) assert len(coords.shape) == 2