Esempio n. 1
0
 def test_integer_casting_dimension(self):
     setting.reset()
     # noinspection PyTypeChecker
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=2.8, system_length=1.0)
     self.assertEqual(setting.dimension, 2)
     self.assertEqual(hypercubic_setting.dimension, 2)
     self.assertEqual(hypercuboid_setting.dimension, 2)
Esempio n. 2
0
 def test_not_matching_system_lengths_raises_error(self):
     # PDB file has system_length=10.261
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=10.26)
     with self.assertRaises(ConfigurationError):
         PdbInputHandler("pdb_test_files/water_test_origin_0.pdb")
Esempio n. 3
0
    def setUp(self) -> None:
        hypercubic_setting.HypercubicSetting(beta=1.0,
                                             dimension=2,
                                             system_length=1.0)
        setting.set_number_of_node_levels(1)
        setting.set_number_of_nodes_per_root_node(1)
        setting.set_number_of_root_nodes(1)
        self._estimator_mock = mock.MagicMock(spec_set=Estimator)
        self._estimator_mock.derivative_bound.side_effect = mock_derivative_bound
        self._estimator_mock.charge_correction_factor = mock_charge_correction_factor
        # self._cells has the cell 0 with cell_min at the origin as the zero cell.
        self._cells = CuboidPeriodicCells(cells_per_side=[4, 4],
                                          neighbor_layers=1)
        self._cell_bounding_potential_without_charge = CellBoundingPotential(
            estimator=self._estimator_mock)
        self._cell_bounding_potential_with_charge = CellBoundingPotential(
            estimator=self._estimator_mock)

        # Redirect stdout to the null device while initializing the estimator
        with open(os.devnull, 'w') as devnull:
            with contextlib.redirect_stdout(devnull):
                self._cell_bounding_potential_without_charge.initialize(
                    self._cells, False)
                self._cell_bounding_potential_with_charge.initialize(
                    self._cells, True)
Esempio n. 4
0
 def test_non_equal_composite_point_objects_raises_error(self):
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=10.261)
     with self.assertRaises(ConfigurationError):
         PdbInputHandler(
             "pdb_test_files/test_non_equal_composite_point_objects.pdb")
Esempio n. 5
0
    def test_two_dimensional_pdb_file(self):
        hypercubic_setting.HypercubicSetting(beta=1.0,
                                             dimension=2,
                                             system_length=1.0)
        # Ignore warnings in logger
        logging.getLogger(
            "jellyfysh.input_output_handler.input_handler.pdb_input_handler"
        ).setLevel(logging.ERROR)

        electric_charge_values = ChargeValues([-1.0], "electric_charge")
        # This file also contains positions outside the system box which should be corrected for periodic boundaries
        pdb_input_handler = PdbInputHandler("pdb_test_files/atom_test_2D.pdb",
                                            [electric_charge_values])
        state = pdb_input_handler.read()
        self.assertEqual(len(state), 2)

        atom_one = state[0]
        self.assertIsNone(atom_one.parent)
        self.assertEqual(atom_one.weight, 1.0)
        self.assertEqual(atom_one.value.charge, {"electric_charge": -1.0})
        self.assertEqual(len(atom_one.value.position), 2)
        # MDAnalysis only uses c floats (not doubles) -> reduce precision
        self.assertAlmostEqual(atom_one.value.position[0], 0.983, places=6)
        self.assertAlmostEqual(atom_one.value.position[1], 0.032, places=6)
        self.assertEqual(len(atom_one.children), 0)

        atom_two = state[1]
        self.assertIsNone(atom_two.parent)
        self.assertEqual(atom_two.weight, 1.0)
        self.assertEqual(atom_two.value.charge, {"electric_charge": -1.0})
        self.assertEqual(len(atom_two.value.position), 2)
        # MDAnalysis only uses c floats (not doubles) -> reduce precision
        self.assertAlmostEqual(atom_two.value.position[0], 0.618, places=6)
        self.assertAlmostEqual(atom_two.value.position[1], 0.697, places=6)
        self.assertEqual(len(atom_two.children), 0)
