# How does lammps calculate number of atoms in the simulation box when using lattice command?

Hey All!!

I am trying to do lj fluid simulations using lj units in lammps. For this, I want to create an initial configuration for a given reduced density (as defined in lammps lj units).

For this I am defining a region with a certain box size, say side = 8 (reduced units), then using lattice command followed by create_atoms command, I create the simulation box with atoms in it.

As we mention the reduced density in the lattice command for lj units, I am unable to understand how does it calculate the no. of atoms in the simulation box. I have read the description for this in lammps documentation, but did not understand fully.

E.g. input and output are as follows:

Input:

``````variable side equal 8
region simbox block 0.0 \${side} 0.0 \${side} 0.0 \${side}
create_box 1 simbox

lattice fcc 1
create_atoms 1 box
``````

Output:

vol = 512 %% cube of 8
atoms = 666 %% Calculated by lammps
density = 1.3007812 %% This we get if we take atoms/vol

My expectation is to get the same density (i.e. 1) as output. But that is not the case. Can someone please help?

Thanks and regards,
Chaitanya

You would get 512 atoms for `lattice sc 1.0`.

I agree, that the documentation about this can be interpreted in different ways. Perhaps @sjplimp can comment on it and provide an explanation.

Yes, exactly. I tried different lattices with different densities.

I get density = 0.5 when I use volume corresponding to 512 atoms with

``````     lattice sc 0.5
``````

But if I change the volume i.e. box size which corresponds to 256 atoms with same lattice command,
the output density changes to 0.6699.

I want to do simulations at different densities and hence want to understand the calculation of number of atoms.

Chaitanya

From some experimentation, I realized that if we input the side length back-calculated from taking number of atoms as 512, gives the expected density for different densities with simple cubic lattice.

Whereas, the same is true for fcc lattice with dimensions input corresponding to 256 atoms.

Please look into it and try to explain the reasoning behind it.

Thanks and regards,
Chaitanya

Hi - the problem in your original post is that you are using the lattice command after
creating the box. You need to use it before you create the box (followed by creating the atoms),
and things will work as you expect.

I.e. if you use lattice fcc 1.0 versus lattice sc 1.0 you will get more atoms in a bigger box for fcc
than for sc, and the two reduced densities will be the same (1.0). More atoms b/c the fcc cubic unit
cell has 4 atoms whereas the sc cubic unit cell has 1.

This is b/c the create_box command uses lattice units by default, and if you haven’t defined
a lattice then it doesn’t know if you are going to use fcc vs sc vs whatever to create atoms and it cannot create a box of the correct size to achieve the density you specify.

Steve

Hey,

I tried to implement what I understood from your explanation as follows:

``````variable side equal 8  %%Based on N=512
region simbox block 0.0 \${side} 0.0 \${side} 0.0 \${side}

lattice fcc 1     %% Reduced density=1
create_atoms 1 box

create_box 1 simbox
``````

This gives me exactly the same output I get according to my original input.
i.e. Natoms = 666 and density = 1.3

Whereas if use sc in place of fcc, I do get correct density = 1
Did I get you wrong?

-Chaitanya

This input has multiple errors and thus cannot produce any output.