diff --git a/diceplayer/__init__.py b/diceplayer/__init__.py index 91ff496..5e16c04 100644 --- a/diceplayer/__init__.py +++ b/diceplayer/__init__.py @@ -1,4 +1,4 @@ -from diceplayer.shared.utils.logger import Logger +from diceplayer.utils import Logger from importlib import metadata diff --git a/diceplayer/environment/__init__.py b/diceplayer/environment/__init__.py new file mode 100644 index 0000000..8490224 --- /dev/null +++ b/diceplayer/environment/__init__.py @@ -0,0 +1,6 @@ +from .atom import Atom +from .molecule import Molecule +from .system import System + + +__all__ = ["Atom", "Molecule", "System"] diff --git a/diceplayer/shared/environment/atom.py b/diceplayer/environment/atom.py similarity index 97% rename from diceplayer/shared/environment/atom.py rename to diceplayer/environment/atom.py index 2f0e40d..a9a9801 100644 --- a/diceplayer/shared/environment/atom.py +++ b/diceplayer/environment/atom.py @@ -1,4 +1,4 @@ -from diceplayer.shared.utils.ptable import atommass +from diceplayer.utils.ptable import atommass class Atom: diff --git a/diceplayer/shared/environment/molecule.py b/diceplayer/environment/molecule.py similarity index 98% rename from diceplayer/shared/environment/molecule.py rename to diceplayer/environment/molecule.py index 24ee1fd..24053ee 100644 --- a/diceplayer/shared/environment/molecule.py +++ b/diceplayer/environment/molecule.py @@ -7,9 +7,9 @@ if TYPE_CHECKING: from nptyping import Float, NDArray, Shape from diceplayer import logger -from diceplayer.shared.environment.atom import Atom -from diceplayer.shared.utils.misc import BOHR2ANG -from diceplayer.shared.utils.ptable import ghost_number +from diceplayer.environment.atom import Atom +from diceplayer.utils.misc import BOHR2ANG +from diceplayer.utils.ptable import ghost_number import numpy as np from numpy.linalg import linalg diff --git a/diceplayer/shared/environment/system.py b/diceplayer/environment/system.py similarity index 98% rename from diceplayer/shared/environment/system.py rename to diceplayer/environment/system.py index 6aed828..ecb4aad 100644 --- a/diceplayer/shared/environment/system.py +++ b/diceplayer/environment/system.py @@ -1,6 +1,6 @@ from diceplayer import logger -from diceplayer.shared.environment.molecule import Molecule -from diceplayer.shared.utils.misc import BOHR2ANG +from diceplayer.environment.molecule import Molecule +from diceplayer.utils.misc import BOHR2ANG import numpy as np from numpy import linalg diff --git a/diceplayer/interface/__init__.py b/diceplayer/interface/__init__.py new file mode 100644 index 0000000..aaedaa1 --- /dev/null +++ b/diceplayer/interface/__init__.py @@ -0,0 +1,6 @@ +from .__interface import Interface +from .dice_interface import DiceInterface +from .gaussian_interface import GaussianInterface + + +__all__ = ["Interface", "DiceInterface", "GaussianInterface"] diff --git a/diceplayer/shared/interface/__interface.py b/diceplayer/interface/__interface.py similarity index 90% rename from diceplayer/shared/interface/__interface.py rename to diceplayer/interface/__interface.py index bc02d86..95829e8 100644 --- a/diceplayer/shared/interface/__interface.py +++ b/diceplayer/interface/__interface.py @@ -1,7 +1,7 @@ from __future__ import annotations from diceplayer.config.player_config import PlayerConfig -from diceplayer.shared.environment.system import System +from diceplayer.environment.system import System from abc import ABC, abstractmethod diff --git a/diceplayer/shared/interface/dice_interface.py b/diceplayer/interface/dice_interface.py similarity index 99% rename from diceplayer/shared/interface/dice_interface.py rename to diceplayer/interface/dice_interface.py index af2637e..1f23c9c 100644 --- a/diceplayer/shared/interface/dice_interface.py +++ b/diceplayer/interface/dice_interface.py @@ -2,8 +2,8 @@ from __future__ import annotations from diceplayer import logger from diceplayer.config.player_config import PlayerConfig -from diceplayer.shared.environment.system import System -from diceplayer.shared.interface import Interface +from diceplayer.environment.system import System +from diceplayer.interface import Interface from setproctitle import setproctitle from typing_extensions import Final, TextIO diff --git a/diceplayer/shared/interface/gaussian_interface.py b/diceplayer/interface/gaussian_interface.py similarity index 97% rename from diceplayer/shared/interface/gaussian_interface.py rename to diceplayer/interface/gaussian_interface.py index cd76aad..cd4bc85 100644 --- a/diceplayer/shared/interface/gaussian_interface.py +++ b/diceplayer/interface/gaussian_interface.py @@ -2,12 +2,12 @@ from __future__ import annotations from diceplayer import logger from diceplayer.config.player_config import PlayerConfig -from diceplayer.shared.environment.atom import Atom -from diceplayer.shared.environment.molecule import Molecule -from diceplayer.shared.environment.system import System -from diceplayer.shared.interface import Interface -from diceplayer.shared.utils.misc import date_time -from diceplayer.shared.utils.ptable import atomsymb +from diceplayer.environment.atom import Atom +from diceplayer.environment.molecule import Molecule +from diceplayer.environment.system import System +from diceplayer.interface import Interface +from diceplayer.utils.misc import date_time +from diceplayer.utils.ptable import atomsymb import numpy as np from nptyping import NDArray diff --git a/diceplayer/player.py b/diceplayer/player.py index 2ed23f7..f711088 100644 --- a/diceplayer/player.py +++ b/diceplayer/player.py @@ -1,12 +1,8 @@ from diceplayer import VERSION, logger from diceplayer.config.player_config import PlayerConfig -from diceplayer.shared.environment.atom import Atom -from diceplayer.shared.environment.molecule import Molecule -from diceplayer.shared.environment.system import System -from diceplayer.shared.interface.dice_interface import DiceInterface -from diceplayer.shared.interface.gaussian_interface import GaussianInterface -from diceplayer.shared.utils.misc import weekday_date_time -from diceplayer.shared.utils.ptable import atomsymb +from diceplayer.environment import Atom, Molecule, System +from diceplayer.interface import DiceInterface, GaussianInterface +from diceplayer.utils import atomsymb, weekday_date_time import yaml from pydantic import BaseModel diff --git a/diceplayer/shared/__init__.py b/diceplayer/shared/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/diceplayer/shared/environment/__init__.py b/diceplayer/shared/environment/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/diceplayer/shared/interface/__init__.py b/diceplayer/shared/interface/__init__.py deleted file mode 100644 index 49adea0..0000000 --- a/diceplayer/shared/interface/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .__interface import Interface - - -__all__ = ["Interface"] diff --git a/diceplayer/shared/utils/__init__.py b/diceplayer/shared/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/diceplayer/utils/__init__.py b/diceplayer/utils/__init__.py new file mode 100644 index 0000000..c5d280c --- /dev/null +++ b/diceplayer/utils/__init__.py @@ -0,0 +1,22 @@ +from .logger import Logger, valid_logger +from .misc import ( + compress_files_1mb, + date_time, + make_qm_dir, + make_step_dir, + weekday_date_time, +) +from .ptable import atommass, atomsymb + + +__all__ = [ + "Logger", + "valid_logger", + "atomsymb", + "atommass", + "weekday_date_time", + "date_time", + "compress_files_1mb", + "make_step_dir", + "make_qm_dir", +] diff --git a/diceplayer/shared/utils/dataclass_protocol.py b/diceplayer/utils/dataclass_protocol.py similarity index 100% rename from diceplayer/shared/utils/dataclass_protocol.py rename to diceplayer/utils/dataclass_protocol.py diff --git a/diceplayer/shared/utils/logger.py b/diceplayer/utils/logger.py similarity index 100% rename from diceplayer/shared/utils/logger.py rename to diceplayer/utils/logger.py diff --git a/diceplayer/shared/utils/misc.py b/diceplayer/utils/misc.py similarity index 100% rename from diceplayer/shared/utils/misc.py rename to diceplayer/utils/misc.py diff --git a/diceplayer/shared/utils/ptable.py b/diceplayer/utils/ptable.py similarity index 100% rename from diceplayer/shared/utils/ptable.py rename to diceplayer/utils/ptable.py diff --git a/tests/shared/environment/test_atom.py b/tests/shared/environment/test_atom.py index 78e7fa5..e3de502 100644 --- a/tests/shared/environment/test_atom.py +++ b/tests/shared/environment/test_atom.py @@ -1,4 +1,4 @@ -from diceplayer.shared.environment.atom import Atom +from diceplayer.environment import Atom import unittest diff --git a/tests/shared/environment/test_molecule.py b/tests/shared/environment/test_molecule.py index 28ad01e..c910390 100644 --- a/tests/shared/environment/test_molecule.py +++ b/tests/shared/environment/test_molecule.py @@ -1,5 +1,4 @@ -from diceplayer.shared.environment.atom import Atom -from diceplayer.shared.environment.molecule import Molecule +from diceplayer.environment import Atom, Molecule import numpy as np import numpy.testing as npt diff --git a/tests/shared/environment/test_system.py b/tests/shared/environment/test_system.py index cbb93b8..3a73539 100644 --- a/tests/shared/environment/test_system.py +++ b/tests/shared/environment/test_system.py @@ -1,5 +1,4 @@ -from diceplayer.shared.environment.molecule import Molecule -from diceplayer.shared.environment.system import System +from diceplayer.environment import Molecule, System import unittest diff --git a/tests/shared/interface/test_dice_interface.py b/tests/shared/interface/test_dice_interface.py index 0eeb075..339a209 100644 --- a/tests/shared/interface/test_dice_interface.py +++ b/tests/shared/interface/test_dice_interface.py @@ -1,9 +1,7 @@ from diceplayer import logger from diceplayer.config.player_config import PlayerConfig -from diceplayer.shared.environment.atom import Atom -from diceplayer.shared.environment.molecule import Molecule -from diceplayer.shared.environment.system import System -from diceplayer.shared.interface.dice_interface import DiceInterface +from diceplayer.environment import Atom, Molecule, System +from diceplayer.interface import DiceInterface from tests.mocks.mock_inputs import get_config_example from tests.mocks.mock_proc import MockConnection, MockProc @@ -51,18 +49,16 @@ class TestDiceInterface(unittest.TestCase): self.assertFalse(hasattr(dice, "step")) self.assertFalse(hasattr(dice, "system")) - @mock.patch("diceplayer.shared.interface.dice_interface.Process", MockProc()) - @mock.patch("diceplayer.shared.interface.dice_interface.connection", MockConnection) + @mock.patch("diceplayer.interface.dice_interface.Process", MockProc()) + @mock.patch("diceplayer.interface.dice_interface.connection", MockConnection) def test_start(self): dice = DiceInterface() dice.configure(self.config, System()) dice.start(1) - @mock.patch("diceplayer.shared.interface.dice_interface.connection", MockConnection) - @mock.patch( - "diceplayer.shared.interface.dice_interface.Process", MockProc(exitcode=1) - ) + @mock.patch("diceplayer.interface.dice_interface.connection", MockConnection) + @mock.patch("diceplayer.interface.dice_interface.Process", MockProc(exitcode=1)) def test_start_with_process_error(self): dice = DiceInterface() dice.configure(self.config, System()) @@ -76,13 +72,9 @@ class TestDiceInterface(unittest.TestCase): with self.assertRaises(SystemExit): dice._simulation_process(1, 1) - @mock.patch( - "diceplayer.shared.interface.dice_interface.DiceInterface._make_proc_dir" - ) - @mock.patch( - "diceplayer.shared.interface.dice_interface.DiceInterface._make_dice_inputs" - ) - @mock.patch("diceplayer.shared.interface.dice_interface.DiceInterface._run_dice") + @mock.patch("diceplayer.interface.dice_interface.DiceInterface._make_proc_dir") + @mock.patch("diceplayer.interface.dice_interface.DiceInterface._make_dice_inputs") + @mock.patch("diceplayer.interface.dice_interface.DiceInterface._run_dice") def test_simulation_process( self, mock_run_dice, mock_make_dice_inputs, mock_make_proc_dir ): @@ -94,8 +86,8 @@ class TestDiceInterface(unittest.TestCase): self.assertTrue(dice._make_dice_inputs.called) self.assertTrue(dice._run_dice.called) - @mock.patch("diceplayer.shared.interface.dice_interface.Path.mkdir") - @mock.patch("diceplayer.shared.interface.dice_interface.Path.exists") + @mock.patch("diceplayer.interface.dice_interface.Path.mkdir") + @mock.patch("diceplayer.interface.dice_interface.Path.exists") def test_make_proc_dir_if_simdir_exists(self, mock_path_exists, mock_path_mkdir): dice = DiceInterface() dice.configure(self.config, System()) @@ -106,8 +98,8 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(mock_path_mkdir.call_count, 2) - @mock.patch("diceplayer.shared.interface.dice_interface.Path.mkdir") - @mock.patch("diceplayer.shared.interface.dice_interface.Path.exists") + @mock.patch("diceplayer.interface.dice_interface.Path.mkdir") + @mock.patch("diceplayer.interface.dice_interface.Path.exists") def test_make_proc_dir_if_simdir_doesnt_exists( self, mock_path_exists, mock_path_mkdir ): @@ -155,9 +147,7 @@ class TestDiceInterface(unittest.TestCase): self.assertFalse(dice._make_npt_eq.called) @mock.patch("builtins.open", new_callable=mock.mock_open, read_data="test") - @mock.patch( - "diceplayer.shared.interface.dice_interface.Path.exists", return_value=True - ) + @mock.patch("diceplayer.interface.dice_interface.Path.exists", return_value=True) def test_make_dice_inputs_nstep_len_two_with_randoninit_first_cycle_two( self, mock_path_exists, mock_open ): @@ -189,9 +179,7 @@ class TestDiceInterface(unittest.TestCase): self.assertFalse(dice._make_npt_ter.called) self.assertFalse(dice._make_npt_eq.called) - @mock.patch( - "diceplayer.shared.interface.dice_interface.Path.exists", return_value=False - ) + @mock.patch("diceplayer.interface.dice_interface.Path.exists", return_value=False) def test_make_dice_inputs_raises_exception_on_last_not_found( self, mock_path_exists ): @@ -240,11 +228,9 @@ class TestDiceInterface(unittest.TestCase): self.assertTrue(dice._make_npt_ter.called) self.assertTrue(dice._make_npt_eq.called) - @mock.patch("diceplayer.shared.interface.dice_interface.os") - @mock.patch("diceplayer.shared.interface.dice_interface.shutil") - @mock.patch( - "diceplayer.shared.interface.dice_interface.Path.exists", return_value=True - ) + @mock.patch("diceplayer.interface.dice_interface.os") + @mock.patch("diceplayer.interface.dice_interface.shutil") + @mock.patch("diceplayer.interface.dice_interface.Path.exists", return_value=True) def test_run_dice_on_first_cycle_run_successful( self, mock_path_exists, mock_shutils, mock_os ): @@ -278,11 +264,9 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(dice.run_dice_file.call_count, 2) self.assertTrue(mock_shutils.copy.called) - @mock.patch("diceplayer.shared.interface.dice_interface.os") - @mock.patch("diceplayer.shared.interface.dice_interface.shutil") - @mock.patch( - "diceplayer.shared.interface.dice_interface.Path.exists", return_value=True - ) + @mock.patch("diceplayer.interface.dice_interface.os") + @mock.patch("diceplayer.interface.dice_interface.shutil") + @mock.patch("diceplayer.interface.dice_interface.Path.exists", return_value=True) def test_run_dice_on_second_cycle_run_successful( self, mock_path_exists, mock_shutils, mock_os ): @@ -312,11 +296,9 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(dice.run_dice_file.call_count, 2) self.assertTrue(mock_shutils.copy.called) - @mock.patch("diceplayer.shared.interface.dice_interface.os") - @mock.patch("diceplayer.shared.interface.dice_interface.shutil") - @mock.patch( - "diceplayer.shared.interface.dice_interface.Path.exists", return_value=False - ) + @mock.patch("diceplayer.interface.dice_interface.os") + @mock.patch("diceplayer.interface.dice_interface.shutil") + @mock.patch("diceplayer.interface.dice_interface.Path.exists", return_value=False) def test_run_dice_raises_filenotfound_on_invalid_file( self, mock_path_exists, mock_shutils, mock_os ): @@ -424,7 +406,7 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(density, 85.35451545000001) @mock.patch("builtins.open", new_callable=mock.mock_open) - @mock.patch("diceplayer.shared.interface.dice_interface.random") + @mock.patch("diceplayer.interface.dice_interface.random") def test_make_nvt_ter(self, mock_random, mock_open): mock_random.random.return_value = 1 @@ -461,7 +443,7 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(lines, expected_lines) @mock.patch("builtins.open", new_callable=mock.mock_open) - @mock.patch("diceplayer.shared.interface.dice_interface.random") + @mock.patch("diceplayer.interface.dice_interface.random") def test_make_nvt_eq(self, mock_random, mock_open): mock_random.random.return_value = 1 @@ -497,7 +479,7 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(lines, expected_lines) @mock.patch("builtins.open", new_callable=mock.mock_open) - @mock.patch("diceplayer.shared.interface.dice_interface.random") + @mock.patch("diceplayer.interface.dice_interface.random") def test_make_npt_ter(self, mock_random, mock_open): mock_random.random.return_value = 1 @@ -533,7 +515,7 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(lines, expected_lines) @mock.patch("builtins.open", new_callable=mock.mock_open) - @mock.patch("diceplayer.shared.interface.dice_interface.random") + @mock.patch("diceplayer.interface.dice_interface.random") def test_make_npt_eq(self, mock_random, mock_open): mock_random.random.return_value = 1 @@ -612,7 +594,7 @@ class TestDiceInterface(unittest.TestCase): self.assertEqual(lines, expected_lines) - @mock.patch("diceplayer.shared.interface.dice_interface.subprocess") + @mock.patch("diceplayer.interface.dice_interface.subprocess") @mock.patch( "builtins.open", new_callable=mock.mock_open, @@ -628,7 +610,7 @@ class TestDiceInterface(unittest.TestCase): self.assertTrue(mock_subprocess.call.called) self.assertTrue(mock_open.called) - @mock.patch("diceplayer.shared.interface.dice_interface.subprocess") + @mock.patch("diceplayer.interface.dice_interface.subprocess") @mock.patch("builtins.open", new_callable=mock.mock_open, read_data="Error\nBLABLA") def test_run_dice_file_raises_runtime_error_on_dice_file( self, mock_open, mock_subprocess @@ -640,7 +622,7 @@ class TestDiceInterface(unittest.TestCase): with self.assertRaises(RuntimeError): dice.run_dice_file(1, 1, "test") - @mock.patch("diceplayer.shared.interface.dice_interface.subprocess") + @mock.patch("diceplayer.interface.dice_interface.subprocess") @mock.patch( "builtins.open", new_callable=mock.mock_open, diff --git a/tests/shared/interface/test_gaussian_interface.py b/tests/shared/interface/test_gaussian_interface.py index 723de74..3ca5381 100644 --- a/tests/shared/interface/test_gaussian_interface.py +++ b/tests/shared/interface/test_gaussian_interface.py @@ -1,7 +1,7 @@ from diceplayer import logger from diceplayer.config.player_config import PlayerConfig -from diceplayer.shared.environment.system import System -from diceplayer.shared.interface.gaussian_interface import GaussianInterface +from diceplayer.environment import System +from diceplayer.interface import GaussianInterface from tests.mocks.mock_inputs import get_config_example import yaml @@ -46,8 +46,8 @@ class TestGaussianInterface(unittest.TestCase): self.assertFalse(hasattr(gaussian_interface, "step")) self.assertFalse(hasattr(gaussian_interface, "system")) - @mock.patch("diceplayer.shared.interface.gaussian_interface.Path.mkdir") - @mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists") + @mock.patch("diceplayer.interface.gaussian_interface.Path.mkdir") + @mock.patch("diceplayer.interface.gaussian_interface.Path.exists") def test_make_qm_dir(self, mock_exists, mock_mkdir): mock_exists.return_value = False @@ -59,8 +59,8 @@ class TestGaussianInterface(unittest.TestCase): mock_exists.assert_called_once() mock_mkdir.assert_called_once() - @mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy") - @mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists") + @mock.patch("diceplayer.interface.gaussian_interface.shutil.copy") + @mock.patch("diceplayer.interface.gaussian_interface.Path.exists") def test_copy_chk_file_from_previous_step(self, mock_exists, mock_copy): gaussian_interface = GaussianInterface() gaussian_interface.configure(self.config, System()) @@ -72,8 +72,8 @@ class TestGaussianInterface(unittest.TestCase): self.assertTrue(mock_exists.called) self.assertTrue(mock_copy.called) - @mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy") - @mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists") + @mock.patch("diceplayer.interface.gaussian_interface.shutil.copy") + @mock.patch("diceplayer.interface.gaussian_interface.Path.exists") def test_copy_chk_file_from_previous_step_no_previous_step( self, mock_exists, mock_copy ): @@ -85,8 +85,8 @@ class TestGaussianInterface(unittest.TestCase): with self.assertRaises(FileNotFoundError): gaussian_interface._copy_chk_file_from_previous_step(2) - @mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy") - @mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists") + @mock.patch("diceplayer.interface.gaussian_interface.shutil.copy") + @mock.patch("diceplayer.interface.gaussian_interface.Path.exists") def test_copy_chk_file_from_previous_step_current_exists( self, mock_exists, mock_copy ): diff --git a/tests/shared/utils/test_logger.py b/tests/shared/utils/test_logger.py index 2fd776f..b3bba51 100644 --- a/tests/shared/utils/test_logger.py +++ b/tests/shared/utils/test_logger.py @@ -1,4 +1,4 @@ -from diceplayer.shared.utils.logger import Logger, valid_logger +from diceplayer.utils import Logger, valid_logger import io import logging @@ -53,8 +53,8 @@ class TestLogger(unittest.TestCase): self.assertEqual(logger._logger.name, "test") @mock.patch("builtins.open", mock.mock_open()) - @mock.patch("diceplayer.shared.utils.logger.Path.exists") - @mock.patch("diceplayer.shared.utils.logger.Path.rename") + @mock.patch("diceplayer.utils.logger.Path.exists") + @mock.patch("diceplayer.utils.logger.Path.rename") def test_set_logger_if_file_exists(self, mock_rename, mock_exists): logger = Logger("test") @@ -66,8 +66,8 @@ class TestLogger(unittest.TestCase): self.assertEqual(logger._logger.name, "test") @mock.patch("builtins.open", mock.mock_open()) - @mock.patch("diceplayer.shared.utils.logger.Path.exists") - @mock.patch("diceplayer.shared.utils.logger.Path.rename") + @mock.patch("diceplayer.utils.logger.Path.exists") + @mock.patch("diceplayer.utils.logger.Path.rename") def test_set_logger_if_file_not_exists(self, mock_rename, mock_exists): logger = Logger("test")