本次Python代写是完成蒙特卡洛算法

7CCP4479

Bio- and Nanomaterials in the Virtual Lab

Lab 1 – Develop a simple MC code

1) (5 marks) Generate a 2d square lattice which has nx x nx vertices (where nx is easily

inputted by the user).

2) (5 marks) Build a system where there is a density r of discs placed randomly onto the

lattice. There will be two types of discs in the simulations (A & B), and you will need to

randomly assign type A to a fraction fA of the discs and the rest of the discs to type B.

Therefore the following relationship between the fraction of the discs that are type A and the

fraction that are type B, fB, will hold: fA + fB = 1. (r and fA both need to be easily inputted by

the user).

3) (30 marks) Calculate the energy of each configuration of the system. In this simulation, we

will simplify things by saying that the energy of any disc at a given vertex on the lattice (say

vertex with coordinates (vx,vy)) is only affected by what species are found in the nearest

neighbour sites to that vertex (e.g. (vx+1,vy), (vx-1,vy), (vx,vy+1), (vx,vy-1)). The contributions to

the energy of each interacting vertex will be dependent on the species which occupy each

vertex. If either interacting vertex is vacant then it will contribute nothing to the energy,

whereas the other possibilities have the following contributions:

• type A on both interacting vertices: energy contribution is eAA

• type A on one vertex, type B on the other vertex: eAB

• type B on both vertices: eBB

(eAA, eAB & eBB need to be easily inputted by the user). Also note that you will need to ensure

that the vertices on the outer edges of the lattice interact via periodic boundary conditions,

as otherwise you will have significant finite size effects.

4) (5 marks) Develop a swap move in order to allow the system to evolve over the course of

the simulation. In this swap move, you should randomly chose a vertex which is occupied by

a disc and then swap its identity (type A or B) with the identity of another randomly chosen

vertex (type A, B or vacant).

5) (10 marks) Employ the Metropolis criteria as to whether or not to accept a swap move. For

this you will need to allow the user to easily input the temperature T that the simulation is to

take place at. The simulation should be able to carry out as many attempted moves (nmoves)

as desired by the user (this value should be easily inputted by the user). Your code should

output the energy after each attempted move, the acceptance ratio after each move (number

of accepted moves divided by the number of moves attempted), and whether the last move

was accepted or rejected.

6) (5 marks) Produce pictures of the initial and final configurations of the studied systems in

which the vertices are coloured differently depending on whether they contain a disc of type

A or type B or are vacant.

Questions: (50 marks)

1) (20 marks) Provide the requested output for two different simulations with the inputs as

described in the table below:

Input Sim 1 Sim 2

nx 50 50

r 0.95 0.95

fA 0.3 0.5

eAA -4.0 kcal/mol 2.0 kcal/mol

eAB 2.0 kcal/mol -2.0 kcal/mol

eBB -2.0 kcal/mol 2.0 kcal/mol

T 300 K 300 K

nmoves 1,000,000 1,000,000

Describe the final configurations (e.g. are A and B mixed or separated?) What kind of

materials would A and B be representative of in the two simulations?

2) (5 marks) Explain why the mixing or lack thereof in the two systems makes sense when

considering the values of eij used in the two simulations.

3) (10 marks) Choose one system and investigate how varying (a) the temperature (T) and (b)

the density (r) affects the evolution of the system, the evolution of the energy of the system

and the acceptance ratio.

4) (5 marks) Briefly describe how you would modify your code to simulate the evolution of

the same two types of discs in two-dimensional space where the system is not defined by a

lattice. (Please consider not only the representation of the discs but also movement and

determination of the energies).

5) (5 marks) Compare the final energies of the two simulations. Briefly provide a physical

description of why the energies are the same/different.

6) (5 marks) Have the systems reached their global energy minimum? Discuss, making

reference to both the energy of the system and the figure of the final frame.

Extra credit: (10 marks)

If you would like a further challenge, and the ability to earn up to 10 extra marks, then below

are a couple of potential extensions that you could incorporate into your model. (NOTE: the

maximum overall percentage of all marks will be 100%, so in this case if the maximum number

of marks that will be assigned when counting the marks from the code, questions and extra

credit is 110.)

1) [10 marks] Incorporate into your code, a displacement move in which a disc is chosen at

random and then a direction [(1,0),(-1,0),(0,1) or (0,-1)] and the disc is moved into that vertex,

if it is vacant. The energies are evaluated before and after the move and then the move would

be accepted/rejected with the Metropolis criteria. [NOTE: you would only make either a

translation or a swap move during each iteration of the code, so you would probably also

want to have some probability assigned to how often each type of move is used in the

simulation, and then you would want to first determine randomly which type of move to try.]

Then use this move with the swap move for one of the previously studied systems and

compare the acceptance ratio and energies after a similar number of total moves, and see if

the incorporation of the translation move improves the efficiency of the search of the energy

landscape or not.

-or2) [10 marks] Modify the swap move in your code so that instead of just swapping one disc

with the identity of a randomly chosen vertex, you choose one random disc and a randomly

chosen nearest neighbour vertex and swap the identity of those two vertices with a randomly

chosen vertex and one of its randomly chosen neighbours else where in the system. Then

use the Metropolis to accept/reject this move. [NOTE: you would only make either a single

disc swap move or a two-disc swap move during each iteration of the code, so you would

probably also want to have some probability assigned to how often each type of move is used

in the simulation, and then you would want to first determine randomly which type of move

to try.] Then use this move with the swap move of a single disc for one of the previously

studied systems and compare the acceptance ratio and energies after a similar number of

total moves, and see if the incorporation of the swap move of two discs improves the

efficiency of the search of the energy landscape or not.

Submission

Please submit a pdf (not .doc, .docx, .rtf, ….) that contains your answers to the questions (&

extra credit)via the Turnitin folder on the module’s KEATS page by 11.59pm on Monday 26

October 2020. If it is in any other format, then you will be given a zero for that portion of the

assignment. Additionally, I will collect the code you have written from your directory on

CoCalc at the same date and time as stated above.

Further extensions

Each week I will also provide additional ideas for extending the code even further as some of

you have asked for additional challenges on the coding side. Note, there will be no credit

given for these points, but Paul, Rob and I will be more than happy to discuss with you the

approach we would take to solve them. Below is a list of such challenges for the Monte Carlo

code you have already started to construct above (NOTE: I have listed them roughly in what I

think is order of difficulty from my perspective):

1) Calculate the entropy of mixing after each attempted move.

2) Add a move to the code that chooses a random group of three vertices and rotate them

around the centre vertex of the three to a randomly determined orientation.

3) Modify the code you have so that it simulates a 3d lattice (as obviously real life exists in

three-dimensions).

4) Modify the code you have such that you remove the reliance on a lattice altogether, as

again in reality things can move in directions which are not right angles to one another.

**程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB**

本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！

**E-mail:** [email protected] **微信:**itcsdx

如果您使用手机请先保存二维码，微信识别。如果用电脑，直接掏出手机果断扫描。