How to use Shake command and molecule file

I want to use the Shake command to fix carbon and aluminum atoms, but it doesn’t work.
The error now looks like this:
ERROR: Cannot use fix shake with non-molecular system (…/fix_shake.cpp:74)

in file:
units metal
boundary p p p
atom_style atomic
atom_modify map yes
read_data lammps.dat
group sub id 14 55
pair_style nnp
pair_coeff * * ffield.sannp eatom zero Si Cr C Al
velocity all create 1873.0 15180

dump Dump all custom 1 tmpdir/lammps.dmp type x y z
thermo_style custom step time cpu pe ke etotal enthalpy temp press vol density cella cellb cellc cellalpha cellbeta cellgamma
thermo 1

fix ensemble all nvt temp 1873.0 1873.0 2.0
fix Cbond sub shake 0.0001 100 0 t 3 4

timestep 2.41837968e-03
run 413500
unfix ensemble

data file:
55 atoms

   4  atom types

0.000000000 9.333094750 xlo xhi
0.000000000 9.333094750 ylo yhi
0.000000000 9.333094750 zlo zhi

Atoms

1 1 1.945687995 0.472764181 0.796730833
2 2 1.582105156 0.516276936 3.017796456
3 1 3.699711557 -0.944224529 2.112539463

Masses

   1  28.085500000 # Si
   2  51.991610000 # Cr
   3  12.010700000 # C
   4  26.981540000 # Al

Do I need to use a molecule file?
I created this file but could not load it successfully.
ERROR: No atoms or invalid atom count in molecule file (…/molecule.cpp:504)
Added molecule command under read_data command.
molecule 1 C-Al.txt

C-Al.txt file:
2 atoms

Coords
1 3.028218224 6.473917973 7.842553786
2 4.343348837 7.832628040 7.330197684

Types
1 1
2 2

Bonds
1 1
1 2

Masses
1 26.981540000 # Al
2 12.010700000 # C

That is because you are misunderstanding what fix shake does and how the SHAKE algorithm works. There are some detailed explanations in the LAMMPS manual, but you seem to have chosen to ignore those. It is also explained in great detail in text books on molecular dynamics simulations.

Bottom line: fix shake works on explicit bonds (like in molecular force fields) and applies a constraint to maintain the bond length (and for groups of three atoms that form a triangle, also the angle can be constrained). This requires defining bonds in the topology and than in turn requires a different atom style. However, your system seems to be using a machine learning potential (albeit not one included in the official LAMMPS distribution) and in those all bonds are implicit.

It is not a good idea to use the verb “to fix” in this context since a) LAMMPS has a “fix” command and b) the verb “to fix” can have rather different meanings (e.g. to repair, or to attach in addition to to fixate or to affix or to immobilize). Often people mean to immobilize and fix shake is definitely the wrong command to immobilize atoms in LAMMPS. I suggest you search the forum archives (or with google or equivalent) for discussions on how to “immobilize atoms” in LAMMPS, e.g. by excluding them from time integration or by setting their velocities and forces to zero.

If you want to immobilize some atoms, why integrate their equations of motion and monitor and adjust their temperature. This is inconsistent.

No that won’t help.

That is because your molecule file does not follow the format as described in the manual. The first line is ignored. In your file it says “2 atoms” and thus you get an error about “No atoms” since there is no statement about the number of atoms in a line that is being read. Furthermore, the syntax of the various sections is not correct (there must be an empty line following each header) and the Bonds section’s content is not correct either. Also, there must not be a Masses section for a system where there are no per-atom masses, but the atomic masses are tied to that atom type.

Besides, the same limitation that I mentioned above applies to molecule files. You cannot create bonds for a system that has no provisions for adding explicit bonds.

Overall, you need to pay much more attention to the documentation. All that I have pointed out, is explained in detail in the documentation. You have to follow it carefully.

Dear akohlmey,

I ended up writing “fixing the atoms,” but the correct answer is “fixing the distance between atoms.”
Sorry for writing it wrong.
I haven’t learned enough yet and thought that only the Shake command could be used in this case. Are there any other commands I can use?

