Bug in assignment of atomic types

Dear all.
Consider the following script. It should print that the atom 1 is type 1 (charge +1) and atom 2 is type 2 (charge -1). However, it prints that both atoms are type 2 with charges -1. If I enter the second basis vector not as 0.5 but 0.49999, it is ok. However, for 0.499999 and closer to 0.5 it fails. This can be reproduced using ver. 29Aug24 and it does the same in 17Apr24. Thanks for your help,
Roman

units metal
atom_style charge
atom_modify map yes

lattice custom 4.0 &
   a1 0.0 0.5 0.5 &
   a2 0.5 0.0 0.5 &
   a3 0.5 0.5 0.0 &
   basis 0.0 0.0 0.0 &
   basis 0.5 0.5 0.5 
region box block 0 1 0 1 0 1
create_box 2 box
create_atoms 2 box basis 1 1 basis 2 2

set type 1 charge 1.0
set type 2 charge -1.0

variable q1 equal q[1]
variable q2 equal q[2]
variable t1 equal type[1]
variable t2 equal type[2]
print "types: ${t1} ${t2}"
print "charges: ${q1} ${q2}"

Its expected. You have only one create_atoms command, and you are using it to create atoms of type 2.

According to the manual “By default, all created atoms are assigned the argument type as their atom type.” Therefore type in create_atoms is irrelevant if I later specify basis.

You are right.

If I add the following commands at the end of your input:

mass * 1
write_data lmp.data

In indicates that you have indeed atom of both types, but atoms 1 and 2 are both type 2:

Atoms # charge

1 2 -1 0 0 2 0 0 0
2 2 -1 0 2 0 0 0 0
3 2 -1 2 0 0 0 0 0
4 1 1 0 0 0 0 0 0
5 2 -1 2 2 2 0 0 0
6 1 1 0 2 2 0 0 0
7 1 1 2 0 2 0 0 0
8 1 1 2 2 0 0 0 0

No, it should not. The ordering of atoms is not guaranteed to be as you seem to expect by the algorithm that applies positions and types in create_atoms. That algorithm is optimized to efficiently create large numbers of atoms in parallel and not a specific ordering.

All you can assume is that 4 out of the 8 atoms created are of type 1 and 4 are of type 2 and that is confirmed by the output from the set command:

Setting atom values ...
  4 settings made for charge
Setting atom values ...
  4 settings made for charge

I see, now I understand. When I print all eight atoms, I get:

types: 2 1 2 2 1 1 1 2
charges: -1 1 -1 -1 1 1 1 -1

The IDs of atoms are just shuffled but they are all there correctly. Thanks a lot Axel.