CHM 579 Lab 1: Basic Monte Carlo Algorithm



Similar documents
MPI Hands-On List of the exercises

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Appendix A. An Overview of Monte Carlo N-Particle Software

Activity 1: Using base ten blocks to model operations on decimals

by Tim Fahlberg, CoolSchoolTools.com,

Mathematical Induction. Mary Barnes Sue Gordon

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Class One: Degree Sequences

0 Introduction to Data Analysis Using an Excel Spreadsheet

Symbol Tables. Introduction

Georgia Standards of Excellence Curriculum Map. Mathematics. GSE 8 th Grade

The 2010 British Informatics Olympiad

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Revised Version of Chapter 23. We learned long ago how to solve linear congruences. ax c (mod m)

Figure 1: Graphical example of a mergesort 1.

Classroom Tips and Techniques: The Student Precalculus Package - Commands and Tutors. Content of the Precalculus Subpackage

For example, estimate the population of the United States as 3 times 10⁸ and the

Data Visualization for Atomistic/Molecular Simulations. Douglas E. Spearot University of Arkansas

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

PGR Computing Programming Skills

Programming Languages & Tools

F.IF.7b: Graph Root, Piecewise, Step, & Absolute Value Functions

LINEAR EQUATIONS IN TWO VARIABLES

Reflection and Refraction

Patterns in Pascal s Triangle

Lesson/Unit Plan Name: Patterns: Foundations of Functions

Common Core State Standards for Mathematics Accelerated 7th Grade

Data Analysis Tools. Tools for Summarizing Data

Exponents and Radicals

6.4 Special Factoring Rules

Lecture Notes on Pitch-Class Set Theory. Topic 4: Inversion. John Paul Ito

Using Excel (Microsoft Office 2007 Version) for Graphical Analysis of Data

A.2. Exponents and Radicals. Integer Exponents. What you should learn. Exponential Notation. Why you should learn it. Properties of Exponents

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Problem of the Month: Once Upon a Time

Simplification of Radical Expressions

Calculation of Source-detector Solid Angle, Using Monte Carlo Method, for Radioactive Sources with Various Geometries and Cylindrical Detector

Common Core Unit Summary Grades 6 to 8

In mathematics, there are four attainment targets: using and applying mathematics; number and algebra; shape, space and measures, and handling data.

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Assignment 2: Option Pricing and the Black-Scholes formula The University of British Columbia Science One CS Instructor: Michael Gelbart

ESPResSo Summer School 2012

A Simple Pseudo Random Number algorithm

Advanced GMAT Math Questions

with functions, expressions and equations which follow in units 3 and 4.

Informatica e Sistemi in Tempo Reale

The Circumference Function

2) Write in detail the issues in the design of code generator.

Probability Distributions

Sources: On the Web: Slides will be available on:

Lecture 3: Models of Spatial Information

Dynamic Load Balancing of Parallel Monte Carlo Transport Calculations

Euler Paths and Euler Circuits

2 Session Two - Complex Numbers and Vectors

Figure 1.1 Vector A and Vector F

Direct Translation is the process of translating English words and phrases into numbers, mathematical symbols, expressions, and equations.

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

SOLVING EQUATIONS WITH RADICALS AND EXPONENTS 9.5. section ( )( ). The Odd-Root Property

Mathematics Common Core Sample Questions

Section 1.1. Introduction to R n

An Incomplete C++ Primer. University of Wyoming MA 5310

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

FURTHER VECTORS (MEI)

Parametric Technology Corporation. Pro/ENGINEER Wildfire 4.0 Tolerance Analysis Extension Powered by CETOL Technology Reference Guide

Geometry. Higher Mathematics Courses 69. Geometry

Matrix Multiplication

2.5 Transformations of Functions

MBA Jump Start Program

Radicals - Multiply and Divide Radicals

Answer: The relationship cannot be determined.

VARIANCE REDUCTION TECHNIQUES FOR IMPLICIT MONTE CARLO SIMULATIONS

(Least Squares Investigation)

LAKE ELSINORE UNIFIED SCHOOL DISTRICT

Session 7 Bivariate Data and Analysis

MA 408 Computer Lab Two The Poincaré Disk Model of Hyperbolic Geometry. Figure 1: Lines in the Poincaré Disk Model

Computational Mathematics with Python

1 BPS Math Year at a Glance (Adapted from A Story of Units Curriculum Maps in Mathematics P-5)

The Pointless Machine and Escape of the Clones

MATH 21. College Algebra 1 Lecture Notes

Mathematics Placement

Heron Triangles. by Kathy Temple. Arizona Teacher Institute. Math Project Thesis

1.3 Conditionals and Loops

Pigeonhole Principle Solutions

