Hi all,
I need to calculate the bond distance of the specific bond and plan to use it as a variable to decide the next step to change some parameters based on the if/else command.
There is compute bond/local command, but it computes a local vector or an array, which can not be used as a variable. So is there any alternative to compute this bond distance and can be used further as a variable in lammps input?
Thank you & Kind regards!
No. You would have to either program a custom compute style yourself or see if you can implement this with a python style variable. In both cases, you have to take into account that LAMMPS uses domain decomposition and atoms may be stored on different MPI processes and thus communication would be required to make the result available to all processes.
Dear Sir,
Thank you for your prompt reply and suggestions.
I am trying with python style variable. So for that, I think first of all I need to extract the “dist” value from the compute bond/local for the specific bond and maybe then need to convert it to python style variable. But I am not sure about this step. Could you please elaborate more on how I can implement the main problem (bond length as a variable) in this python style variable? I can do the rest if/else for parameters updates but I need this specific variable value for this if/else command.
For the first step based on 2.3.8. Compute, fixes, variables — LAMMPS documentation I have started with the following:
from lammps import lammps
lmp = lammps()
lmp.file(“input.lammps”)
dist = lmp.extract_compute(“foo”, “bond/local”, “dist”)
foo = lmp.extract_atom(“foo”)
for i in range(foo):
print(", foo[i][0], foo[i][1], foo[i][2], ")
lmp.close()
But it gave the error: range() integer end argument expected, got NoneType. Maybe because of some problem in the above commands.
I have also tried this:
nlocal = lmp.extract_global(“nlocal”)
x = lmp.extract_atom(“x”)
for i in range(nlocal):
print("(x,y,z) = (", x[i][0], x[i][1], x[i][2], “)”)
which is giving the coordinates for the last or very first step of the run. I am planning to calculate the distance for specific atoms based on this step. But I am not sure I can use it as a variable in lammps or not because calculating this for every step is still another challenge here?
Kind regards!
Nothing of what you were doing has anything to do with a python style variable in LAMMPS. Also it looks like what you are doing is mostly copying from existing code examples for the LAMMPS python module (which may be needed, but would not be called like this) and disregards information from the documentation. In general, your questions show a scary disregard for the documentation and lack of understanding of what it is you need to do. It also seems to me that you are not quite understanding how and when you can use the “if” command in the LAMMPS input. You need to spend much more time leaning things and reading the documentation.
Don’t assume that because Python programming is easier to learn than programming C++ that your task is easier done with Python. I’d say the contrary.
And you haven’t even touched the fact that when executing LAMMPS in parallel, data may be scattered across MPI ranks and thus your two atoms of interest may be located on different processes and you would need MPI communication to collect the information and perform your computation.
That is another chunk of reading and understanding of the internals of LAMMPS.
Dear Sir,
Thank you for your prompt reply.
Yes, I have copied the existing examples and manipulated them in the wrong way. I’ll take care of this. I will read the documentation.
I have checked the existing lammps command for importing python variables “python add_numbers input 1 v_n return v_fact format ii here “””. So based on that I’m trying the above existing examples.
I have already tested the required update of parameters from “if” command in lammps input. and they worked perfectly for me. For example:
variable end2end equal 4.0
bond_coeff 61 85.00 ${end2end}
if “${end2end} > 3.5” then “delete_bonds one multi”
So I only looking for the “3.5” term, which needs to be the actual bond length (as a variable).
Because for test runs I am using Serial executable, so not considered the MPI ranks. But I will also need to check this more closely for main simulations in parallel executable LAMMPS.
Thank you & Kind regards!
If all that you want to do is break/delete a bond once a certain distance is reached, you should look into either fix bond/break or the more sophisticated and flexible fix bond/react.
Please also note that the “if” statement as used here is executed immediately and not during a run, while the two fix styles operate during a run.
Dear Sir,
Thank you for suggesting these two fix styles. But the bond I aim to break is not only depending on its bond length but also on the other side atom’s distances.
The fix bond/break is useful for half of the requirements but just after bond rupture I also need to update some parameters. That is why I need the “if” command here. But as you already mentioned “if” command will not work during the run, so I think I need to work on the custom compute here.
Kind regards!