Changing the temperature of the system using a user defined temperature function

Dear LAMMPS users,

I have created a box of iron in LAMMPS. I would like to know if there is a way to control the temperature of the box using a user-defined function. Let’s say I want the temperature as a function of time to increase from 0 K to 500 K using T(t) = exp(5t). Is that doable using any type of fix command or anything else?

I will appreciate any assistance.
Thank you

You have to study the documentation of the various fix commands that can do thermostatting. Usually, you can enter a linear temperature ramp through the Tstart and Tstop parameters, but some thermostats will accept an equal style variable as Tstart (and ignore Tstop) and then use the value of the variable as thermostat target.

Please keep in mind that thermostats have a “lag” time until the system has followed the prescribed target temperature and equilibrated to the new target. with this in mind, an exponential shape of the target curve is not a good idea. You would rather have something where the change is larger at the beginning and then smaller toward the end.

1 Like

Thank you for your response.

I have read and tried several fix commands, but they all do linear ramping. My idea is just to impose some other function that is not linear. Even if that function is not suitable due to the lag time, I can still just use it and address the deviation from the exact desired function.

So could you please tell me if we can impose a specific temperature function?

Thank you

That is not correct. You have not studied the respective documentation pages with the required attention to detail. The fixes langevin, temp/berendsen, temp/csvr, and temp/rescale can use an equal style variable to define the target temperature (the second argument is then ignored).

Thank you very much for your kind support

I just have one inquiry. I noticed that when I perform heating with a user-defined temperature function using “fix langevin” + nve time integration, the morphology of the system does not change when it reaches the melting temperature (the particles are not settling down during melting). This is not the case when I use “fix nvt” or “fix npt” with linear temperature ramping. I think this has something to do with the theory behind each fix. So I am seeking a way to use “fix langevin” (to use my user-defined temperature function) and at the same time capture the melting behaviour (particles need to settle down). Would adding “fix gravity” be the right choice?

Thank you very much

Melting (and freezing) are activated processes that result in a hysteresis when just raising or lowering the temperature until melting or freezing happens spontaneously. This is not only affected by thermostats but also by system size and specifics of the system. I suggest a look into some physical chemistry or thermodynamics text books.

If you want to accurately determine the melting point you need a smarter approach than just rasing/lowering the temperature. A frequently used approach would be a so-called coexistence simulation (please search the archives for previous discussion on the subject).

From least to most important:

  • All thermostats work by flowing heat into (or from) the system based on its momentary deviation from the desired temperature. The Langevin thermostat’s heat flow is a stochastic first-order response to the temperature deviation; the Nose-Hoover thermostat’s response is deterministic second-order. This difference has real mathematical consequences (such as in the time constant of temperature fluctuations); but these precise effects are also mathematical artefacts far more than they are useful analogues for realistic physical phenomena.
  • You mentioned that fix langevin with your custom temperature function behaves differently from fix n[vp]t with a linear temperature ramp. What about fix langevin with a linear temperature ramp?
  • Ultimately, every molecular dynamicist must remember what George Box said half a century ago:

Since all models are wrong the scientist cannot obtain a “correct” one by excessive elaboration. On the contrary following William of Occam he should seek an economical description of natural phenomena. Just as the ability to devise simple but evocative models is the signature of the great scientist so overelaboration and overparameterization is often the mark of mediocrity.

Since all models are wrong the scientist must be alert to what is importantly wrong. It is inappropriate to be concerned about mice when there are tigers abroad.

But this is especially relevant for LAMMPS users; its incredible flexibility is its greatest strength and danger. LAMMPS has trapped dozens of tigers no other package could trap, and thousands of mice no other package would ever bother with.

1 Like