Beispiel #1
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()
Beispiel #2
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)
Beispiel #3
0
 def test_run_without_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.number_of_jumps = 10
     simulation.run()
     self.assertEqual(simulation.lattice.jump.call_count, 10)
Beispiel #4
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'])
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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')
Beispiel #8
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')