Create and run mixed liquid system with OPLS-AA force fields using moltemplate + LAMMPS

  1. Create ‘oplsaa_subset.prm’ from ‘oplsaa.prm’ by delete all lines starting with keyword ‘atom’ that does not use in our system.
  2. Generate ‘’ file using the following moltemplate command: oplsaa_subset.prm

    As a result, ‘’ file will be created.

  3. For each type of molecule used in the system, create ‘[MOLNAME].lt’ file containing atomic data of that molecule (i.e. atom coordinate, atom species corresponding to the and covalent bonding). For example, file for ethylene molecule is formatted as the following:

    import “

    Ethylene inherits OPLSAA {

      # atomid  molid  atomtype charge      X         Y        Z

      write(‘Data Atoms’) {

        $atom:C1  $mol @atom:88  0.00  -0.6695    0.000000  0.000000

        $atom:C2  $mol @atom:88  0.00   0.6695    0.000000  0.000000

        $atom:H11 $mol @atom:89  0.00  -1.234217 -0.854458  0.000000

        $atom:H12 $mol @atom:89  0.00  -1.234217  0.854458  0.000000

        $atom:H21 $mol @atom:89  0.00   1.234217 -0.854458  0.000000

        $atom:H22 $mol @atom:89  0.00   1.234217  0.854458  0.000000


      # Note: You don’t have to specify the charge in this example because

      #       we are using the OPLSAA forcefield assigns this by atomtype.

      #       Just leave these numbers as 0.00 for now.

      write(‘Data Bond List’) {

        $bond:C12  $atom:C1 $atom:C2

        $bond:C1H1 $atom:C1 $atom:H11

        $bond:C1H2 $atom:C1 $atom:H12

        $bond:C2H1 $atom:C2 $atom:H21

        $bond:C2H2 $atom:C2 $atom:H22


    } # Ethylene

  4.  Create ‘’ file, which describes how the molecule will be mixed. The following is an example provided by moltemplate to create ethylene+benzene system:

    import “  # <- defines the “Ethylene” molecule type.

    import “  # <- defines the “Benzene” molecule type.

    # Periodic boundary conditions:

    write_once(Data Boundary) {

       0.0  80.00  xlo xhi

       0.0  80.00  ylo yhi

       0.0  80.00  zlo zhi


    # Create 1000 ethylenes and 500 benzenes

    ethylenes = new Ethylene[10].move(8.0, 0, 0)

                            [10].move(0, 8.0, 0)

                            [10].move(0, 0, 8.0)

    benzenes  = new Benzene[10].move(8.0, 0, 0)

                           [10].move(0, 8.0, 0)

                           [5].move(0, 0, 16.0)

    # Now shift the positions of all of the benzene molecules,

    # to reduce the chance that they overlap with the ethylene molecules.

    benzenes[*][*][*].move(4.0, 4.0, 4.0)

    Note: Leave enough empty space for system to expand.

  5. Run the following command create LAMMPS input files using moltemplate:

    This command will generate input files (i.e.*) and initial configuration (i.e. Note that the bond angle, torsion angle, etc, will be generated automatically.

  6. Run NPT simulation to find the corresponding density of the mixed liquid system. Here is the NPT provided by moltemplate:


    #     You must use to create 3 files:


    #     (Follow the instructions in,

    #      or run the file as a script using ./

    # ——————————- Initialization Section ——————–

    include         “”

    # ——————————- Atom Definition Section ——————-

    read_data       “”

    # OPLSAA atom charges are stored in a separate file.

    # Load that file now:

    include         “”

    # ——————————- Settings Section ————————–

    include         “”

    # ——————————- Run Section ——————————-

    # — minimization protocol —

    minimize 1.0e-4 1.0e-6 100000 400000

    # — simulation protocol —

    timestep        1.0

    print “—————————————————————————“

    print “First, use Langevin dynamics to randomize the initial shape of the molecules”

    print “(This is not really necessary, but it seems to speed up equilibration.)”

    print “—————————————————————————“

    fix fxlan all langevin  300.0 300.0  120  123456  # temp: 300 K

    fix fxnph all nph  iso 50.0 50.0 1000.0   # pressure: 50 barr

    run 2000

    unfix fxlan

    unfix fxnph

    print “—————————————————————————“

    print “— Now continue the simulation using a Nose-Hoover Thermostat/Barostat —“

    print “—————————————————————————“

    dump            1 all custom 1000 traj_npt.lammpstrj id mol type x y z ix iy iz

    # temperature: 300 K, pressure: 50 barr

    fix             fxnpt all npt temp 300.0 300.0 100.0 iso 50.0 50.0 1000.0 drag 1.0

    thermo          100

    #thermo_modify  flush yes

    run             100000


    Make sure that number of run steps is sufficient for system to equilibrated.

  7. After that, ‘’ can be used to run NVT if other properties are needed (e.g. MSD, g(r), velocity auto-correlation function). Here is the NVE setting provided by moltemplate:


    #   1) You must use to create 3 files:


    #      (Follow the instructions in,

    #       or run the file as a script using ./

    #   2) You must equilibrate the system beforehand using “”.

    #      This will create the file “” which this file reads.

    #      (Note: I have not verified that this equilibration protocol works well.)

    # ——————————- Initialization Section ——————–

    include         “”

    # ——————————- Atom Definition Section ——————-

    # Read the coordinates generated by an earlier NPT simulation

    read_data       “”

    # OPLSAA atom charges are stored in a separate file.

    # Load that file now:

    include         “”

    # ——————————- Settings Section ————————–

    include         “”

    # (The “write_restart” and “read_restart” commands were buggy in 2012,

    #  but they should work also.  I prefer “write_data” and “read_data”.)

    # ——————————- Settings Section ————————–


    # ——————————- Run Section ——————————-

    # — simulation protocol —

    timestep        1.0

    dump            1 all custom 5000 traj_nvt.lammpstrj id mol type x y z ix iy iz

    fix             fxnvt all nvt temp 300.0 300.0 500.0 tchain 1

    thermo          500

    #thermo_modify  flush yes

    run             200000


  8. Note: for visualization, a bit of modification is needed in order to correct the atom species, pbc, wrapping atoms:
  9. ——- To view a lammps trajectory in VMD ——–

    1) Build a PSF file for use in viewing with VMD.

    This step works with VMD 1.9 and topotools 1.2.

    (Older versions, like VMD 1.8.6, don’t support this.)

    a) Start VMD

    b) Menu  Extensions->Tk Console

    c) Enter:

    (I assume that the the DATA file is called “”)

       topo readlammpsdata full

       animate write psf system.psf


    Later, to Load a trajectory in VMD:

      Start VMD

      Select menu: File->New Molecule

    -Browse to select the PSF file you created above, and load it.

      (Don’t close the window yet.)

    -Browse to select the trajectory file.

      If necessary, for “file type” select: “LAMMPS Trajectory”

      Load it.

       —-  A note on trajectory format: —–

    If the trajectory is a DUMP file, then make sure the it contains the

    information you need for pbctools (see below.  I’ve been using this

    command in my LAMMPS scripts to create the trajectories:

      dump 1 all custom 5000 DUMP_FILE.lammpstrj id mol type x y z ix iy iz

    It’s a good idea to use an atom_style which supports molecule-ID numbers

    so that you can assign a molecule-ID number to each atom.  (I think this

    is needed to wrap atom coordinates without breaking molecules in half.)

    Of course, you don’t have to save your trajectories in DUMP format,

    (other formats like DCD work fine)  I just mention dump files

    because these are the files I’m familiar with.

    3) —–  Wrap the coordinates to the unit cell

              (without cutting the molecules in half)

    a) Start VMD

    b) Load the trajectory in VMD (see above)

    c) Menu  Extensions->Tk Console

    d) Try entering these commands:

        pbc wrap -compound res -all

        pbc box

        —– Optional —-

        Sometimes the solvent or membrane obscures the view of the solute.

        It can help to shift the location of the periodic boundary box

        To shift the box in the y direction (for example) do this:

        pbc wrap -compound res -all -shiftcenterrel {0.0 0.15 0.0}

        pbc box -shiftcenterrel {0.0 0.15 0.0}

        Distances are measured in units of box-length fractions, not Angstroms.

        Alternately if you have a solute whose atoms are all of type 1,

        then you can also try this to center the box around it:

        pbc wrap -sel type=1 -all -centersel type=2 -center com


        You should check if your periodic boundary conditions are too small.

        To do that:

           select Graphics->Representations menu option

           click on the “Periodic” tab, and

           click on the “+x”, “-x”, “+y”, “-y”, “+z”, “-z” checkboxes.

    5) Optional: If you like, change the atom types in the PSF file so

       that VMD recognizes the atom types, use something like:

    sed -e ‘s/   1    1      /   C    C      /g’ < system.psf > temp1.psf

    sed -e ‘s/   2    2      /   H    H      /g’ < temp1.psf  > temp2.psf

    sed -e ‘s/   3    3      /   P    P      /g’ < temp2.psf  > system.psf

    (If you do this, it might effect step 2 above.)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s