Third year CMP compulsory experiment/Calculating the energy and magnetisation

From ChemWiki
Revision as of 15:41, 19 January 2015 by Npj12 (Talk | contribs) (Modifying the files)

Jump to: navigation, search

This is the second section of the third year CMP experiment. You can return to the previous page, Introduction to the Ising model, or jump ahead to the next section, Introduction to Monte Carlo simulation.

Getting the files for the experiment

Various scripts have been prepared to assist you with this experiment, and you can obtain them by downloading the file here.

We recommend that you use the IPython Qt console to do your simulation work. This should be available on all of the college computers, where you can access it through Start -> All Programs -> Anaconda (64-bit) -> IPython QTConsole. You are very welcome to use the IPython Notebook, that you were introduced to last year, to perform some of the analysis tasks later in the experiment. When using the QTConsole, you should start the session by running the commands:

%load_ext autoreload
%autoreload 2

This will ensure that when you try executing your code, you always run the most recent version!

For this section of the experiment, you will need the files IsingLattice.py and ILcheck.py. Extract them from the zip file to a convenient location in your H drive, then in the IPython QTConsole use cd H:\... to move to the correct directory.

Modifying the files

The file IsingLattice.py contains a Python class called IsingLattice. Open this file in your favourite text editor. This class will be the basis for our model of the system, and is restricted to modelling the two dimensional case. It contains a number of stub functions that you will complete as you work through the experiment.

The only function currently filled in is the constructor, __init__. This takes two arguments, while are simply the number of rows and columns that our lattice will have. The attribute self.lattice is then created, which is a NumPy array with the requested number of rows and columns. The function
np.random.choice
is used to create a random collection of spins for our initial configuration. You can see the documentation for this function here.

TASK: complete the functions energy() and magnetisation(), which should return the energy of the lattice and the total magnetisation, respectively. In the energy() function you may assume that J=1.0 at all times (in fact, we are working in reduced units in which J=k_B, but there will be more information about this in later sections). Do not worry about the efficiency of the code at the moment — we will address the speed in a later part of the experiment.

Testing the files

When you have completed the energy() and magnetisation() functions, we need to test that they work correctly. You are welcome to do this yourself — from the IPython Qt console (ensuring that you are in the correct directory), you can simply type
import IsingLattice
then create objects of your class with the command
il = IsingLattice.IsingLattice(n_rows, n_columns)

We have also provided you with a script, ILcheck.py, which will create three IsingLattice objects and check their energies and magnetisations, displaying these on a graph. One configuration corresponds to the energy minimum, one to the energy maximum, and one to an intermediate state.

TASK: Run the ILcheck.py script from the IPython Qt console using the command
%run ILcheck.py
The displayed window has a series of control buttons in the bottom left, one of which will allow you to export the figure as a PNG image. Save an image of the ILcheck.py output, and include it in your report.

This is the second section of the third year CMP experiment. You can return to the previous page, Introduction to the Ising model, or jump ahead to the next section, Introduction to Monte Carlo simulation.