Memory Management Simulation Interactive Lab

Year 9 set 1 Mathematics notes, to accompany the 9H book.

Supplemental Worksheet Problems To Accompany: The Pre-Algebra Tutor: Volume 1 Section 1 Real Numbers

MATH 90 CHAPTER 6 Name:.

Mathematics. Mathematical Practices

POISSON AND LAPLACE EQUATIONS. Charles R. O Neill. School of Mechanical and Aerospace Engineering. Oklahoma State University. Stillwater, OK 74078

Relevant Reading for this Lecture... Pages

1.6 The Order of Operations

Ummmm! Definitely interested. She took the pen and pad out of my hand and constructed a third one for herself:

CCSS Mathematics Implementation Guide Grade First Nine Weeks

The Fourier Analysis Tool in Microsoft Excel

Pre-Algebra Academic Content Standards Grade Eight Ohio. Number, Number Sense and Operations Standard. Number and Number Systems

Factoring Trinomials: The ac Method

NEW MEXICO Grade 6 MATHEMATICS STANDARDS

F B = ilbsin(f), L x B because we take current i to be a positive quantity. The force FB. L and. B as shown in the Figure below.

How To Run Statistical Tests in Excel

Transcription:

CHM 579 Lab 1: Basic Monte Carlo Algorithm Due 02/12/2014 The goal of this lab is to get familiar with a simple Monte Carlo program and to be able to compile and run it on a Linux server. Lab Procedure: Before starting with the procedure below, make sure that you know basic things about the Linux command line environment. You have 15 files that contain an implementation of the Monte-Carlo algorithm in Fortran 90. If you are not familiar with Fortran, examine these files one after another following the directions and explanations below. You may go to step 15 right away if you are a Fortran guru. Step 1: This is our first FORTRAN program. It does not do much, only prints a line on the terminal in which you are running the program. Note how comments are made: An exclamation sign (!) means that anything to its right is a comment. Compile and run the file mc-001.f90 To compile: gfortran filename.f90 -o filename.out To run:./filename.out Step 2 In any program that does anything there are a number of variables. The statement implicit none forces the explicit definition of all the variables. There are several variable types: integer, real and double precision are just three examples. real and double precision variables are to store floating point numbers. The "variable" np is defined as a parameter, which means that its value will never change. Therefore it is a constant!. The variables x, y and z are actually arrays. Each one of them stores np (20, in this case) real numbers. We use x, y and z to keep the Cartesian coordinates of the particles in the simulation. Note the structure of a do loop. It will assign the value 1 to the variable i, and execute all the statements between the do and enddo keywords. Then, the value stored in variable i will be incremented in 1, and again execute everything between the do and enddo. This process will be repeated until i is larger than np.

Compile and run the file mc-002.f90 We have not assigned any value to the coordinates, so the printed numbers have no meaning. Step 3 We introduce the parameters for the Lennard-Jones interaction potential. The selected values correspond to the Oxygen atom in the SPCE water model, but this is irrelevant at this point. Mathematics with FORTRAN: a*b means a times b a/b means a divided by b a**b means a to the power b Compile and run the file mc-003.f90 Now we have assigned values to the coordinates! Step 4 We assign values to the initial coordinates of the particles using a (pseudo) random number generator. This is not the most common way to initialize the system, but is easy to understand, so for our simple program it is a good alternative. Imagine the simulation box as a cube with one corner in the origin of the Cartesian coordinates system: Then, the coordinates of the particles should be a number between 0 and box. The function ran() returns a real number between 0 and 1.

Then, the output of ran() is multiplied by box to get a coordinate in the proper range. Compile and run the file mc-004.f90 IMPORTANT The function ran() is not standard FORTRAN and may not be available in compilers other than gfortran. Step 5 To start the simulation we need not only the initial coordinates, but also the inital energy. At this point we introduce the variable u, which will be used to keep the value of the potential energy of the system throughout the simulation. Also we define some auxiliary variables (ddx, ddy, ddz and dd) to calculate the distance between particles. The total potential energy is defined as the sum of the Lennard-Jones interaction of all the pair of particles in the system: The distance between particles "i" and "j" is calculated by first finding the distance along each Cartesian component. Then, the sum of the squares of the components is the square of the distance. Note the function sqrt() which calculates the square root of its argument. IMPORTANT: So far we have not applied periodic boundary conditions, necessary to mimic bulk conditions. Compile and run the file mc-005.f90 Step 6 In order to mimic a bulk system we imagine that our simulation cell is replicated and shifted in all six Cartesian directions.

