[lammps-users] Calculation of velocity of random atom

Hi lammps users,

I’m working on the electron irradiation of a single walled carbon nanotube.

The aim of this piece of my script is to select a random atom from within a group (called target), find its velocity and use that to calculate and modify kinetic energy of that atom.

I have two issues at the moment:

(1) choosing the random atom from within the target group

Axel suggested using fix deposit - this command adds a new atom to the group which is not something I aiming to do.

My idea at the moment is to link the output from compute property/atom id to variable index i.e.
Link
compute c target property/atom id
with
variable randomID index

I thought this could start the link
compute c target property/atom id
variable c1 atom c_contents
print ${c1}
but my simulation stops & i don’t know how to link this to variable index anyway…

I’ve looked through the output options mentioned in the manual:
fix/ave: not an option because I need the individual atom ids
compute reduce: same issue as fix averages
dump: output for post processing
variable atom style (as above)
fix store/state + fix print: restart files involved, i don’t if that’s a good idea
thermo: c_contents is not a thermo quantity or global scalar

Any ideas?

(2) variable calculation of velocity

Option one:
variable v equal vy[i]

If I insert the atom id into [i], either manually or through the variable name (randomID) there is no error but it doesn’t seem to calculate - when I try to use variable v in other calculations my script stops running. I tried doing an absolute value of vy - since equal style doesn’t do vectors - but nothing changes.

Option two: grouping the randomly selected atom into a group by itself then using compute to find the velocity of that group, compute reduce to scalar quantity, then variable equal style but that didn’t work either…

i.e.
group randatom id ${randomID} # As per Axels suggestion I delete this group later on to make sure nothing is in it for the next atom in the loop
compute v1 randomatom property/atom vy
compute v2 randomatom reduce min vy
variable v3 equal $v2

Any thoughts?

Thanks in advance!

KATE McDONELL | PhD Candidate
School of Civil Engineering | Faculty of Engineering and IT

THE UNIVERSITY OF SYDNEY

hi kate,

without going into too much detail. i see two major issues.

1) what you want to do is in my opinion best done through writing
your own fix and not with scripting. writing the fix should be straightforward
if modelled after an existing fix (like fix deposit, without the depositing,
of course).

2) you do not seem to be aware that there are two ways to
expand an equal style variable in LAMMPs: a) ${name} expands
the variable _immediately_ to its current value, but b) v_name
expands to the value the "name" variable has when the corresponding
variable is evaluated. to make this work, you'll still have to run
your MD in tiny chunks and do your script evaluations in between.
perhaps the python script interface might be more suitable for that.
there are some examples that communicate coordinates very often

cheers,
   axel.

I agree with Axel that the simplest route is probably just to
write your own custom fix that does exactly what you want. I only
note that there is a random() math function available for
equal-style or atom-style variables to use, as described on
the variable doc page. Perhaps it could help with part of
your algorithm.

Steve

Hi Steve & Axel,

(1) I'll give it a go....

(2) Variable velocity

My script:
atom_modify map array #defined before read_data

variable name equal vy[i]
thermo_style custom step temp v_name
print ${name}

script returns

print 0

I've been randomly changing the value of [i] but the value of velocity is always 0. An atom value other than zero is returned for mass, type and the coordinates of the atom but not any component of force or velocity...

Am I doing something wrong?

I added in the atom_modify command as an error asked me to but how does the atom_modify command know what the velocity is if the velocity changes after the command was executed?

Thanks so much for all your help,

KATE McDONELL | PhD Candidate
School of Civil Engineering | Faculty of Engineering and IT
THE UNIVERSITY OF SYDNEY

If I add these lines to bench/in.lj, they appear to work fine:

variable name equal vy[10]
thermo_style custom step temp epair press v_name
thermo 10
run 100
print "VEL ${name}"

You do need the atom_modify command at the top as well.

Steve

Thank you both so much for your help. It so exciting! It runs! :slight_smile:

KATE McDONELL | PhD Candidate
School of Civil Engineering | Faculty of Engineering and IT
THE UNIVERSITY OF SYDNEY