Moltemplate cannot create Data Atoms file

Dear all,

I am a new user of LAMMPS and I have been trying to experiment with Moltemplate to gain some experience into creating LAMMPS input data.
I successfully recreated the “nanotube+water” example from moltemplate, and then proceded with a few tweaks to make it progressively closer to the systems I will study using LAMMPS. First of all, swapped the bespoke SPC/E water model with the SPC water model in the OPLSAA force field, to study the use of pre-existing force fields in moltemplate. After ironing a few spelling mistakes, the swap was successful and I could run a simulation.
Later, however, I tried creating a box of Acetonitrile using a bespoke force field file but molteplate seems unable to identify the “Data Atoms” field, and therefore the final system shows no atoms or bonds.
As far as I could see, the syntax of my structural (from ltemplify.py) and force field is consistent with both the OPLSAA file and the manual pages for creating force fields, but clearly something is missing my inspection, because molteplate runs normally elsewhere.
I have attached my input files. The “system” file is ‘acn_box.lt’, which depends on ‘acn.lt’ and ‘forcefield.lt’ files. I have omitted the carbon nanostructure files from the example, though including them through a final ‘system.lt’ file did not change the result. The assignment file does recognise the force field file, but seems unable to create instance of my Acetonitrile molecule, and I do not understand why.
Being a new user I cannot attach files unfortunately, so I will copy them below. ‘#’ lines have been removed for clarity, '@' is there to avoid tags.

Is there anyone who can find the mistake in my input? I would be very grateful for your help.
It must be in the syntax of some parts, but however long I inspect them I am unable to locate it.
Thank you in advance for your support.

Best regards,
Fabrizio Silveri

------- input files --------

------- File: ForceField_ACN.lt >

