Best practices for a simulation that turns on and off forces during run

I want to use LAMMPS to investigate the effect of 2 forces on the temperature of a certain system. The 1st force should always be applied, and the 2nd force should be applied only after 5000 timesteps.

Since I am mainly interested in the effect of the 2nd force on temperature, I want the system to be in the a constant temperature when the 2nd force appears, no matter what are the parameters of the 1st force. This requirement led me to also use a fix langevin in the first 5000 timesteps, and then unfix it.

Is it correct to use fix langevin and unfix it after I run 5000 to achieve this behavior? Also regarding the fix addforce of the 2nd force - is it correct to run 5000 and then fix addforce the 2nd force?

I also read in this answer that fix addforce can be used to add time dependence to forces, but I don’t understand how to do that (an example LAMMPS command would be great), and I’m not sure whether for my requirement using fix addforce, then unfix should produce the desired simulation.

Your requirements are contradicting each other.

If you add a (constant) force to a system, it will increase its kinetic energy unless it is balanced by some friction that takes out the equivalent amount of energy. A good example for that is fix langevin: it adds random forces but also has a friction term and both are balanced to reach the desired temperature.

So, if you want to see the effect on temperature from adding a force, you must not use a thermostat since that will just hide that impact.

For the same reason, your results will be tainted if you suddenly stop using that thermostat and add a second force, since you will see the effect on the temperature from both.

The explanation is there: it says that you need to use a time dependent atom style variable. A command example to use a variable with fix addforce is there. Now you just need to construct an atom style variable where the value changes with time. That can be done in many ways. You need to study the variable command documentation and search the forum for previous questions about this.

Thanks for the quick reply @akohlmey !

I am aware of that, and indeed the 2nd force I’m adding depends on the velocity of my atoms, and hence the goal is too see how it cools the system.

I don’t understand, how did you infer I’m using a thermostat? Also what do you mean exactly? How do I know if I’m using a thermostat? If I understand correctly that using a thermostat means using a fix langevin, then indeed I wrote in my post that essentially what I’m doing is this:

# create_atoms many times...
fix myLangevin all langevin # more parameters ...
variable force1ValueX atom # expression of the 1st force on every atom...
# Same for force1ValueY and force1ValueZ
fix force1 all addforce v_force1ValueX v_force1ValueY v_force1ValueZ
run 5000
unfix myLangevin
variable force2ValueX atom # expression of the 2nd force on every atom...
# Same for force2ValueY and force2ValueZ
fix force1 all addforce v_force2ValueX v_force2ValueY v_force2ValueZ
# This is most of the simulation:
run 1000000

I’m still not sure what do you mean by thermostat, but indeed I suspect that my results are tainted, because something weird happens to the temperature when I unfix the langevin bath and add the 2nd force right afterwards. That’s why I’m asking for help here - to find out whether I’m doing it OK and whether there is a better way to implement this.

I’m sorry but I must be blind, I only saw code blocks I didn’t understand from the OP there, and no code from you, nor any examples that use the time in the docs of fix addforce…

Actually, I did manage to think now of LAMMPS code:

variable force2Started equal "step > 5000"
# In (...x,y,z...) the original expression of the force should appear...
variable force2ValueX atom "v_force2Started * (...x,y,z...)
fix force2_f all addforce v_force2

What do you think about that @akohlmey ?

You wrote:

Is fix langevin not a thermostat?

An added force changes the kinetic energy of the system, but a thermostat will try to compensate that. That is what it is supposed to do. So you cannot observe the “effect on the temperature” when you are trying to thermostat the system at the same time.

You are contradicting yourself again.

This is it, I have no more interest to continue a discussion under such circumstances.
Good luck!

Well now I understand that it is, but at the time I wrote the comment I wasn’t sure of that, that’s why I also wrote this paragraph:

Also what confused me, is your usage of the word “thermostat” right after I used the words fix langevin, which seem to be equivalent in this context. I am sorry but I’m not fluent with the terminology, I was hoping it’d still be legitimate to ask a question.

How is that a contradiction? Whenever I mentioned the word thermostat I also write that I’m not sure what you mean every time…

@akohlmey Do you posses basic theory of mind? Are you capable of conceiving that users of your software are not fluent in all the details of it? And that they are not familiar with all of the different terms of it? I was hoping it would be clear from the amount of times I wrote how I’m not sure of things, and in general the amount of questions I asked.

I’m sorry this comes out like that @akohlmey , I just feel that you are not reading thoroughly what I write, and the discussion is not focused on the right points. If you want to help people use LAMMPS, you should be able to conceive that users probably won’t know all of the details of it and all of the commands and terminology of it by heart. If they had know all of these details, they wouldn’t have reached the forum in the first place :].

I’d really appreciate if you’d focus on the code block I wrote, quoting it here:

Does the fix and unfix usages make sense to you?

I am quite aware of what people do and do not know and how little some people know. Not just in the context of LAMMPS. I am responding to questions on various mailing lists and forums for over 20 years. The situation is quite simple: you what help from us, so you have to make it easy for us to help you and not the other way around. The more people say, “I don’t know” or “I am not sure” is an indication that they have not done the necessary homework to have a meaningful and effective on-topic discussion. It is not my job to remove your confusion. This may sound harsh to you right now and your self-esteem may get a bit dented, but in my experience, it will teach you some valuable lessons and help you to become better at discussing your work (and at the very least receive better responses the next time).

Please re-read my first response to your original post. I contains everything I have to say about your approach and still applies since it is consistent with your initial description (before you started the distracting confusion about thermostats). You can (and should) draw your own conclusions. This forum is not a “LAMMPS input file approval service™”.

P.S.: as a point of reference, the first mailing list that I had subscribed and followed was the Linux kernel mailing list in the late 1990s. That was a completely different dimension of rough, strictly meritocratic and very educational.

1 Like

Please see this discussion here for how an exchange here can go smoothly.

The person asking doesn’t seem to be more experienced than you (possibly less), but is doing the necessary checks and experiments to figure out what is unclear and asks concise questions when encountering unexpected behavior. Overall, not very different conceptually from your kind of problem, but executed in a way that it was easy and convenient to provide helpful answers and demonstrating that an effort was made to solve the problem without additional help and thus asking only when reaching a dead end and with suitable explanations and reasoning.