Replicating structures where bonds/angles etc cut through the periodic boundary

Are you certain that you need to have bonds in your crystal?
(See "Comments" at the end of this email.)

It is surprisingly difficult to do generate these kinds of bonds in moltemplate
(even if you write a for-loop to generate them. See comment #2 below...)

Moltemplate is currently does not yet have the ability to efficiently
check whether two atoms are close together, and add connecting bonds.

If you are certain that you need to simulate crystals filled with bond
constraints, then I recommend that you use use topotools to assign
bonds between nearby atoms. Then, if you still wish to use
moltemplate, you can convert the crystal created by topotools
(including atoms, bonds, angles, etc...) into a moltemplate object
format using the "" utility.

------------------------ Explanation ----------------------
(This was written in a hurry.
  Please correct me if you find any mistakes.)

   If you already have created the crystal in moltemplate, but it
lacks bonds, then you can use moltemplate to convert it into a DATA
file. #(this creates "")

    Then use topotools to read the DATA file created by moltemplate
(typically called "" using these commands (typically run
from inside the "Tk Console" in VMD):

topo readlammpsdata full

   (Note: you don't need to use moltemplate to generate the crystal.
Topotools has its own commands. See link below.) After you have
created or loaded the crystal into topotools, then use this command to
generate bonds between nearby atoms:

set sel [atomselect top all]
$sel set radius 2.1
mol bondsrecalc top

    I have not tried this. You may have to to play with the radius
parameter to get this to work. For more details, see:

    Next, write out a new DATA file using this command
topo writelammpsdata angle

    Finally, use to create a new .lt file.

echo "atom_style full" >

    Then run to convert into a moltemplate file: -name Crystal >

    Finally, create a new .LT file, and add these commands to that
file (in addition to other molecules you wish to use, like water):

crystal = new Crystal

    You can add other molecules to this file, for example, water:

import ""
wat = new SPCE [10].move(0.00, 0.00, 3.45)
                [10].move(0.00, 3.45, 0.01)
                [10].move(3.45, 0.01, 0.01)

    Finally, run on this new .LT file. is explained in appendix B of the moltemplate manual:

    An example of usage here:

------- COMMENTS: --------

I have never attempted a simulation of minerals

1) If you simulating pyrophyllite crystals in water at low
temperatures, then it is really the water you are simulating. You
probably don't need to use an accurate force-field if the atoms in the
pyrophyllite, if they do not move very much. In that case, simply
omit all of the crystal atoms from the group of atoms being integrated
in "fix nvt" or "fix npt". Alternately, use something like "fix
restrain" or "fix rigid" to constrain their motion.

(If your crystal is as large as your simulation box, then you will
have to be careful when running simulations under NPT conditions.
Be warned that the advice in that link is no longer up-to-date, and
may no longer work.)

2) If you are certain that you must bonds to connect atoms between
unit cells, you could try using a for-loop to create bonds between
atoms in neighboring unit cells. Prompted by your email, I attempted
to make a bonded aluminum crystal. As a cautionary tale, I have
attached a picture of what this looks like. (...along with the python
script which generated them. Atoms in the first unit cell are shown
in dark blue. Apparently not all bonds are between nearest-neighbor
lattice sites. Notice missing bonds between atoms in unit cells
accross the central diagonal. It's certainly possible to change the
python script to add these diagonal bonds, but is it worth the

In summary, I recommend you use topotools to generate the crystal, and
using to convert the crystal back into moltemplate

Even if you get around this issue, keep in mind that you will not be
able to simulate crystal dislocations and defects which may be
important at higher temperatures and/or pressures. Bonds behave like
harmonic constraints which prevent those kinds of atom movements from
occurring. However, LAMMPS offers several manybody pair_styles which
might be useful under these conditions. (To be clear, if you are
using these pair_styles, you should not be connecting these atoms
together with bonds.)

I hope this helps


al_bonded_crystal_failure.png (1.69 KB) (5.06 KB) (5.84 KB) (947 Bytes)

Dear Andrew,

Thank you for the reply.
I am planning to build pair style for my pyrophyllite model, therefore, I think I do not need to build bonds as you mentioned in the last sentence(To be clear, if you are using these pair_styles, you should not be connecting these atoms together with bonds.).
However, I have a question based on this sentence.
In the example of CNT which is on the moltemplate website, the SPCE water molecule has OH bonds but there is also pair style in the script. This do not meet what you have mentioned. Can you please explain?

Thank you!

Miao-Chun Wang