ForceField {

write_once(“Data Masses”) {
@\atom:CT 12.010700
@\atom:CZ 12.010700
@\atom:NZ 14.006700
@\atom:HC 1.007940
}

write_once(“In Init”) {
units real
atom_style full
pair_style lj/cut/coul/long 11.0 11.0
bond_style harmonic
angle_style harmonic
dihedral_style opls
improper_style harmonic
pair_modify mix geometric
special_bonds lj/coul 0.0 0.0 0.5
kspace_style pppm 0.0001
}

write_once(“In Settings”) {
pair_coeff @\atom:CT @\atom:CT 0.066 3.30
pair_coeff @\atom:HC @\atom:HC 0.015 2.50
pair_coeff @\atom:NZ @\atom:NZ 0.170 3.20
pair_coeff @\atom:CZ @\atom:CZ 0.066 3.30
}

write_once(“In Settings”) {
bond_coeff @\bond:CT-CZ 385.0 1.458
bond_coeff @\bond:CT-HC 410.0 1.087
bond_coeff @\bond:CZ-NZ 650.0 1.157
}

write_once(“Data Bonds By Type”) {
@\bond:CT-CZ @\atom:CT @\atom:CZ
@\bond:CT-HC @\atom:CT @\atom:HC
@\bond:CZ-NZ @\atom:CZ @\atom:NZ
}

write_once(“In Settings”) {
angle_coeff @\angle:HC–CT–CZ 35.0 108.5
angle_coeff @\angle:CT–CZ–NZ 150.0 180.0
angle_coeff @\angle:HC–CT–HC 35.0 109.5
}

write_once(“Data Angles By Type”) {
@\angle:HC–CT–CZ @\atom:HC @\atom:CT @\atom:CZ
@\angle:CT–CZ–NZ @\atom:CT @\atom:CZ @\atom:NZ
@\angle:HC–CT–HC @\atom:HC @\atom:CT @\atom:HC
}

< forcefield.lt END

------- File: acn.lt >

import “ForceField_ACN.lt”

ACN inherits ForceField {

write(“Data Atoms”) {
$atom:c2 $mol:acn @\atom:CT −0.08 -0.527520 -0.736650 -0.061930
$atom:c1 $mol:acn @\atom:CZ 0.460 -0.490180 0.691350 0.123090
$atom:n1 $mol:acn @\atom:NZ -0.56 -0.460210 1.840750 0.272090
$atom:h21 $mol:acn @\atom:HC 0.060 0.490830 -1.139500 -0.140720
$atom:h22 $mol:acn @\atom:HC 0.060 -1.074560 -0.989770 -0.979630
$atom:h23 $mol:acn @\atom:HC 0.060 -1.028760 -1.219740 0.787100
}

write(“Data Bond List”) {
$bond:cc $atom:CT $atom:CZ
$bond:ch1 $atom:CT $atom:HC_1
$bond:ch2 $atom:CT $atom:HC_2
$bond:ch3 $atom:CT $atom:HC_3
$bond:cn $atom:CZ $atom:NZ
}

write_once(“In Settings”) {
group acn type @\atom:CT @\atom:CZ @\atom:NZ @\atom:HC
}

write_once(“In Constraints”) {
fix fRattleAcn acn rattle 0.0001 10 100 b @\bond:CT-HC a @\angle:HC–CT–HC
}

} # end of “ACN” type definition

< acn.lt END

----- File: acn_box.lt >

import “acn.lt”

write_once(“Data Boundary”) {
-15.98682895386 15.98682895386 xlo xhi
-14.91 14.91 ylo yhi
-31.0 31.00 zlo zhi
}

solv = new ACN [7].move(2.5, 0, 0).rot(90, 1, 0, 0)
[7].move(0, 5.0, 0)
[4].move(2.5, 0, 0)

< acn_box.lt END

This is a question for @jewettaij, the author of moltemplate.

Disclaimer: this thread is slightly off-topic in this forum, but it’s still helpful to teach how to use Moltemplate to create suitable initial geometries for MD simulations and a complete input deck for LAMMPS.

Fabrizio, your idea was correct. However, you made many syntactic mistakes:

  • The files should be plain text, but yours seem to be formatted with a word editor: quotes and hyphens are replaced with special characters, e.g.
    wrong: write_once(“In Settings”) {
    correct: write_once("In Settings") {
    or
    wrong: angle_coeff @\angle:HC–CT–CZ 35.0 108.5
    correct: angle_coeff @angle:HC-CT-CZ 35.0 108.5
  • Moltemplate variables should be declared without escaping characters:
    wrong: @\atom:CT 12.010700
    correct: @atom:CT 12.010700
  • In the molecule definition (file acn.lt), the bond list must be defined with the variable used in the "Data Atoms" section:
    wrong: $bond:ch1 $atom:CT $atom:HC_1
    correct: $bond:ch1 $atom:c2 $atom:h21
  • The geometry that you specified has a lot of overlaps. But without creating the data file, it’s hard to tell!

I rearranged your input files more logically. This should get you started. The force field does not contain any dihedral or improper term to control the rotation of the terminal CH3 group, you may want to add one.

Here are the revised files.

File: ForceField_ACN.lt
ForceField {

write_once("Data Masses") {
 @atom:CT 12.010700
 @atom:CZ 12.010700
 @atom:NZ 14.006700
 @atom:HC 1.007940
}


write_once("In Settings") {
 pair_coeff @atom:CT @atom:CT 0.066 3.30
 pair_coeff @atom:HC @atom:HC 0.015 2.50
 pair_coeff @atom:NZ @atom:NZ 0.170 3.20
 pair_coeff @atom:CZ @atom:CZ 0.066 3.30
}

# Bonds
write_once("Data Bonds By Type") {
 @bond:CT-CZ @atom:CT @atom:CZ
 @bond:CT-HC @atom:CT @atom:HC
 @bond:CZ-NZ @atom:CZ @atom:NZ
}

write_once("In Settings") {
 bond_coeff @bond:CT-CZ 385.0 1.458
 bond_coeff @bond:CT-HC 410.0 1.087
 bond_coeff @bond:CZ-NZ 650.0 1.157
}

# Angles
write_once("Data Angles By Type") {
 @angle:HC-CT-CZ @atom:HC @atom:CT @atom:CZ
 @angle:CT-CZ-NZ @atom:CT @atom:CZ @atom:NZ
 @angle:HC-CT-HC @atom:HC @atom:CT @atom:HC
}

write_once("In Settings") {
 angle_coeff @angle:HC-CT-CZ 35.0 108.5
 angle_coeff @angle:CT-CZ-NZ 150.0 180.0
 angle_coeff @angle:HC-CT-HC 35.0 109.5
}

# You may want to add dihedral and improper angles too!


# These settings are needed for every simulation, so it's good
# to store them along with the force field.
write_once("In Init") {
 units real
 atom_style full
 pair_style lj/cut/coul/long 11.0 11.0
 bond_style harmonic
 angle_style harmonic
 dihedral_style opls
 improper_style harmonic
 pair_modify mix geometric
 special_bonds lj/coul 0.0 0.0 0.5
 kspace_style pppm 0.0001
}

}
File: acn.lt
import ForceField_ACN.lt

ACN inherits ForceField {

write("Data Atoms") {
 $atom:c2  $mol:acn @atom:CT  0.080 -0.527520 -0.736650 -0.061930
 $atom:c1  $mol:acn @atom:CZ  0.460 -0.490180  0.691350  0.123090
 $atom:n1  $mol:acn @atom:NZ -0.560 -0.460210  1.840750  0.272090
 $atom:h21 $mol:acn @atom:HC  0.060  0.490830 -1.139500 -0.140720
 $atom:h22 $mol:acn @atom:HC  0.060 -1.074560 -0.989770 -0.979630
 $atom:h23 $mol:acn @atom:HC  0.060 -1.028760 -1.219740  0.787100
}

# A list of atoms must be defined using the variable names used in the previous section.
write("Data Bond List") {
 $bond:cc  $atom:c1 $atom:c2
 $bond:ch1 $atom:c2 $atom:h21
 $bond:ch2 $atom:c2 $atom:h22
 $bond:ch3 $atom:c2 $atom:h23
 $bond:cn  $atom:c1 $atom:n1
}

# The group command can go in the same file as the rattle command.
write_once("In Constraints") {
 group acn type @atom:CT @atom:CZ @atom:NZ @atom:HC
 fix fRattleAcn acn rattle 0.0001 10 100 b @bond:CT-HC a @angle:HC-CT-HC
}

}
File: acn_box.lt
# I use moltemplate in a slightly different way,
# with a master file containing all the commands needed
# to create a valid input deck for LAMMPS.

# Define the input variables.
write_once("In Init"){
 # Input variables.
 variable run    string acn_box   # output log
 variable ts     equal  1         # timestep
 variable temp   equal  300       # equilibrium temperature
 variable p      equal  1.        # equilibrium pressure
 variable d      equal  1000      # output frequency
 variable prod   equal  30000     # Production steps

 # PBC (set them before the creation of the box).
 boundary p p p
}

# Import the force field.
import acn.lt

# Create the input sample.
# Changing geometry to avoid bad contacts.
solv = new ACN [7].move( 5, 0, 0)
               [7].move( 0, 5, 0)
               [4].move( 0, 0, 5)
solv[*][*][*].move(-17.5, -17.5, -10)

# Set the simulation box.
write_once("Data Boundary") {
 -17.5 17.5 xlo xhi
 -17.5 17.5 ylo yhi
 -10 10     zlo zhi
}

# Run an NPT simulation.
write_once("In Run"){
 # Derived variables.
 variable tcouple equal \$\{ts\}*100
 variable pcouple equal \$\{ts\}*1000

 # Output.
 thermo          \$d
 thermo_style custom step etotal evdwl ecoul elong ebond eangle edihed eimp &
 ke pe temp press vol density cpu
 thermo_modify flush yes
  
 # Trajectory.
 dump TRJ all dcd \$d \$\{run\}.dcd
 dump_modify TRJ unwrap yes
 
 # Thermalisation and relaxation, NPT ensemble.
 timestep       \$\{ts\}
 fix             NPT all npt temp \$\{temp\} \$\{temp\} \$\{tcouple\} aniso \$p \$p \$\{pcouple\}
 velocity all create \$\{temp\} 858096 dist gaussian
 run    \$\{prod\}
 unfix NPT
}

Note that here, I have used the escape character to protect LAMMPS variables inside the Moltemplate script, e.g. \$\{run\}.

Compile with:
moltemplate.sh acn_box.lt -overlay-all
Run with:
mpirun -np 4 lmp_2Aug23 -in acn_box.in -l acn_box.log

2 Likes

Dear Sir, sorry to bother you. I have a similar problem. I tried running this example from moltemplate but unfortunately i keep getting warnings about atom_style being unspecified. because of that it’s unable to generate data atoms file. Please, how can this be resolved? Below is the input script. thank you

file “spce.lt”

h1 h2

\ /

o

SPCE {

AtomID MoleculeID AtomType charge X Y Z

write(“Data Atoms”) {
$atom:o $mol:w @atom:open_mouth: -0.8476 0.0000000 0.00000 0.000000
$atom:h1 $mol:w @atom:H 0.4238 0.8164904 0.00000 0.5773590
$atom:h2 $mol:w @atom:H 0.4238 -0.8164904 0.00000 0.5773590
}

write_once(“Data Masses”) {
@atom:open_mouth: 15.9994
@atom:H 1.008
}

write(“Data Bonds”) {
$bond:oh1 @bond:OH $atom:o $atom:h1
$bond:oh2 @bond:OH $atom:o $atom:h2
}

write(“Data Angles”) {
$angle:hoh @angle:HOH $atom:h1 $atom:o $atom:h2
}

write_once(“In Settings”) {
bond_coeff @bond:OH 600.0 1.0
angle_coeff @angle:HOH 75.0 109.47
pair_coeff @atom:open_mouth: @atom:open_mouth: 0.1553 3.166
pair_coeff @atom:H @atom:H 0.0 0.0
group spce type @atom:open_mouth: @atom:H
# Note: Since we are using RATTLE constraints, the bond and angle strength
# parameters (“600.0”, “75.0”) do not matter. But the equilibrium bond
# length (“1.0”) and equilibrium angle (“109.47”) does matter. LAMMPS
# obtains these numbers from the bond_coeff and angle_coeff commands above.
}

write_once(“In Constraints”) {
group spce type @atom:open_mouth: @atom:H
fix fRattleSPCE spce rattle 0.0001 10 100 b @bond:OH a @angle:HOH
# Remember to put this command in your LAMMPS input script:
# include system.in.constraints
# …after minimization and after all integration fixes
}

write_once(“In Init”) {
# – Default styles (for solo “SPCE” water) –
units real
atom_style full
pair_style lj/charmm/coul/long 9.0 10.0
bond_style harmonic
angle_style harmonic
kspace_style pppm 0.0001
#pair_modify mix arithmetic # LEAVE THIS UNSPECIFIED!
}

} # end of definition of “SPCE” water molecule type

I don’t know why the scripts suddenly have emojis when i pasted them in this platform

  1. Please Read This First: Guidelines and Suggestions for posting LAMMPS questions
  2. You edit your post, making it readable.
  3. You add which command you have used, what you expected, and what you have obtained.
  4. You see emojis because you are pasting computer code in a markdown environment. If you don’t understand how to communicate your needs effectively, you will have a hard time in becoming a computational scientist.

Regarding your question, my guess is that you are asking Moltemplate to render the file spce.lt, which contains the force field specification of a single molecule of water. It does not make sense. Please start from the example which I have discussed and build from it.

Dear Dr. Roscioni,

thank you for your very helful reply.
About your comments:
For the first two mistakes you found, I only added "" characters to post the comment here, as the forum with interpret them as calling to other forum users and prevent me from posting. However, the last one was indeed a mistake that you helped me fix.
While I managed to create a workaround for the problem in the time since my initial post, I will try to integrate your very much advanced usage of the script in my systems.
Thank you,

Fabrizio Silveri

I know this forum typically deals with LAMMPS. But I understand that you are encountering a similar issue while generating LT files from moltemplate. I am discussing my issue here in the hope that someone can provide assistance. initially, I generated dmc. lt file by this command
mol22lt.py -i dmc.mol2 -o dmc.lt -name dmc -ff MyForceField --ff-file my_force_field
but i tried to generate my forcefield.lt file its empty by using this command below

amber2lt.py --in frcmod.dmc --name MyForceField \

my_force_field.lt
I encountered this error
Format Error: Expected (‘MASS’, ‘MASSES’). Found ‘BOND’. (Split file and use --bond, --angle, --dihedral, --improper arguments instead.)
Also, how to generate a master file (system. lt) when I have both OPLSAA and GAFF parameters?
thank you

This is too off-topic to be taken here. I also doubt that anyone could offer any advice on the error you have encountered, given that only you know what is inside the file frcmod.dmc. Please study the source code of amber2lt.py and try to figure it out yourself.

Mixing force fields is never a good idea, as you will have imbalances in the LJ and Coulomb interactions.

1 Like