With this picture in mind, we should decide the proper way to calculate the energy. We will apply here the simplest criterion, which states that the distance between particles "i" and "j" is the minimum possible distance between these two particles when both of them are in the simulation box, or one of them is in any of the neighboring replica boxes. Then, the 1-2 and 1-3 distances are taken within the central box, but the distance 2-3 is shorter if we consider particle 2 in the central box, and particle 3 in the replica to the right of the central box. Using this 'minimum image criterion', the maximum distance (parallel to a Cartesian axis) is box/2. Note in the code how we have applied this criterion. Note the structure of the if conditional operator. Compile and run the file mc-006.f90

Step 7 A spherical cut-off is necessary to have an isotropic system. As we said previously, the maximum distance (along a Cartesian axis) between particles is box/2. In the XY plane (for example) the maximum distance between two particles is sqrt(2)*box/2. Therefore, without imposing a cut-off to the interaction will have a longer range along the diagonals than along the Cartesian axis. The spherical cut-off distance has to be at most equals to half the box length. Now the initial energy is calculated now. Compile and run the file mc-007.f90 Step 8 The energy will be calculated many times during the simulation. Therefore, it is convenient to have a separate function (or subroutine) that performs the energy calculation. Note that we pass all the necessary information to the subroutine in the argument section, which is indicated by the parenthesis. The last argument is an integer number which should be equal to "0" in order to calculate the total potential energy. Other options will be necessary in the following steps. Except for the introduction of the subroutine, there is no difference with program mc-007.f90 Compile and run the file mc-008.f90 Step 9 In a Monte Carlo simulation we need to select a particle and displace it from its current position. The move will be accepted or rejected based on a criterion that depends with the change in energy of the system. In this program, we select at random the particle to move. The line: it=int(ran()*np)+1 assign an integer between 0 and np to the variable it, which is the particle that we will attempt to displace. In the subroutine energy, we have added the possibility of calculating the interaction energy of any single particle with the rest of the system. Compile and run the file mc-009.f90 Step 10 The selected particle is displaced from its position by a random distance. It is important to store the particle's coordinates, in case we decide not to accept the move. Also, once the particle has been moved we check if it is inside or outside the central box. In the later case, we apply the periodic boundary conditions to put the particle back into the central box. Compile and run the file mc-010.f90

Step 11 All the moves that lower the energy are accepted. Compile and run the file mc-011.f90 Step 12 In a Monte Carlo program, we attempt to move the particles many times, therefore we use a do loop to repeat the procedure. Compile and run the file mc-012.f90 Step 13 As we said, every time the energy is lowered by a particle move, the move is accepted. When the energy rises, we accept the move with a probability P=Exp[-DeltaU/kT]. In practical terms, this means to compare P with a random number RN between 0 and 1. If P>RN, we accept the move. Compile and run the file mc-013.f90 Step 14 By using a subroutine to perform the move procedure, we get a more compact and readable main program. We have introduced a new variable that will count the number of accepted moves. Compile and run the file mc-014.f90 Step 15 To complete this first stage in the development of the MC program, we define the variable mcsteps, which represents the number of attempted moves. Also, we monitor the potential energy of the system, writing its value every 100 steps. This energy is recorded in the file energy.dat. Once the simulation is completed, examine the energy file (plot). Compile and run the file mc-015.f90 Step 16: Your Turn A: Random Numbers Run the program from step 15 twice and compare the results (geometries and energies). (1) Are they any different? You may wonder why it is so. The reason is in the way the random number generator is initialized, i.e., what is its SEED number. Find the first call to ran() in the program. You see that there is no explicit initialization. It means that a default integer (which may be different between different compilers and different operating systems) is used as SEED each time, and a sequence of random numbers is the same in

all runs. In order to make the random number sequence really random, do the following trick: before the first time ran() is called, add a line: call srand(seed) Here seed should be any odd integer. Remember to initialize it in the beginning of the program. Providing different seed numbers, you will get different random sequences and different results. To make the randomization procedure really automatic, you can use current time as an argument. For example, like this: seed1=2*int(secnds(0.0)) seed=7654321+seed1 call srand(seed) Here the current seconds (counted from midnight) are added to an integer which will result in different seed numbers unless you run the program too often. To make sure that this procedure works properly, compile the program and run it twice, saving and comparing the results. B: Different Step Size (2) Plot the energy as a function of the step number. Note what the acceptance rate is. Decrease the step size in the program (10 to 100 times smaller). Compile and run the program again; observe the acceptance rate and energy changes. (3) Do you see any interesting differences? Hint: you may look in more detail at a shorter segment of the energy plot in order to see interesting changes. C: Different Temperature Change the temperature. Again, recompile and rerun. (4) How are the energy and the acceptance rate different? (5) In the lab report, provide acceptance rates and energy plots (or parts of them) corresponding to different step sizes and temperatures. Explain observed differences.