Fix bond/create bug

Dear LAMMPS users,

I tried to use LAMMPS to create bonds on a solid
(I know there might be better ways to do it as well, but why not?)
and i found that if the crystal is unperturbed and hence, the atoms lie at their
perfect positions the fix bond/create command does not work
since it creates less bonds than desired.

I assume that when the algorithm tries to create a new bond in an atom
but it detects multiple neighbors at the exact same distance it cant
decide which pair to chose and it skips the current atom.

I found a quick “hacky” solution to overcome this issue that can
be summarized as follows:

  1. Apply a small random perturbation to distort the crystal.
  2. Create the bonds
  3. Reverse the applied perturbation

My solution works fine although i had to make a random generator
since i couldn’t figure out how to reset the seed during the run.

Below i post an excerpt of my code in case anyone finds it useful:

49 # Parameters
50 group GAt id 1 # initialize group
51 variable ampl equal 0.000001 # max displacement
52 variable aa equal 1664525 # LCG rand gen parameter
53 variable mm equal 4294967296 # LCG rand gen parameter
54 variable cc equal 1013904223 # LCG rand gen parameter
56 # Apply the perturbation
57 variable rseed equal 123456789
58 variable nid loop (count(all)) 59 label loopApply 60 group GAt clear 61 group GAt id {nid}
62 variable rseed equal ({rseed}*{aa}+{cc})%{mm}
63 variable rnd equal {rseed}/{mm}
64 displace_atoms GAt move 0 0 (v_ampl*v_rnd) units box 65 next nid 66 jump SELF loopApply 67 68 # Generate the bonds 69 fix FGenBond GSolid bond/create 1 1 1 3.0 2 iparam 0 1 jparam 0 1 70 thermo 10 71 run 200 72 73 # Reverse the perturbation 74 variable rseed equal 123456789 75 variable nid loop (count(all))
76 label loopReverse
77 group GAt clear
78 group GAt id {nid} 79 variable rseed equal ({rseed}{aa}+{cc})%{mm} 80 variable rnd equal {rseed}/{mm} 81 displace_atoms GAt move 0 0 (-v_amplv_rnd) units box
82 next nid
83 jump SELF loopReverse
85 # Done
86 write_data
87 quit

Also for this to work, one has to include the following in the header of
the data file.

[Set Number] extra bond per atom
[Set Number] extra special per atom

For some reason Number had to be larger than 87 for this to work.

So im curious, is there a way to reset the seed within the script?
Also is this a bug or i did something wrong in the first place?

Best Regards,
A. Sgouros

I think the reason fix bond/create won’t work as is,

is that it requires both atoms (in the bond) agree

on forming that bond. So if there are lots of ties,

then it’s unlikely very many pairs will agree on

a particular timestep. Since on a timestep only

one bond (per atom) can be formed.

You could also use the create_bonds command.

It just creates all bonds within a distance criterion.


Dear Steve,

thanks a lot for your quick reply!

The solution you proposed is very elegant and
seems to be the proper way to do this.

I should read the manual more thoroughly
next time…

Kind Regards,
A. Sgouros

Dear Steve,

thanks a lot for your quick reply!

The solution you proposed is very elegant and
seems to be the proper way to do this.

I should read the manual more thoroughly
next time..

​this reminds me of this crazy idea that i had a while ago:​

we could modify LAMMPS in such a way, that it requires some kind of
"licensed to use" key, and one has to regularly answer questions about how
to correctly use LAMMPS, that require looking the answers up in the manual
(or memorize them) in order to obtain an updated key. that would provide
additional motivation, would it not? :wink:

of course, that would also provide an infrastructure for a "don't nag me"
program connected to it, where you can obtain such keys also through
donating money towards LAMMPS development, training and dissemination
efforts, or finding and fixing bugs, improving the documentation, adding
new features, providing helpful answers on the mailing list. the quality
and quantity of such actions would then determine how long one would be
exempted from having to get a new key and dig through the documentation,

just a crazy thought...


There was also the idea of paid-for consulting services :slight_smile:


Hahaha, that’s funny Axel!
(please don’t do this!)

Anyway, even though my solution was “strange”
my code did work after all, so, the main reason i
send the mail was to report a possible bug…
(albeit its not really important except in
extreme cases.)

A. Sgouros