Suppose, a polymer has N monomers in its chain. I want to simulate its movement using the bead-spring model.

So, I wrote the following program in Python.

I am using 0.1 million steps. The energy is not fluctuating as expected. After several steps, the curve goes totally flat.

enter image description here

The X-axis is steps. Y-axis is total energy.

Can anyone check the source code and tell me what I should change?

N.B. I am especially concerned with the function that calculates the total energy of the polymer.

  • 1
    $\begingroup$ My last advice would be to write it in a friendlier language, or, more common language. Python/Matlab/Julia are the best for trying new things, and many people don't mind looking at codes written in these languages. C# is not that common for modelling. Last Last advice, make a polymer made of only two beads, calculate the energy for several snapshots by hand, and compare with the program. $\endgroup$
    – B. Kelly
    Apr 28 at 2:24
  • $\begingroup$ Do your beads stop moving when it goes flat? If so, perhaps your random number generator breaks. print to screen the random number used in the metropolis criteria, as well as the math.exp(-(energy_new-energy_old)/T), see which one of those stops changing. Also print to screen the X and Y positions to see if they stop changing $\endgroup$
    – B. Kelly
    Apr 28 at 2:37
  • 2
    $\begingroup$ If the beads stop moving, you need to figure out if it is because new positions aren't being generated correctly, or, new positions arent being accepted correctly. If positions aren't being generated correctly - probably random number generator issue. If moves aren't being accepted, it could be random number generator issue, or potential energy calculation issue, but since potential energy seems to work before, that would be odd. If your energies are dimensionless as they appear, and really are raised to the thousand, that may be an issue. that is a big number for a single molecule $\endgroup$
    – B. Kelly
    Apr 28 at 2:41
  • $\begingroup$ Not sure what the best chat room for this would be. $\endgroup$ May 2 at 4:56
  • 1
    $\begingroup$ Thanks for letting me know :) $\endgroup$ May 3 at 21:22


Browse other questions tagged .