예제 #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)