Constrain which distances between which pairs of atoms at which distance?
In a general crystal structure with multiple atoms of multiple types, the result constraining all distances between all pairs is typically identical with immobilizing those atoms due to symmetry.

The fix shake command requires bonds to know which pairs of atoms and the equilibrium distance of the corresponding bond potential provides the constraint distance. In your system such information does not exist.

I would like to fix the 14th carbon atom and the 55th aluminum atom with an interatomic distance of 1.96 Å out of 55 atoms. Below is the atomic coordinate data.

  55  atoms

   4  atom types

0.000000000 9.333094750 xlo xhi
0.000000000 9.333094750 ylo yhi
0.000000000 9.333094750 zlo zhi

Atoms

1 1 1.945687995 0.472764181 0.796730833
2 2 1.582105156 0.516276936 3.017796456
3 1 3.699711557 -0.944224529 2.112539463
4 2 -0.571848048 4.641325620 -1.936857954
5 1 7.639968698 2.846396037 1.992652128
6 1 6.378594410 1.028708636 -2.745235556
7 2 0.731594231 8.191470600 -3.384992136
8 1 1.763776646 10.972124318 5.732895449
9 2 5.854717535 7.374231225 1.839283249
10 1 3.162228897 2.954447142 1.333215785
11 1 10.421510927 2.872327108 -0.698688539
12 2 10.319423670 2.367235886 1.912780437
13 1 -1.835026424 4.960243067 2.976614175
14 4 3.028218224 6.473917973 7.842553786
15 1 5.150198611 5.886116866 5.490886436
16 1 3.814410625 6.654929612 0.386509586
17 2 7.326911501 4.885629641 5.296032883
18 1 0.932300567 5.073449773 2.679765763
19 2 2.161729539 2.980133685 3.760283342
20 1 3.636500373 1.144328881 4.053306118
21 1 6.965802865 2.867907887 4.625594689
22 2 -0.152024914 3.050004032 3.935607393
23 1 9.118069580 2.504764637 6.426797977
24 2 6.425935599 0.251552103 1.223672319
25 1 1.239050459 6.993716285 0.919282767
26 1 8.597415423 9.744349170 9.618425189
27 2 9.588348358 5.218173407 4.967936337
28 1 3.374629600 1.970228435 7.437223081
29 2 5.342545294 2.810900411 2.845565392
30 1 5.899758117 4.230586386 0.575409557
31 1 2.773879758 4.614409908 6.102709062
32 2 2.665618658 8.230713464 8.150102591
33 1 9.568001278 7.336334193 8.230269208
34 2 -0.578288817 4.217101931 0.609238293
35 2 2.602121882 6.958684514 5.635750999
36 1 8.522792664 9.512460032 6.981427399
37 2 1.135362577 0.544381684 7.676299636
38 1 -1.720166827 -1.953539928 4.533736503
39 2 8.024948590 2.359929939 8.685564636
40 1 4.208893474 4.600204004 7.931710974
41 1 6.402655128 3.779030729 7.366181431
42 2 11.171976676 4.638840217 9.901540885
43 1 -4.009946426 8.962169565 3.826504449
44 2 5.007606656 9.119750470 8.424223984
45 1 3.982159937 4.693831744 2.746479658
46 1 4.390083376 1.362758764 9.763445616
47 2 4.590242792 3.199970999 5.482361587
48 1 8.585203068 0.946207812 13.664834150
49 2 5.718218224 6.473917973 7.842553786
50 1 7.466036211 5.982216009 9.492114818
51 1 8.124683907 7.914278619 11.550101410
52 2 3.587352296 9.217793697 6.264674655
53 1 0.634288319 7.445505269 3.580076215
54 2 7.828058557 6.792657158 6.873145767
55 3 4.343348837 7.832628040 7.330197684

Velocities