Esempio n. 6
0
    def setUp(self) -> None:
        hypercubic_setting.HypercubicSetting(beta=1.0,
                                             dimension=2,
                                             system_length=1.0)
        self._bounding_potential_mock_without_charge = mock.MagicMock(
            spec_set=InvertiblePotential)
        self._bounding_potential_mock_without_charge.number_separation_arguments = 1
        self._bounding_potential_mock_without_charge.number_charge_arguments = 0
        self._bounding_potential_mock_without_charge.potential_change_required = True
        self._potential_mock_without_charge = mock.MagicMock(
            spec_set=Potential)
        self._potential_mock_without_charge.number_separation_arguments = 1
        self._potential_mock_without_charge.number_charge_arguments = 0
        self._event_handler_without_charge = TwoLeafUnitBoundingPotentialEventHandler(
            potential=self._potential_mock_without_charge,
            bounding_potential=self._bounding_potential_mock_without_charge)

        self._bounding_potential_mock_with_charge = mock.MagicMock(
            spec_set=InvertiblePotential)
        self._bounding_potential_mock_with_charge.number_separation_arguments = 1
        self._bounding_potential_mock_with_charge.number_charge_arguments = 2
        self._bounding_potential_mock_with_charge.potential_change_required = True
        self._potential_mock_with_charge = mock.MagicMock(spec_set=Potential)
        self._potential_mock_with_charge.number_separation_arguments = 1
        self._potential_mock_with_charge.number_charge_arguments = 2
        self._event_handler_with_charge = TwoLeafUnitBoundingPotentialEventHandler(
            potential=self._potential_mock_with_charge,
            bounding_potential=self._bounding_potential_mock_with_charge,
            charge="charge")
Esempio n. 7
0
    def test_pdb_file_atom_origin_l2(self):
        # Origin of system box in pdb file at [-L/2, -L/2, -L/2]
        hypercubic_setting.HypercubicSetting(beta=1.0,
                                             dimension=3,
                                             system_length=1.0)
        electric_charge_values = ChargeValues([1.0], "electric_charge")
        # This file also contains positions outside the system box which should be corrected for periodic boundaries
        with warnings.catch_warnings():
            # Ignore warnings of MDAnalysis
            warnings.simplefilter("ignore", UserWarning)
            pdb_input_handler = PdbInputHandler(
                "pdb_test_files/atom_test_origin_l2.pdb",
                [electric_charge_values])
            state = pdb_input_handler.read()
        self.assertEqual(len(state), 4)

        atom_one = state[0]
        self.assertIsNone(atom_one.parent)
        self.assertEqual(atom_one.weight, 1.0)
        self.assertEqual(atom_one.value.charge, {"electric_charge": 1.0})
        self.assertEqual(len(atom_one.value.position), 3)
        # MDAnalysis only uses c floats (not doubles) -> reduce precision
        self.assertAlmostEqual(atom_one.value.position[0], 0.983, places=6)
        self.assertAlmostEqual(atom_one.value.position[1], 0.032, places=6)
        self.assertAlmostEqual(atom_one.value.position[2], 0.714, places=6)
        self.assertEqual(len(atom_one.children), 0)

        atom_two = state[1]
        self.assertIsNone(atom_two.parent)
        self.assertEqual(atom_two.weight, 1.0)
        self.assertEqual(atom_two.value.charge, {"electric_charge": 1.0})
        self.assertEqual(len(atom_two.value.position), 3)
        # MDAnalysis only uses c floats (not doubles) -> reduce precision
        self.assertAlmostEqual(atom_two.value.position[0], 0.618, places=6)
        self.assertAlmostEqual(atom_two.value.position[1], 0.697, places=6)
        self.assertAlmostEqual(atom_two.value.position[2], 0.848, places=6)
        self.assertEqual(len(atom_two.children), 0)

        atom_three = state[2]
        self.assertIsNone(atom_three.parent)
        self.assertEqual(atom_three.weight, 1.0)
        self.assertEqual(atom_three.value.charge, {"electric_charge": 1.0})
        self.assertEqual(len(atom_three.value.position), 3)
        # MDAnalysis only uses c floats (not doubles) -> reduce precision
        self.assertAlmostEqual(atom_three.value.position[0], 0.312, places=6)
        self.assertAlmostEqual(atom_three.value.position[1], 0.806, places=6)
        self.assertAlmostEqual(atom_three.value.position[2], 0.642, places=6)
        self.assertEqual(len(atom_three.children), 0)

        atom_four = state[3]
        self.assertIsNone(atom_four.parent)
        self.assertEqual(atom_four.weight, 1.0)
        self.assertEqual(atom_four.value.charge, {"electric_charge": 1.0})
        self.assertEqual(len(atom_four.value.position), 3)
        # MDAnalysis only uses c floats (not doubles) -> reduce precision
        self.assertAlmostEqual(atom_four.value.position[0], 0.012, places=6)
        self.assertAlmostEqual(atom_four.value.position[1], 0.923, places=6)
        self.assertAlmostEqual(atom_four.value.position[2], 0.100, places=6)
        self.assertEqual(len(atom_four.children), 0)
