how to improve moltemplate performance

CC'd to the list. This conversation could be relevant to others
struggling to run moltemplate on large systems.

I have been using now for a while moltemplate as a way to generate
lammps data files...
The thing is moltemplate it is extremely slow for lots of small
molecules (e.g ~9 hours to generate the system for 500000 atoms of
benzenes molecules). Furthermore as far as I know moltemplate is not
parallelized either. Would the internal loops be easy to parallelize
using the multiprocessing package in Python for example? That was the
situation the last time I checked and I wanted to know if there are any
new improvements on performance in this regard?
Many thanks in advance,
Eduardo

Hi Eduardo

See the end of this email for my long term strategy to solve this problem.
(In this reply I added some new suggestions to the email I sent you earlier.)
For now, this is what I would do:

1) Run moltemplate.sh with the optional "-nocheck" argument. This
will improve performance by a factor of 1.5x up to 2x.

    (Only do this this *after* you have eliminated all of the syntax
errors from your files. I would not use the "-nocheck" when you are
initially building your first system. For what it's worth, even my
own moltemplate .LT files usually contain at least a couple errors
that would be difficult to find without "-nocheck". So I run
moltemplate on a small version of my system without "-nocheck" and get
rid of these errors. And then I increase the system size and run
moltemplate.sh again on the full-sized system using "-nocheck")

2) Avoid using the "cleanup_moltemplate.sh" script. (This is also
known as the "README_remove_irrelevant_info.sh" script.) It slows
down moltemplate by a factor of about 2x or 3x. So avoid it if you
can. If you do that, then the data file will contain references to
many atom types (and bond, angle, dihedral, and improper types) which
you don't need in your simulation. This isn't a problem. Having
several hundred extra atom types present doesn't slow down the
simulation more than 1-2% (on CPUs at least), and behavior of the
simulation will be identical. But it makes it a little harder to use
certain 3rd party tools (like VMD) which expect the number of atom
types to be small (less than 10 for VMD). (See below for VMD usage
tips.)

3) Try this only if you are desperate:
    Try consolidating your system into a few large objects, each with
many atoms, instead of many small molecules. I suggest this because I
am under the strong impression that the speed of moltemplate is
(mostly) determined by the number of objects that it has to create
(and much less so by the number of atoms in the system).
    To consolidate your system you could create a smaller version of
your system and use moltemplate.sh to create a LAMMPS data file and
input scripts for this small system (eg "system.data",
"system.in.init", "system.in.settings"...).
    Then you can run "ltemplify.py" on these newly created files to
create one object (eg. "SmallSystem") describing the entire (small)
system.

ltemplify.py -name SmallSystem \
    system.in.init system.in.settings system.data \
    > small_system.lt

Then you can create a new "system.lt" file containing many copies of
"SmallSystem":

------ example of "system.lt" file ------

import "small_system.lt"
subs = new SmallSystem
           [5].move(60.0, 0, 0)
           [5].move(0, 60.0, 0)
           [5].move(0, 0, 60.0)

write_once("Data Boundary") {
  0 300.0 xlo xhi
  0 300.0 ylo yhi
  0 300.0 zlo zhi
}