1 0.000000000 0.000000000 0.000000000
2 0.000000000 0.000000000 0.000000000
3 0.000000000 0.000000000 0.000000000
4 0.000000000 0.000000000 0.000000000
5 0.000000000 0.000000000 0.000000000
6 0.000000000 0.000000000 0.000000000
7 0.000000000 0.000000000 0.000000000
8 0.000000000 0.000000000 0.000000000
9 0.000000000 0.000000000 0.000000000
10 0.000000000 0.000000000 0.000000000
11 0.000000000 0.000000000 0.000000000
12 0.000000000 0.000000000 0.000000000
13 0.000000000 0.000000000 0.000000000
14 0.000000000 0.000000000 0.000000000
15 0.000000000 0.000000000 0.000000000
16 0.000000000 0.000000000 0.000000000
17 0.000000000 0.000000000 0.000000000
18 0.000000000 0.000000000 0.000000000
19 0.000000000 0.000000000 0.000000000
20 0.000000000 0.000000000 0.000000000
21 0.000000000 0.000000000 0.000000000
22 0.000000000 0.000000000 0.000000000
23 0.000000000 0.000000000 0.000000000
24 0.000000000 0.000000000 0.000000000
25 0.000000000 0.000000000 0.000000000
26 0.000000000 0.000000000 0.000000000
27 0.000000000 0.000000000 0.000000000
28 0.000000000 0.000000000 0.000000000
29 0.000000000 0.000000000 0.000000000
30 0.000000000 0.000000000 0.000000000
31 0.000000000 0.000000000 0.000000000
32 0.000000000 0.000000000 0.000000000
33 0.000000000 0.000000000 0.000000000
34 0.000000000 0.000000000 0.000000000
35 0.000000000 0.000000000 0.000000000
36 0.000000000 0.000000000 0.000000000
37 0.000000000 0.000000000 0.000000000
38 0.000000000 0.000000000 0.000000000
39 0.000000000 0.000000000 0.000000000
40 0.000000000 0.000000000 0.000000000
41 0.000000000 0.000000000 0.000000000
42 0.000000000 0.000000000 0.000000000
43 0.000000000 0.000000000 0.000000000
44 0.000000000 0.000000000 0.000000000
45 0.000000000 0.000000000 0.000000000
46 0.000000000 0.000000000 0.000000000
47 0.000000000 0.000000000 0.000000000
48 0.000000000 0.000000000 0.000000000
49 0.000000000 0.000000000 0.000000000
50 0.000000000 0.000000000 0.000000000
51 0.000000000 0.000000000 0.000000000
52 0.000000000 0.000000000 0.000000000
53 0.000000000 0.000000000 0.000000000
54 0.000000000 0.000000000 0.000000000
55 0.000000000 0.000000000 0.000000000

Masses

   1  28.085500000 # Si
   2  51.991610000 # Cr
   3  12.010700000 # C
   4  26.981540000 # Al

Again, please do not use the verb “to fix” in the context of LAMMPS. In this case the better term is to constrain. Also, if you have only 55 atoms in total and have multiple atom types, you cannot have a 55th carbon atom, but only the 55th atom (which will be a carbon). In fact, I only see one atom of type 3 and type 4 each (which would be carbon and aluminum, respectively, according to your original post).

You have three options:

  1. define a group (e.g. with group onebond id 14 55) and then use fix rigid with the “group onebond” option to select the group of atoms to keep rigid. Please note that this is not compatible with minimizations (fix rigid is not applied in that case).
  2. change the atom style (and the data file correspondingly) so that you define a bond between those two atoms (e.g. using bond style zero). Then you will need to use special_bonds lj/coul 1.0 1.0 1.0 to make certain there are no exclusions applied to the non-bonded interactions. And then you can apply fix shake based on the bond type (that would be bond type 1, since you will have only one bond and thus only one bond type).
  3. use fix restrain to add a restraining force between those two atoms. This will not keep the distance fixed, but close to the desired distance in accord with the selected force constant. Please note, that using a very large force constant (to make it a stiff restraint) will require using a shorter timestep.