Esempio n. 8
0
 def test_correct_periodic_boundary_separation_entry_length_half(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=4, system_length=0.5)
     separation = [-0.25, -0.3, 0.4, 0.25]
     separation[1] = setting.periodic_boundaries.correct_separation_entry(separation[1], 1)
     self.assertAlmostEqualSequence(separation, [-0.25, 0.2, 0.4, 0.25], places=13)
     separation = [-0.1, 0.1, 0.0, 0.05]
     separation[2] = setting.periodic_boundaries.correct_separation_entry(separation[2], 2)
     self.assertAlmostEqualSequence(separation, [-0.1, 0.1, 0.0, 0.05], places=13)
Esempio n. 9
0
 def setUp(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=1.0)
     self._event_handler_one = FinalTimeEndOfRunEventHandler(
         end_of_run_time=0.5, output_handler="some_output_handler")
     self._event_handler_two = FinalTimeEndOfRunEventHandler(
         end_of_run_time=1.3, output_handler="output")
Esempio n. 10
0
 def test_correct_periodic_boundary_separation_entry_length_one(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=4, system_length=1.0)
     separation = [-0.5, -0.3, 0.4, 0.5]
     separation[3] = setting.periodic_boundaries.correct_separation_entry(separation[3], 3)
     self.assertAlmostEqualSequence(separation, [-0.5, -0.3, 0.4, -0.5], places=13)
     separation = [-0.6, 1.3, 0.4, 0.9]
     separation[0] = setting.periodic_boundaries.correct_separation_entry(separation[0], 0)
     self.assertAlmostEqualSequence(separation, [0.4, 1.3, 0.4, 0.9], places=13)
Esempio n. 11
0
 def test_number_of_node_levels_one_raises_error(self):
     setting.reset()
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=1.0)
     setting.set_number_of_node_levels(1)
     with self.assertRaises(ConfigurationError):
         self._event_handler_to_root_unit_motion = RootLeafUnitActiveSwitcher(
             chain_length=0.5, aim_mode="leaf_unit_active")
Esempio n. 12
0
 def setUp(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=1.0)
     setting.set_number_of_node_levels(2)
     self._event_handler_to_root_unit_motion = RootLeafUnitActiveSwitcher(
         chain_length=0.5, aim_mode="root_unit_active")
     self._event_handler_to_leaf_unit_motion = RootLeafUnitActiveSwitcher(
         chain_length=0.7, aim_mode="leaf_unit_active")
Esempio n. 13
0
 def test_no_charge_for_every_point_mass_raises_error(self):
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=10.261)
     # Only specify two charges although three are required
     electric_charge_values = ChargeValues([0.41, -0.82], "electric_charge")
     with self.assertRaises(ConfigurationError):
         PdbInputHandler("pdb_test_files/water_test_origin_0.pdb",
                         [electric_charge_values])
Esempio n. 14
0
 def setUp(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=1.0)
     # Set these so the settings are initialized
     setting.set_number_of_root_nodes(2)
     setting.set_number_of_nodes_per_root_node(2)
     setting.set_number_of_node_levels(1)
     # noinspection PyArgumentEqualDefault
     self._potential = InversePowerCoulombBoundingPotential(prefactor=1.6)
