Controlling the pore surface

Dear Karsu

   If you want to replace atoms with chemical groups in an existing
structure, it's relatively simple to delete the atoms you don't want,
and paste coordinates for the new chemical groups or subunits into the
correct positions with the correct orientation. It's also easy to
connect them with bonds. I demonstrate how to do these steps (using
moltemplate) below (see steps 4-7).

     However the more difficult issue is that you will be forced to
create 3-body and 4-body angle and dihedral (and improper)
interactions which join the old and new bonds (so the chemical groups
don't flop about in a crazy fashion). You have to do that whenever
you change the bond topology of the system. You can attempt to
manually add these interactions to the "Angles" and "Dihedrals"
sections of the data file yourself, but there are often a large number
of them, and it is easy to make a mistake and omit one.

---- Figure out the new angles and dihderals manually ---

    If you have figured out all of the old old and new angle and
dihedral interactions (to replace a C=O bond with a C-CH3 bond, for
example), you can define molecule templates before and after the
reaction and use "fix bond/react" to perform the reaction immediately
(setting Nevery to 1 and the reaction probability to 1).
https://lammps.sandia.gov/doc/fix_bond_react.html
  Fix bond/react is powerful, but I'm not aware that it can change the
number of atoms in the system yet. (Hopefully somebody will correct
me if I'm wrong. This is relevant since you will be replacing O atoms
with CH3 groups.) Either way, I suppose you could delete the terminal
oxygens and place the methyl groups in the appropriate locations and
wait for the reaction to happen (which should hopefully take only 1
Verlet iteration).

---- Use a molecule builder to generate the new angles, dihedrals,
impropers ----

   Alternatively, molecule builders allow you to specify the list of
bonds, angles, dihedrals that you want exactly, as well as
(optionally) a set of force-field rules which tell the software how
you want it to create these angular interactions automatically so you
don't have to.

   If you are going to use a molecule builder, you have two choices:

A) Familiarize yourself with the file format the software uses to
describe these rules, so that you can tell the molecule builder how
you want it to generate new angle and dihedral interactions when you
replace an O atom with a methyl group (for example).

B) Choose an existing popular force-field (and choose a
molecule-builder which supports it), and change all of the atom types
in your structure to be compatible with the atom types used by that
force field.

