Changing atom types

Hi Everyone,
I am trying to change the atom type of oxygen attached to the carbon with atom type 12 and the atom type of oxygen attached to the carbon with atom type 14. The different atom types are circled in red ink. I tried using the “if” statement to do the grouping for the different oxygen but was throwing this error “Illegal if command”. I am not too sure why I am having this error. Your suggestions on how to resolve this error or a better way to group the different oxygen atoms without the if statement would be greatly appreciated. Thanks. Please find attached the structure and the input file. Thanks.

group type4atoms type 4

group type12atoms type 12

group type16atoms type 16

Compute neighbor lists

neighbor 2.0 bin
neigh_modify every 1 delay 0 check yes

Define a variable to count the number of bonds

variable numBonds atom 0

Loop over atoms of type 4

label loop_atoms4

#variable i equal 1
variable i atom “${i} + 1”

Check if this atom is in group type1atoms

if “group(type4atoms) == ${i}” then

Loop over neighbors of atom i

variable j atom 0
label loop_neighbors
variable j atom “${j} + 1”

Check if this neighbor is in group type12atoms

if "group(type12atoms) == {j}" then # Change the atom type to 16 set type {i} 16
set type ${j} 16
endif
next loop_neighbors
endif

Increment the bond counter

variable numBonds atom “${numBonds} + 1”

Check if there are more atoms of type 1 to process

if “${i} <= count(type4atoms)” then
jump SELF loop_atoms1
endif

Your quoted input file is unusable/unreadable, since you are not quoting it correctly. Please see Please Read This First: Guidelines and Suggestions for posting LAMMPS questions

Overall, you are misunderstanding how looping and accessing data works. LAMMPS input file scripting is not a full programming language, so the logic that you want to employ cannot work. If you can manually look up individual atom IDs that need to be changed, you can use the set command on them or define a group and then apply set to the group.

Thank you for your reply. It will be difficult to manually look up the atom IDs because it is a polymer with over 60,000 atoms and I have even completed the production run. That’s why I am looking for a way to group and apply the set command. Could you please give me an idea of how I can do the grouping since you said the proposed way is not going to work?

1 Like

You won’t need to look them up manually. You just need some kind of property with a predictable pattern. For example, you can use atom style variables to select atoms. The following will define a group picking the 5th atom in each monomer of 20 atoms for a polymer that has a single atom as terminating group.

variable        get5th atom ((id-1)%20)==4
group           fifth variable get5th

You can also include checks for the existing atom type etc. Multiple conditions can be combined by multiplication. See the documentation for the group and the variable commands for more details and background information.

1 Like

Thanks for your help akohlmey. I have thought of this approach, but it is difficult to get a regular pattern because of the terminal monomers. One approach I am thinking of is to use the carbon atoms the oxygen atoms share bonds with to group the oxygen atoms since the carbon atoms have different atom types. Any suggestion on how I can do this?

I have shown you the path of how you have to think and looks at possible solutions. There are lots of features and trickery that can be done based on the various facilities and LAMMPS. It is mostly a matter of creativity to come up with more elaborate strategies. Since this is not my research, I know too little about the specifics (And I am not interested to learn them. That is between you and your adviser/supervisor/tutor) and your descriptions are too vague anyway.

You need some per-atom property to do this within LAMMPS, otherwise you have to use some programming of your own in a proper programming language. You can have a look at: Pre/Post Processing Tools for use with LAMMPS and 10. Auxiliary tools — LAMMPS documentation

I usually do complex system manipulation tasks with VMD since I know this program well and am comfortable with scripting in Tcl (hell, I have contributed quite a few extensions to VMD written in Tcl and am - to the best of my knowledge - the only person that was crazy enough to write an interface between Tcl and MPI for parallel programming using Tcl), but takes a while to pick up and learn. So I won’t recommend that unless you are already familiar with writing scripts in Tcl.

My only other advice, in case none of my suggestions are viable to you, is to find a sufficiently competent collaborator.

At any rate, this is now too specific to keep discussing it in this forum.

1 Like

‘fix bond/react’ can do what you need without using an “if” statement. however, generally speaking as Axel mentioned, this type of task is better done with pre/prost-processing tools if possible

1 Like