Esempio n. 15
0
 def test_two_dimensional_pdb_file_contains_three_dimensional_system_box_raises_error(
         self):
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=2,
                                          system_length=1.0)
     # Ignore warnings in logger
     logging.getLogger(
         "jellyfysh.input_output_handler.input_handler.pdb_input_handler"
     ).setLevel(logging.ERROR)
     with self.assertRaises(ConfigurationError):
         PdbInputHandler("pdb_test_files/atom_test_2D_wrong_system_box.pdb")
Esempio n. 16
0
 def test_correct_periodic_boundary_separation_length_one(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=4, system_length=1.0)
     separation = [-0.5, -0.3, 0.4, 0.5]
     setting.periodic_boundaries.correct_separation(separation)
     self.assertAlmostEqualSequence(separation, [-0.5, -0.3, 0.4, -0.5], places=13)
     separation = [-0.6, 1.3, 0.4, 0.9]
     setting.periodic_boundaries.correct_separation(separation)
     self.assertAlmostEqualSequence(separation, [0.4, 0.3, 0.4, -0.1], places=13)
     setting.system_length = None
     setting.system_length_over_two = None
     setting.dimension = None
Esempio n. 17
0
 def setUp(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=1.0)
     self._event_handler_one = InitialChainStartOfRunEventHandler(
         initial_direction_of_motion=0,
         speed=1.0,
         initial_active_identifier=[0])
     self._event_handler_two = InitialChainStartOfRunEventHandler(
         initial_direction_of_motion=2,
         speed=0.5,
         initial_active_identifier=[0, 1])
Esempio n. 18
0
 def test_repeated_charge_name_raises_error(self):
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=10.261)
     # Create two charge values with the same name
     electric_charge_values = ChargeValues([0.41, -0.82, 0.41],
                                           "electric_charge")
     oxygen_indicator_charge = ChargeValues([0.0, 1.0, 0.0],
                                            "electric_charge")
     with self.assertRaises(ConfigurationError):
         PdbInputHandler("pdb_test_files/water_test_origin_0.pdb",
                         [electric_charge_values, oxygen_indicator_charge])
Esempio n. 19
0
 def test_dimension_unequal_three_raises_error(self):
     setting.reset()
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=2,
                                          system_length=1.0)
     # Set these so the settings are initialized
     setting.set_number_of_root_nodes(2)
     setting.set_number_of_nodes_per_root_node(2)
     setting.set_number_of_node_levels(1)
     with self.assertRaises(ConfigurationError):
         self._potential = InversePowerCoulombBoundingPotential(
             prefactor=1.6)
Esempio n. 20
0
 def setUpSystemLengthTwo(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=3,
                                          system_length=2.0)
     setting.set_number_of_root_nodes(2)
     setting.set_number_of_nodes_per_root_node(2)
     setting.set_number_of_node_levels(1)
     self._potential = MergedImageCoulombPotential(alpha=3.45,
                                                   fourier_cutoff=6,
                                                   position_cutoff=2,
                                                   prefactor=1.0)
     self._variant_potential = MergedImageCoulombPotential(
         alpha=5.0, fourier_cutoff=9, position_cutoff=2)
Esempio n. 21
0
 def test_correct_periodic_boundary_position_entry_system_length_two(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0)
     position = [0.1, 1.4, 1.9]
     position[2] = setting.periodic_boundaries.correct_position_entry(position[2], 2)
     self.assertEqual(position, [0.1, 1.4, 1.9])
     position = [0.0, 0.4, 2.0]
     position[1] = setting.periodic_boundaries.correct_position_entry(position[1], 1)
     self.assertAlmostEqualSequence(position, [0.0, 0.4, 2.0])
     position = [-0.3, 1.4, 3.9]
     position[0] = setting.periodic_boundaries.correct_position_entry(position[0], 0)
     self.assertAlmostEqualSequence(position, [1.7, 1.4, 3.9], places=13)
     position = [-10.0, 102.231, 0.999999]
     position[0] = setting.periodic_boundaries.correct_position_entry(position[0], 0)
     self.assertAlmostEqualSequence(position, [0.0, 102.231, 0.999999], places=13)