Details (B):
  Choose an existing popular force-field (and choose a
molecule-builder which supports it), and change all of the atom types
in your structure to be compatible with the atom types used by that
force field. Most molecule builders use atom type (and sometimes bond
type) to lookup angle, dihedral, and improper interactions, so you
will have to change the name of these atom types to something that the
force field understands. (You will also have to delete all of the
existing text in the "Angles", "Dihedrals", and "Impropers" section of
your DATA file, since all of these interactions will have to be
generated from scratch. It's not a great idea to combine interactions
from two different force fields in same simulation, or same molecule)
Then, add the new atoms (and if necessary, bonds). The molecule
builder will do the rest. There are instructions for doing this with
moltemplate below. (moltemplate currently supports OPLSAA, GAFF,
GAFF2, COMPASS-published.

---------- instructions for doing this with moltemplate ----------

---- step 1 ----
Firstly, I assume that you already have a LAMMPS data file (and the
corresponding input file that works with it, which I named "FILE.data"
and "FILE.in" in the example below). If so, you can create a
moltemplate object describing it using the "ltemplify.py" file
converter (which is included with moltemplate). This will enable you
to edit and modify your original system with moltemplate:

ltemplify.py -name OldSystem FILE.in FILE.data > old_system.lt

(See appendix B of the moltemplate manual if you want more information
about what "ltemplify.py" does.)

---- step 2(A) ----

    Note: There are two versions of this step.
    Either choose step 2A OR step 2B, but not both.

    IF you decide to create rules to add new angle and dihedral
interactions to your system, then create these rules in a file (eg
"force_field.lt")

ForceField {
   #rules and force field parameters go here...
}

Details: The file format of "force_field.lt" is described in the
"force_field.lt" and "oplsaa_simple.lt" files included (with context)
in these examples:
http://moltemplate.org/examples/force_fields/

     A gruesomely detailed explanation of the file format is included
in slides #51-54 of this talk:
http://moltemplate.org/doc/moltemplate_talk_2013-8-07.pdf

...and it is also mentioned in chapter 6 of the moltemplate manual
(http://moltemplate.org/doc), as well If you have any questions about
the file format, let me know. (Incidentally, moltemplate will not
automatically erase your existing angle, dihedral, and improper
interactions. It will simply add new ones.)

Then insert the following line (import "force_field.lt") to the
BEGINNING of your "old_system.lt" file which you created in step 1, so
that the beginning of that file now looks like this:

import "force_field.lt"
OldSystem inherits ForceField {

---- step 2(B) ----

    ALTERNATIVELY, if you don't want to create new force-field rules,
but you want to use the existing force-field rules from an existing
force field, you will need to replace all of the existing atom types
in your structure, with atom types from that force field (for example
OPLSAA). In that case, the procedure below is a little bit involved:

First, manually edit the "old_system.lt" file, and replace the first
line ("OldSystem {") with the following text:

import "oplsaa.lt" #(defines OPLSAA)
OldSystem inherits OPLSAA {

You will have to familiarize yourself with these atom types. For a
list of the atom type names used by the OPLSAA force-field that comes
with moltemplate, see this file:
https://github.com/jewettaij/moltemplate/blob/master/moltemplate/force_fields/oplsaa.lt
In particular, look at the write_once("In Charges") section, near the top.
Excerpt from that file:
    set type @atom:80 charge -0.18 # "Alkane CH3-"
    set type @atom:81 charge -0.12 # "Alkane -CH2-"
    set type @atom:82 charge -0.06 # "Alkane >CH-"
    set type @atom:83 charge -0.24 # "Methane CH4"
    set type @atom:84 charge 0.0 # "Alkane >C<"
    set type @atom:85 charge 0.06 # "Alkane H-C"

(Again, if you're curious about the file format simplified version of
this file is available here:
https://moltemplate.org/examples/force_fields/alkane_chain_single/oplsaa_simple.lt)

(Incidentally, if you're using OPLSAA, then avoid the atom-types from
1-56 whose descriptions end in "(UA)". Those are for coarse-grained
("united-atom") simulations. Don't use them in an all-atom sim.)

  Now comes the difficult part: Read the file created in step 1
("old_system.lt"). In moltemplate, atom types are given names
beginning with "@atom:". The "ltemplify.py" script currently usually
generates atom type names such as "@atom:type1", but they might have
different names, depending on the contents of the DATA file you fed to
it in step 1.) You need to replace each of these old atom type names
(eg. "@atom:type6") with the corresponding OPLSAA-compatible name (eg
"@atom:80"). (Incidentally, "@atom:80" in OPLSAA corresponds the
the carbon atom from a methyl group.) One way to do that is to open a
text editor and manually replace all of these text strings yourself
("@atom:type6" -> "@atom80"). However that's probably a bit
cumbersome and error-prone.

Alternatively, you can copy the "oplsaa.lt" file into the working
directory containing your other .LT files. (such as "old_system.lt".
Incidentally, moltemplate will preferentially use the local version of
any .LT file.) Then edit this file and insert additional "replace"
commands for each of your atom types. Scroll down to the beginning of
the list of "replace" commands (it's a long file), and add commands
like this to the beginning of this list:

  replace{ @atom:type1 @atom:83_b013_a013_d013_i013 }
  replace{ @atom:type2 @atom:81_b013_a013_d013_i013 }
  replace{ @atom:type3 @atom:84_b013_a013_d013_i013 }
  replace{ @atom:type4 @atom:82_b013_a013_d013_i013 }
  replace{ @atom:type5 @atom:85_b046_a046_d046_i046 }
  replace{ @atom:type6 @atom:80_b013_a013_d013_i013 }
  replace{ @atom:type7 @atom:78_b044_a044_d044_i044 }
  replace{ @atom:type8 @atom:79_b045_a045_d045_i045 }

Add one such command for each of the atom types in your original data file.

   What do these weird "80_b013_a013_d013_i01" strings mean?
Actually, I lied earlier. @atom:80" is not the full name of the
methyl carbon atom type in OPLSAA. (The full name is actually
"@atom:80_b013_a013_d013_i01", but nobody wants to type that in, so I
allow them to use the abbreviated name "@atom:80" instead. That's
actually the purpose of all of these "replace" commands.)

To recap, for each TYPE of atom in your "old_system.lt" file (eg
"@atom:type6"), you would need to:

FIRST, figure out the abbreviated atom type name in the force field
you want to use (eg "@atom:83")

THEN, figure out what the corresponding full-length version of that
atom type name (eg "@atom:80_b013_a013_d013_i01"), by searching for
@atom:80 in the list of "replace" commands in the force field file
("oplsaa.lt").

This is tricky, so you have any questions about this then email me.

Once this is done, then things get much easier:

---- step 3 -----

Create a new file (eg "system.lt") with the following contents:
---- system.lt ----
import "old_system.lt" #(defines "OldSystem")
old_system = new OldSystem #(create a single copy of the old system)

...Then, if you can write a script which can identify all of the
terminal oxygen atoms in your structure that you want to replace,
along with the atoms they are currently bonded to, then you can use a
list of moltemplate commands, added to the "system.lt" file, such as
these:

---- step 4 Delete the terminal oxygens ----

Note: The remaining steps assume you are using the OPLSAA force field.
If not, then replace OPLSAA with the name of whatever force field you
are using, and change the @atom type names accordingly.

OldSystem inherits OPLSAA {
  # augment the definition of "OldSystem" with these commands
  delete $atom:old_system/type7_243
  delete $atom:old_system/type7_247
  delete $atom:old_system/type7_253
}
  :
# In moltemplate, anything beginning with $atom: (including the "/")
# refers to an "instance" of an atom instance (ie. an atomID counter).
# The name of the atoms may vary, but $atom names generated by
# ltemplify.py usually begin with "type?_" followed by a counter
# indicating which copy of that atom type you are interested in.

---- step 5: change atom types bound to oxygens ----

# Optional? Change the types of the atoms which
# were bound to the terminal oxygens:
# (eg "type7_151", 153, 156,...)

OldSystem inherits OPLSAA {
  # augment the definition of "OldSystem" with these commands:
  # overwrite the atoms which were bonded to the terminal oxygens:
  write("Data Atoms") {
    $atom:type7_151 $mol @atom:84 0.11 -3.365 0.678 1.133
    $atom:type7_153 $mol @atom:84 0.11 -3.892 1.592 -0.905
    $atom:type7_156 $mol @atom:84 0.11 -4.264 -1.466 -0.292
      :
  }
}

# Note: The coordinates must also be copied from the original data file.
# (unfortunately)

ch3group.lt (2.19 KB)

Sigh.
There were enough serious mistakes and omissions in my previous post,
that I think it warrants another post.

Here are some corrections and clarifications:

> What I want to is to delete for instance all the terminal oxygen atoms (red ones)
> that are on the pore surface and replace them with an organic group like methyl.
> it'd be really helpful if I have some guidance in terms of which procedure
> is more achievable and likely to give me what I want, so that I can invest
> my time completely on that approach.

Dear Karsu

   If you want to replace atoms with chemical groups in an existing
structure, it's relatively simple to delete the atoms you don't want,
and paste coordinates for the new chemical groups or subunits into the
correct positions with the correct orientation. It's also easy to
connect them with bonds. I demonstrate how to do these steps (using
moltemplate) below (see steps 4-7).

     However the more difficult issue is that you will be forced to
create 3-body and 4-body angle and dihedral (and improper)
interactions which join the old and new bonds (so the chemical groups
don't flop about in a crazy fashion). You have to do that whenever
you change the bond topology of the system. You can attempt to
manually add these interactions to the "Angles" and "Dihedrals"
sections of the data file yourself, but there are often a large number
of them, and it is easy to make a mistake and omit one.

---- Figure out the new angles and dihderals manually ---

    If you have figured out all of the old old and new angle and
dihedral interactions (to replace a C=O bond with a C-CH3 bond, for

? I may be chemically challenged, but that previous statement doesn't
sound right to me. If I got the atom types wrong, hopefully you
understood what I was trying to say.

More corrections to follow (scroll down)

example), you can define molecule templates before and after the
reaction and use "fix bond/react" to perform the reaction immediately
(setting Nevery to 1 and the reaction probability to 1).
https://lammps.sandia.gov/doc/fix_bond_react.html
  Fix bond/react is powerful, but I'm not aware that it can change the
number of atoms in the system yet. (Hopefully somebody will correct
me if I'm wrong. This is relevant since you will be replacing O atoms
with CH3 groups.) Either way, I suppose you could delete the terminal
oxygens and place the methyl groups in the appropriate locations and
wait for the reaction to happen (which should hopefully take only 1
Verlet iteration).

---- Use a molecule builder to generate the new angles, dihedrals,
impropers ----

   Alternatively, molecule builders allow you to specify the list of
bonds, angles, dihedrals that you want exactly, as well as
(optionally) a set of force-field rules which tell the software how
you want it to create these angular interactions automatically so you
don't have to.

   If you are going to use a molecule builder, you have two choices:

A) Familiarize yourself with the file format the software uses to
describe these rules, so that you can tell the molecule builder how
you want it to generate new angle and dihedral interactions when you
replace an O atom with a methyl group (for example).

B) Choose an existing popular force-field (and choose a
molecule-builder which supports it), and change all of the atom types
in your structure to be compatible with the atom types used by that
force field.

Details (B):
  Choose an existing popular force-field (and choose a
molecule-builder which supports it), and change all of the atom types
in your structure to be compatible with the atom types used by that
force field. Most molecule builders use atom type (and sometimes bond
type) to lookup angle, dihedral, and improper interactions, so you
will have to change the name of these atom types to something that the
force field understands. (You will also have to delete all of the
existing text in the "Angles", "Dihedrals", and "Impropers" section of
your DATA file, since all of these interactions will have to be
generated from scratch. It's not a great idea to combine interactions
from two different force fields in same simulation, or same molecule)
Then, add the new atoms (and if necessary, bonds). The molecule
builder will do the rest. There are instructions for doing this with
moltemplate below. (moltemplate currently supports OPLSAA, GAFF,
GAFF2, COMPASS-published.

---------- instructions for doing this with moltemplate ----------

---- step 1 ----
Firstly, I assume that you already have a LAMMPS data file (and the
corresponding input file that works with it, which I named "FILE.data"
and "FILE.in" in the example below). If so, you can create a
moltemplate object describing it using the "ltemplify.py" file
converter (which is included with moltemplate). This will enable you
to edit and modify your original system with moltemplate:

ltemplify.py -name OldSystem FILE.in FILE.data > old_system.lt

(See appendix B of the moltemplate manual if you want more information
about what "ltemplify.py" does.)

---- step 2(A) ----

    Note: There are two versions of this step.
    Either choose step 2A OR step 2B, but not both.

    IF you decide to create rules to add new angle and dihedral
interactions to your system, then create these rules in a file (eg
"force_field.lt")

ForceField {
   #rules and force field parameters go here...
}

Details: The file format of "force_field.lt" is described in the
"force_field.lt" and "oplsaa_simple.lt" files included (with context)
in these examples:
http://moltemplate.org/examples/force_fields/

     A gruesomely detailed explanation of the file format is included
in slides #51-54 of this talk:
http://moltemplate.org/doc/moltemplate_talk_2013-8-07.pdf

...and it is also mentioned in chapter 6 of the moltemplate manual
(http://moltemplate.org/doc), as well If you have any questions about
the file format, let me know. (Incidentally, moltemplate will not
automatically erase your existing angle, dihedral, and improper
interactions. It will simply add new ones.)

Then insert the following line (import "force_field.lt") to the
BEGINNING of your "old_system.lt" file which you created in step 1, so
that the beginning of that file now looks like this:

import "force_field.lt"
OldSystem inherits ForceField {

---- step 2(B) ----

    ALTERNATIVELY, if you don't want to create new force-field rules,
but you want to use the existing force-field rules from an existing
force field, you will need to replace all of the existing atom types
in your structure, with atom types from that force field (for example
OPLSAA). In that case, the procedure below is a little bit involved:

First, manually edit the "old_system.lt" file, and replace the first
line ("OldSystem {") with the following text:

import "oplsaa.lt" #(defines OPLSAA)
OldSystem inherits OPLSAA {

You will have to familiarize yourself with these atom types. For a
list of the atom type names used by the OPLSAA force-field that comes
with moltemplate, see this file:
https://github.com/jewettaij/moltemplate/blob/master/moltemplate/force_fields/oplsaa.lt
In particular, look at the write_once("In Charges") section, near the top.
Excerpt from that file:
    set type @atom:80 charge -0.18 # "Alkane CH3-"
    set type @atom:81 charge -0.12 # "Alkane -CH2-"
    set type @atom:82 charge -0.06 # "Alkane >CH-"
    set type @atom:83 charge -0.24 # "Methane CH4"
    set type @atom:84 charge 0.0 # "Alkane >C<"
    set type @atom:85 charge 0.06 # "Alkane H-C"

(Again, if you're curious about the file format simplified version of
this file is available here:
https://moltemplate.org/examples/force_fields/alkane_chain_single/oplsaa_simple.lt)

(Incidentally, if you're using OPLSAA, then avoid the atom-types from
1-56 whose descriptions end in "(UA)". Those are for coarse-grained
("united-atom") simulations. Don't use them in an all-atom sim.)

  Now comes the difficult part: Read the file created in step 1
("old_system.lt"). In moltemplate, atom types are given names
beginning with "@atom:". The "ltemplify.py" script currently usually
generates atom type names such as "@atom:type1", but they might have
different names, depending on the contents of the DATA file you fed to
it in step 1.) You need to replace each of these old atom type names
(eg. "@atom:type6") with the corresponding OPLSAA-compatible name (eg
"@atom:80"). (Incidentally, "@atom:80" in OPLSAA corresponds the
the carbon atom from a methyl group.) One way to do that is to open a
text editor and manually replace all of these text strings yourself
("@atom:type6" -> "@atom80"). However that's probably a bit
cumbersome and error-prone.

Alternatively, you can copy the "oplsaa.lt" file into the working
directory containing your other .LT files. (such as "old_system.lt".
Incidentally, moltemplate will preferentially use the local version of
any .LT file.) Then edit this file and insert additional "replace"
commands for each of your atom types. Scroll down to the beginning of
the list of "replace" commands (it's a long file), and add commands
like this to the beginning of this list:

  replace{ @atom:type1 @atom:83_b013_a013_d013_i013 }
  replace{ @atom:type2 @atom:81_b013_a013_d013_i013 }
  replace{ @atom:type3 @atom:84_b013_a013_d013_i013 }
  replace{ @atom:type4 @atom:82_b013_a013_d013_i013 }
  replace{ @atom:type5 @atom:85_b046_a046_d046_i046 }
  replace{ @atom:type6 @atom:80_b013_a013_d013_i013 }
  replace{ @atom:type7 @atom:78_b044_a044_d044_i044 }
  replace{ @atom:type8 @atom:79_b045_a045_d045_i045 }

Add one such command for each of the atom types in your original data file.

   What do these weird "80_b013_a013_d013_i01" strings mean?
Actually, I lied earlier. @atom:80" is not the full name of the
methyl carbon atom type in OPLSAA. (The full name is actually
"@atom:80_b013_a013_d013_i01", but nobody wants to type that in, so I
allow them to use the abbreviated name "@atom:80" instead. That's
actually the purpose of all of these "replace" commands.)

To recap, for each TYPE of atom in your "old_system.lt" file (eg
"@atom:type6"), you would need to:

FIRST, figure out the abbreviated atom type name in the force field
you want to use (eg "@atom:83")

THEN, figure out what the corresponding full-length version of that
atom type name (eg "@atom:80_b013_a013_d013_i01"), by searching for
@atom:80 in the list of "replace" commands in the force field file
("oplsaa.lt").

This is tricky, so you have any questions about this then email me.

Once this is done, then things get much easier:

---- step 3 -----

Create a new file (eg "system.lt") with the following contents:
---- system.lt ----
import "old_system.lt" #(defines "OldSystem")
old_system = new OldSystem #(create a single copy of the old system)

...Then, if you can write a script which can identify all of the
terminal oxygen atoms in your structure that you want to replace,
along with the atoms they are currently bonded to, then you can use a
list of moltemplate commands, added to the "system.lt" file, such as
these:

---- step 4 Delete the terminal oxygens ----

Note: The remaining steps assume you are using the OPLSAA force field.
If not, then replace OPLSAA with the name of whatever force field you
are using, and change the @atom type names accordingly.

OldSystem inherits OPLSAA {
  # augment the definition of "OldSystem" with these commands
  delete $atom:old_system/type7_243
  delete $atom:old_system/type7_247
  delete $atom:old_system/type7_253
}

CORRECTION

First of all, I should clarify:
These lines should be added to the end of your "old_system.lt" file.
The correct lines are:

OldSystem inherits OPLSAA {
  # modify the definition of "OldSystem" with these commands
  delete $atom:type7_243
  delete $atom:type7_247
  delete $atom:type7_253
}

# In moltemplate, anything beginning with $atom: (including the "/")
# refers to an "instance" of an atom instance (ie. an atomID counter).
# The name of the atoms may vary, but $atom names generated by
# ltemplify.py usually begin with "type?_" followed by a counter
# indicating which copy of that atom type you are interested in.

---- step 5: change atom types bound to oxygens ----

# Optional? Change the types of the atoms which
# were bound to the terminal oxygens:
# (eg "type7_151", 153, 156,...)

OldSystem inherits OPLSAA {
  # augment the definition of "OldSystem" with these commands:
  # overwrite the atoms which were bonded to the terminal oxygens:
  write("Data Atoms") {
    $atom:type7_151 $mol @atom:84 0.11 -3.365 0.678 1.133
    $atom:type7_153 $mol @atom:84 0.11 -3.892 1.592 -0.905
    $atom:type7_156 $mol @atom:84 0.11 -4.264 -1.466 -0.292
      :
  }
}

CLARIFICATION: You should place the lines above at the end of your
"old_system.lt" file created in step 1.

# Note: The coordinates must also be copied from the original data file.
# (unfortunately)
#
# Note: Anything following "@atom:" (including "/" if present)
# refers to an atom type (not an atom ID).
#
# Note: You don't have to change the atom instance names ("$atom:type7_151")
# It doesn't matter that you changed the type from "type7" to "84".

---- step 6: Define the methyl group subunit object. ----

I have attached a file "ch3gcontaining a definition of the "CH3"

CORRECTION:

That line got garbled. I meant to say that I have attached file named
"ch3group.lt" to this post which contains a version of the methyl
group object which has been oriented in the correct direction. If you
actually decide to follow this procedure, then please use this file.

object (which you can rename if you like), to this post which uses the
OPLSAA force field. The name of the file is "ch3group.lt". This is
just a version of the methyl group defined here:
https://github.com/jewettaij/moltemplate/blob/master/examples/all_atom/force_field_OPLSAA/butane/moltemplate_files/ch3group.lt

If you are not using the OPLSAA force field, then make modifications
to this file according to the force field you are using.

---- step 7: Instantiate copies of the methyl group ("CH3") ----

CORRECTION:

Please also insert the following line at the beginning of the
"old_system.lt" file:

import "ch3group.lt"

This line defines the "CH3" object which we refer to later:

---- step 7: Instantiate copies of the methyl group ("CH3") ----

added_group1 = new CH3.rotvv(1,0,0,0.2,-0.75,0.9).move(27.81,-14.25,55.23)
added_group2 = new CH3.rotvv(1,0,0,0.83,0.31,-0.2).move(31.67,-11.81,50.18)
added_group3 = new CH3.rotvv(1,0,0,-0.92,1.5,0.7).move(29.92,-17.48,52.43)
added_group4 = new CH3.rotvv(1,0,0,-0.6,0.82,-0.4).move(24.81,-12.95,53.14)

CLARIFICATION:
Put these commands above at the end of "old_system.lt" file created in
step 1, somewhere before the final "}" bracket.

The "rotvv(ax,ay,az,bx,by,bz)" command will rotate the "CH3" object
originally oriented along the ax,ay,az direction so that it now points
along the bx,by,bz direction. You will probably want to choose this
new direction (bx,by,bz) so that it points along the original
direction of the bond that was attached to the terminal oxygen that
you deleted. The .move() command will move the "CH3" group so that
(the carbon atom of) that now occupies the position of the deleted
oxygen atom.

---- step 8 ----

CORRECTION:
The procedure described so far is incomplete.
I forgot to explain how to explicitly create bonds connecting the
methyl groups to the atoms you modified earlier.
Once the bonds have been defined, moltemplate will generate the angles
and dihedrals. But (unlike some other molecule builders) you do have
to define the bonds between atoms explicitly. (Moltemplate won't
infer their existence due to close proximity.) Here is how you do
that.

Note: Again, there are two versions of step 8: 8A and 8B.
Choose 8A OR 8B, but not both:

Step 8A:

If you are using the OPLSAA force field, then add these lines to the
end of your "old_system.lt" file:

OldSystem inherits OPLSAA {

  # Add bonds between the old atoms and the C atoms from the
  # CH3 objects we added earlier.

  write("Data Bond List") {
    $bond:new1 $atom:type7_151 $atom:added_group1/C
    $bond:new2 $atom:type7_153 $atom:added_group2/C
    $bond:new3 $atom:type7_156 $atom:added_group3/C
      :
  }
}

8B)
Alternatively, if you are NOT using an existing force-field like
OPLSAA, then you probably want to explicitly specify the type of bond
you want to add explicitly (instead of using force-field rules to
lookup the bond type). In that case use:

OldSystem inherits ForceField {

  # Add bonds of type "RCH3" between the old atoms and
  # the C atoms from the CH3 objects we added earlier.
  # (See "ch3group.lt" for a definition of the "CH3" object.)

  write("Data Bonds") {
    $bond:new1 @bond:RCH3 $atom:type7_151 $atom:added_group1/C
    $bond:new2 @bond:RCH3 $atom:type7_153 $atom:added_group2/C
    $bond:new3 @bond:RCH3 $atom:type7_156 $atom:added_group3/C
      :
  }
}

Somewhere, we need to define the @bond:RCH3 we are using. One way to
do this is to edit the "force_field.lt" file you created in step 2b,
and add these lines:

  write("In Settings") {
    bond_coeff @bond:RCH3 paramters for that new bond type go here
    # see https://lammps.sandia.gov/doc/bond_coeff.html
  }

Whew. That's it. Now run moltemplate:

moltemplate system.lt

This will generate a new DATA file, as well as an updated LAMMPS input
script containing the angle_coeff, dihedral_coeff commands for the new
angles and dihedrals you are creating for the methyl groups you added.

Keep in mind that it's quite likely that I probably have made some
typos in my long instructions above.
But the procedure should work.

I'm sure there are probably additional mistakes I made which I haven't
caught yet. But hopefully this gives you an idea how one might tackle
this kind of task using moltemplate (even if I admit, it's not that
easy).

If you get stuck, send me an email.
(It's probably not a good idea to include the LAMMPS mailing list in
your reply since your application is so specific to the problem you
are working on.)

Good luck.

ch3group.lt (2.19 KB)