Пример #1
0
 def test_define_lattice_from_file(self):
     with patch('lattice_mc.init_lattice.lattice_from_sites_file'
                ) as mock_lattice_from_file:
         mock_lattice_from_file.return_value = 'foo'
         simulation = Simulation()
         cell_lengths = np.array([1.0, 2.0, 3.0])
         simulation.define_lattice_from_file('filename', cell_lengths)
         self.assertEqual(simulation.lattice, 'foo')
         mock_lattice_from_file.assert_called_with(
             'filename', cell_lengths=cell_lengths)
Пример #2
0
 def test_set_number_of_atoms_with_specific_sites(self):
     simulation = Simulation()
     simulation.lattice = Mock(spec=Lattice)
     mock_atoms = [Mock(spec=Atom), Mock(spec=Atom)]
     simulation.lattice.populate_sites = Mock(return_value=mock_atoms)
     with patch('lattice_mc.species.Species') as mock_Species:
         mock_Species.return_value = 'some atoms'
         simulation.set_number_of_atoms(3, selected_sites=['A'])
         self.assertEqual(
             simulation.lattice.populate_sites.call_args[1]
             ['selected_sites'], ['A'])
Пример #3
0
 def test_set_number_of_atoms(self):
     simulation = Simulation()
     simulation.lattice = Mock(spec=Lattice)
     mock_atoms = [Mock(spec=Atom), Mock(spec=Atom)]
     simulation.lattice.populate_sites = Mock(return_value=mock_atoms)
     with patch('lattice_mc.species.Species') as mock_Species:
         mock_Species.return_value = 'some atoms'
         simulation.set_number_of_atoms(3)
         self.assertEqual(simulation.number_of_atoms, 3)
         self.assertEqual(simulation.atoms, 'some atoms')
         mock_Species.assert_called_with(mock_atoms)
Пример #4
0
 def test_run_with_equilibration_steps(self):
     simulation = Simulation()
     simulation.is_initialised = Mock(return_value=(True, None))
     simulation.atoms = 'a'
     simulation.lattice = Mock(spec=Lattice)
     simulation.lattice.jump = Mock()
     simulation.reset = Mock()
     simulation.number_of_equilibration_jumps = 20
     simulation.number_of_jumps = 30
     simulation.run()
     self.assertEqual(simulation.lattice.jump.call_count, 20 + 30)
     self.assertEqual(simulation.reset.call_count, 1)
Пример #5
0
 def test_is_initialised_fails_with_no_lattice(self):
     simulation = Simulation()
     simulation.atoms = 'foo'
     simulation.number_of_jumps = 'bar'
     simulation.lattice = None
     with self.assertRaises(AttributeError):
         simulation.is_initialised()
Пример #6
0
 def test_simulation_is_initialised(self):
     simulation = Simulation()
     self.assertEqual(simulation.lattice, None)
     self.assertEqual(simulation.number_of_atoms, None)
     self.assertEqual(simulation.number_of_equilibration_jumps, 0)
     self.assertEqual(simulation.number_of_jumps, None)
     self.assertEqual(simulation.for_time, None)
     self.assertEqual(simulation.number_of_atoms, None)
     self.assertEqual(simulation.has_run, False)
Пример #7
0
 def test_reset(self):
     simulation = Simulation()
     simulation.lattice = Mock(spec=Lattice)
     simulation.atoms = Mock(spec=Species)
     simulation.atoms.atoms = [Mock(spec=Atom), Mock(spec=Atom)]
     simulation.reset()
     self.assertEqual(simulation.lattice.reset.call_count, 1)
     self.assertEqual(simulation.atoms.atoms[0].reset.call_count, 1)
     self.assertEqual(simulation.atoms.atoms[1].reset.call_count, 1)
Пример #8
0
    def test_run_for_time(self):
        simulation = Simulation()
        simulation.is_initialised = Mock(return_value=(True, None))
        simulation.atoms = 'a'
        simulation.lattice = Mock(spec=Lattice)
        simulation.lattice.time = 0.0

        def fake_jump_method():
            simulation.lattice.time += 1.0

        simulation.lattice.jump = fake_jump_method
        simulation.run(for_time=10.0)
        self.assertEqual(simulation.lattice.time, 10.0)
        self.assertEqual(simulation.number_of_jumps, 10)
Пример #9
0
 def test_collective_correlation(self):
     s = Simulation()
     self.assertEqual(s.collective_correlation, None)
Пример #10
0
 def test_set_site_energies(self):
     simulation = Simulation()
     simulation.lattice = Mock(spec=Lattice)
     simulation.lattice.set_site_energies = Mock()
     simulation.set_site_energies('foo')
     simulation.lattice.set_site_energies.assert_called_with('foo')
Пример #11
0
 def test_set_nn_energy(self):
     simulation = Simulation()
     simulation.lattice = Mock(spec=Lattice)
     simulation.lattice.set_nn_energy = Mock()
     simulation.set_nn_energy('foo')
     simulation.lattice.set_nn_energy.assert_called_with('foo')
Пример #12
0
 def test_set_number_of_equilibration_jumps(self):
     simulation = Simulation()
     simulation.set_number_of_equilibration_jumps(32)
     self.assertEqual(simulation.number_of_equilibration_jumps, 32)
Пример #13
0
 def setUp(self):
     self.simulation = Simulation()
     self.simulation.has_run = True
Пример #14
0
 def test_collective_diffusion_coefficient_per_atom(self):
     s = Simulation()
     self.assertEqual(s.collective_diffusion_coefficient_per_atom, None)
Пример #15
0
 def test_run_raises_error_if_not_initialised(self):
     simulation = Simulation()
     simulation.is_initialised = Mock(side_effect=AttributeError('test'))
     with self.assertRaises(AttributeError) as context:
         simulation.run()
Пример #16
0
 def test_tracer_diffusion_coefficient(self):
     s = Simulation()
     self.assertEqual(s.tracer_diffusion_coefficient, None)
Пример #17
0
 def test_tracer_correlation(self):
     s = Simulation()
     self.assertEqual(s.tracer_correlation, None)