Esempio n. 22
0
 def test_correct_periodic_boundary_position_system_length_one(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     position = [0.1, 0.4, 0.9]
     setting.periodic_boundaries.correct_position(position)
     self.assertEqual(position, [0.1, 0.4, 0.9])
     position = [0.0, 0.4, 1.0]
     setting.periodic_boundaries.correct_position(position)
     self.assertAlmostEqualSequence(position, [0.0, 0.4, 0.0], places=13)
     position = [-0.3, 1.4, 3.9]
     setting.periodic_boundaries.correct_position(position)
     self.assertAlmostEqualSequence(position, [0.7, 0.4, 0.9], places=13)
     position = [-10.0, 102.231, 0.999999]
     setting.periodic_boundaries.correct_position(position)
     self.assertAlmostEqualSequence(position, [0.0, 0.231, 0.999999], places=13)
Esempio n. 23
0
 def test_dimension_unequal_three_raises_error(self):
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=2,
                                          system_length=1.0)
     setting.set_number_of_root_nodes(2)
     setting.set_number_of_nodes_per_root_node(2)
     setting.set_number_of_node_levels(1)
     with self.assertRaises(ConfigurationError):
         MergedImageCoulombPotential(alpha=3.45,
                                     fourier_cutoff=6,
                                     position_cutoff=2,
                                     prefactor=1.0)
     setting.reset()
     hypercubic_setting.HypercubicSetting(beta=1.0,
                                          dimension=1,
                                          system_length=1.0)
     setting.set_number_of_root_nodes(2)
     setting.set_number_of_nodes_per_root_node(2)
     setting.set_number_of_node_levels(1)
     with self.assertRaises(ConfigurationError):
         MergedImageCoulombPotential(alpha=3.45,
                                     fourier_cutoff=6,
                                     position_cutoff=2,
                                     prefactor=1.0)
Esempio n. 24
0
 def setUp(self) -> None:
     # Build up two dipoles to test everything
     self._root_nodes = [Node(), Node()]
     self._root_nodes[0].add_child(Node(Particle(position=[0, 0], charge={"e": 1})))
     self._root_nodes[0].add_child(Node(Particle(position=[0.1, 0.05], charge={"e": -1})))
     self._root_nodes[1].add_child(Node(Particle(position=[0.9, 0.8], charge={"e": 1})))
     self._root_nodes[1].add_child(Node(Particle(position=[0.9, 0.75], charge={"e": -1})))
     for node in self._root_nodes:
         position = [sum(leaf_node.value.position[index] * leaf_node.weight
                         for leaf_node in node.children) for index in range(2)]
         node.value = Particle(position=position)
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     setting.number_of_node_levels = 2
     setting.number_of_root_nodes = 2
     setting.number_of_nodes_per_root_node = 2
     # Test the combination used throughout the application in JFV 1.0.0.0
     physical_state = TreePhysicalState()
     lifting_state = TreeLiftingState()
     self._state_handler = TreeStateHandler(physical_state, lifting_state)
 def test_new_initialize_hypercubic_setting_raises_error(self):
     with self.assertRaises(AttributeError):
         hypercubic_setting.HypercubicSetting(beta=1.0,
                                              dimension=3,
                                              system_length=1.0)
Esempio n. 26
0
 def setUp(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self._event_handler_one = FixedIntervalSamplingEventHandler(sampling_interval=0.5,
                                                                 output_handler="some_output_handler")
     self._event_handler_two = FixedIntervalSamplingEventHandler(sampling_interval=1.3, output_handler="output",
                                                                 first_event_time_zero=True)
Esempio n. 27
0
 def setUp(self) -> None:
     hypercubic_setting.HypercubicSetting(beta=2, dimension=5, system_length=1.5)
Esempio n. 28
0
 def test_next_image_length_two(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0)
     self.assertEqual(setting.periodic_boundaries.next_image(1.9, 1), 3.9)
Esempio n. 29
0
 def test_next_image_length_one(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self.assertEqual(setting.periodic_boundaries.next_image(0.4, 0), 1.4)
Esempio n. 30
0
 def test_separation_vector_system_length_two(self):
     hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0)
     position_one = [1.7, 0.1, 1.5]
     position_two = [0.4, 1.0, 1.4]
     self.assertAlmostEqualSequence(setting.periodic_boundaries.separation_vector(position_one, position_two),
                                    [0.7, 0.9, -0.1])