3 # reads Amber forcefield definition file(s) and converts to Gromacs
6 # Anton Feenstra - Vrije Universiteit Amsterdam - The Netherlands
12 # unit conversion functions:
14 # Angstrom (1e-10 m) to nanometers (1e-9 m)
19 # Angstrom^-1 to nanometers^-1
24 # kCalories to kJoules
29 # kCal mol^-1 A^-n to kJoule mol^-1 nm^-n
30 # 'n' is usually 2 (for bonds) or 6 or 12 (for LJ)
31 function kcalpmolpA2kjpmolpnm
(k
, n
) {
39 printf("WARNING: %s\n", s
);
43 function print_warn
() {
45 printf("\nThere were %d warnings\n\n", nwarn
);
48 function fatal_error
(s
) {
49 printf("FATAL ERROR: %s\n", s
);
56 print("amber2gmxff [ffname=<name>] [debug=1] parm##.dat");
58 print("Reads Amber forcefield definition file (parm##.dat) and writes");
59 print("Gromacs forcefield files:");
60 print("ff<name>.atp, ff<name>.itp, ff<name>nb.itp, ff<name>bon.itp");
61 print("Default for <name> is 'amber'.");
63 print("Use 'debug=1' for extremely verbose output.");
68 if ( !ffname
) ffname=
"amber";
69 ffbon =
"ff" ffname
"bon.itp";
70 ffnb =
"ff" ffname
"nb.itp";
71 ffmain=
"ff" ffname
".itp";
72 ffatp =
"ff" ffname
".atp";
73 ffpdihs = ffname
"-dihedrals.txt";
74 ffidihs = ffname
"-impropers.txt";
75 printf("Sending output to: %s, %s and %s\n", ffmain
, ffnb
, ffbon
);
76 printf("; Amber forcefield converted to Gromacs\n") > ffnb
;
77 printf("; from file %s\n", ARGV[1]) > ffnb
;
78 printf("; \n") > ffnb
;
79 printf("; Amber forcefield converted to Gromacs\n") > ffbon
;
80 printf("; from file %s\n", ARGV[1]) > ffbon
;
88 nhb=
0; # H-bonds (10-12)
89 neq=
0; # equivalent 6-12
91 section
[tp_TITL=
0]=
"title";
92 section
[tp_ATOM=
1]=
"atom";
93 section
[tp_HYDR=
2]=
"hydro";
94 section
[tp_BOND=
3]=
"bond";
95 section
[tp_ANGL=
4]=
"angle";
96 section
[tp_PDIH=
5]=
"pdih";
97 section
[tp_IDIH=
6]=
"idih";
98 section
[tp_HB =
7]=
"HB";
99 section
[tp_EQ =
8]=
"eq";
100 section
[tp_LJ =
9]=
"LJ";
104 # keep track of what we are reading, sections are separated by empty line
108 printf("; NOTE: all H-bond (10-12) parameters are Zero\n") > ffnb
;
110 printf("; WARNIGN: Not all H-bond (10-12) parameters are Zero\n") > ffnb
;
111 warning
("Not all H-bond (10-12) parameters are Zero\n");
115 printf("Start reading section: %d = %s\n", type
, section
[type
]);
119 type==tp_TITL
{ # title
121 printf("; %s\n", title
) > ffnb
;
122 printf("; \n") > ffnb
;
123 printf("; %s\n", title
) > ffbon
;
124 printf("; \n") > ffbon
;
129 type==tp_ATOM
{ # atoms
130 if (debug
) printf("; %s\n", $
0);
131 anm =
substr($
0, 1, 2) ; # 1- 2
133 amass
[anm
] =
substr($
0, 4,10)+0; # 4-13
134 atpol
[anm
] =
substr($
0,15,10)+0; # 15-24
135 atcom
[anm
] =
substr($
0,38,length); # rest
137 if (debug
) printf("; '%s' %10g %10g '%s'\n",
138 anm
, amass
[anm
], atpol
[anm
], atcom
[anm
]);
141 type==tp_HYDR
{ # hydrophylic atoms
142 if (debug
) printf("; %s\n", $
0);
148 type
>=tp_BOND
&& type
<=tp_IDIH
{ # bonded interaction
149 ai =
substr($
0, 1, 2) ; # 1- 2
150 aj =
substr($
0, 4, 2) ; # 4- 5
151 ak =
substr($
0, 7, 2) ; # 7- 8
152 al =
substr($
0,10, 2) ; # 10-11
155 type==tp_BOND
{ # bonds
157 printf("\n") > ffbon
;
158 printf("[ bondtypes ]\n") > ffbon
;
159 printf(";%4s %5s %4s %8s %8s\n", "ai", "aj", "ft", "b0", "kb") > ffbon
;
160 printf(";%4s %5s %4s %8s %8s\n","","","", "(nm)", "(kj/mol/nm2)") > ffbon
;
163 if (debug
) printf("; %s\n", $
0);
166 rk
[nb
] = kcalpmolpA2kjpmolpnm
(substr($
0, 6,10), 2); # 6-15
167 req
[nb
] = A2nm
(substr($
0,16,10)); # 16-25
168 bcom
[nb
]=
substr($
0,29,length); # rest
169 printf("%5s %5s %4d %8g %8g ; %s\n",
170 ibt
[nb
], jbt
[nb
], ft
, req
[nb
], rk
[nb
], bcom
[nb
]) > ffbon
;
174 type==tp_ANGL
{ # angles
176 printf("\n") > ffbon
;
177 printf("[ angletypes ]\n") > ffbon
;
178 printf(";%4s %5s %5s %4s %8s %8s\n",
179 "ai", "aj", "ak", "ft", "th0", "cth") > ffbon
;
180 printf(";%4s %5s %5s %4s %8s %8s\n",
181 "", "", "", "", "(degr)", "(kj/mol/rad2)") > ffbon
;
184 if (debug
) printf("; %s\n", $
0);
188 tk
[na
] = kcal2kj
(substr($
0, 9,10)); # 9-18
189 teq
[na
] =
substr($
0,19,10)+0; # 19-28
190 acom
[na
]=
substr($
0,33,length); # rest
191 printf("%5s %5s %5s %4d %8g %8g ; %s\n",
192 itt
[na
],jtt
[na
],ktt
[na
], ft
, teq
[na
], tk
[na
], acom
[na
]) > ffbon
;
196 type==tp_PDIH
|| type==tp_IDIH
{ # proper/improper dihedrals
197 if (type==tp_PDIH
&& np==
0) {
200 printf("\n") > ffbon
;
201 printf("[ dihedraltypes ]\n") > ffbon
;
202 printf(";%4s %5s %5s %8s %8s %5s\n",
203 "aj","ak", "ft","phi0","cp","mult") > ffbon
;
204 printf(";%4s %5s %5s %8s %8s %5s\n",
205 "","", "","(degr)","(kJ/mol/rad)","") > ffbon
;
207 if (type==tp_IDIH
&& ni==
0) {
208 ft=
1; # we'll have to 'abuse' propers to correspond to Amber definition
209 printf("\n") > ffbon
;
210 printf(";%4s %5s %5s %5s %5s %8s %8s %5s\n",
211 "ai","aj","ak","al", "ft","q0","cq","mult") > ffbon
;
212 printf("; WARNING: using Gromacs propers to define Amber impropers\n") > ffbon
;
213 printf("; defining improper parameters for improper types\n") > ffbon
;
214 warning
("using Gromacs propers to define Amber impropers\n");
216 if (debug
) printf("; %s\n", $
0);
217 idivf =
substr($
0,12, 4)+0; # 12-15
218 pk = kcal2kj
(substr($
0,16,15)); # 16-30
219 phase =
substr($
0,31,15)+0; # 31-45
220 pn =
substr($
0,46,15)+0; # 46-50
221 com =
substr($
0,61,length); # rest
233 if ( ai==
"X " && al==
"X " ) {
234 # this is the type of dihedral GROMACS can manage:
235 printf("%5s %5s %5d %8g %8g %5d ; %s\n",
236 aj
,ak
, ft
, phase
, pk
/idivf
, pn
, com
) > ffbon
;
238 printf(" ; WARNING: multiple dihedral types not supperted") > ffbon
;
239 warning
("multiple dihedral types not supperted");
242 # here we need a hack, since we cannot hava a dihedral type
243 # depend on all four atom types in GROMACS...
244 if (bFirstPdihDefine
) {
246 printf("\n") > ffbon
;
247 printf("; defining dihedral parameters for four-atom dependent\n") > ffbon
;
248 printf("; dihedral types, which Gromacs does not handle by default\n") > ffbon
;
250 print ai
, aj
, ak
, al
> ffpdihs
;
251 gsub(" ","_",ai
); gsub(" ","_",aj
); gsub(" ","_",ak
); gsub(" ","_",al
);
252 if (pn
<0 && ninc==
"")
254 printf("#define ad_%2s_%2s_%2s_%2s%1s%1s %8g %8g %5d %8g %8g %5d %s%s\n",
255 ai
,aj
,ak
,al
, ninc?
"_":" ", ninc
,
256 phase
, pk
/idivf
, abs
(pn
), phase
, pk
/idivf
, abs
(pn
),
257 length(com
)?
"; ":"", com
) > ffbon
;
275 # here we need a hack, since we cannot hava a dihedral type
276 # depend on all four atom types in GROMACS...
277 print ai
, aj
, ak
, al
> ffidihs
;
278 gsub(" ","_",ai
); gsub(" ","_",aj
); gsub(" ","_",ak
); gsub(" ","_",al
);
279 printf("#define ai_%2s_%2s_%2s_%2s %8g %8g %5d %8g %8g %5d %s%s\n",
280 ai
,aj
,ak
,al
, pk
,phase
,pn
,pk
,phase
,pn
,
281 length(com
)?
"; ":"",com
) > ffbon
;
285 type==tp_HB
{ # H-bond 10-12 parameters
288 printf("; H-bond params not implemented\n") > ffnb
;
289 warning
("H-bond params not implemented\n");
292 if (debug
) printf("; %s\n", $
0);
293 a=
substr($
0, 11, 10)+0; # 11-20
294 b=
substr($
0, 21, 10)+0; # 21-30
296 printf("; WARNING: non-zero H-bond (10-12) parameters: %s %s %g %g\n",
297 ai
, aj
, a
, b
) > ffnb
;
298 warning
("non-zero H-bond (10-12) parameters:", ai
, aj
, a
, b
);
304 type==tp_EQ
{ # equivalent atom symbols 6-12 parameters
307 printf("; LJ 6-12 equivalent atom symbols\n") > ffnb
;
310 if (debug
) printf("; %s\n", $
0);
311 anm=
substr($
0, 1, 2);
312 for(i=
1; i
<length; i
+=
4) {
314 eqat
[neq
, int
(i
/4)]=
substr($
0, i
, 2);
317 for(i=
0; i
<eqat
[neq
]; i
++) {
318 printf("%3s ", eqat
[neq
, i
]) > ffnb
;
320 printf("(%d)\n", eqat
[neq
]) > ffnb
;
324 type==tp_LJ
{ # 6-12 potential parameters
332 printf("; Define LJ 6-12 parameter types:\n") > ffnb
;
334 if (debug
) printf("; %s\n", $
0);
335 ljt
[nlj
] =
substr($
0, 3, 2) ; # 3- 4
336 p1 =
substr($
0,11,20)+0; # 11-20
337 p2 =
substr($
0,21,30)+0; # 21-30
339 p = kcalpmolpA2kjpmolpnm
(p2
, 6);
340 p2 = kcalpmolpA2kjpmolpnm
(p1
, 12);
347 p3 =
substr($
0,31,40)+0; # 31-40
348 if (debug
) printf("; '%s' %10g %10g %10g\n",
349 ljt
[nlj
], p1
, p2
, p3
);
350 printf("#define alj_%s %10g %10g\n", ljt
[nlj
], p1
,p2
) > ffnb
;
357 # write forcefield main ff<name>.itp file
358 # we do that here so we have the title...
359 printf("#define _FF_%s\n", toupper(ffname
)) > ffmain
;
360 printf("; Amber forcefield converted to Gromacs\n") > ffmain
;
361 printf("; from file %s\n", ARGV[1]) > ffmain
;
362 printf("; \n") > ffmain
;
363 printf("; %s\n", title
) > ffmain
;
364 printf("\n") > ffmain
;
365 printf("[ defaults ]\n") > ffmain
;
366 if (kindnb==
"AC") cr=
1;
367 if (kindnb==
"RE") cr=
2;
368 printf("; %8s %10s %10s %10s %10s\n",
369 "nbfunc", "comb-rule", "gen-pairs", "fudgeLJ", "fudgeQQ") > ffmain
;
370 printf("%10d %10d %10s %10.3g %10.3g\n", 1, cr
, "no", 1.0, 1.0) > ffmain
;
371 printf("\n") > ffmain
;
372 printf("#include \"%s\"\n", ffnb
) > ffmain
;
373 printf("#include \"%s\"\n", ffbon
) > ffmain
;
375 # expand LJ parameters (using 'equivalent atoms')
376 for(i=
0; i
<neq
; i
++) {
378 if (debug
) print i
, eqnm
, eqat
[i
];
379 for(j=
1; j
<eqat
[i
]; j
++)
380 atlj
[eqat
[i
, j
]] = eqnm
;
382 for(i=
0; i
<nat
; i
++) {
384 if (!atlj
[anm
]) atlj
[anm
]=anm
;
385 if (debug
) print i
, anm
, atlj
[anm
];
388 printf("[ atomtypes ]\n") > ffnb
;
390 printf(";%4s%10s %4s %2s %-10s\n",
391 "name", "mass", "q", "tp", "c6/c12") > ffnb
;
393 printf(";%4s%10s %4s %2s %-10s\n",
394 "name", "mass", "q", "tp", "sigma/epsilon") > ffnb
;
397 for(i=
0; i
<nat
; i
++) {
399 printf("%4s %10.6g %4.2g %2s alj_%-3s ; %s\n",
400 anm
, amass
[anm
], q
, ptype
, atlj
[anm
], atcom
[anm
]) > ffnb
;
402 printf("%4s %10.6g ; %s\n", anm
, amass
[anm
], atcom
[anm
]) > ffatp
;
407 printf("# atoms: %s\n", nat
);
408 printf("# bonds: %s\n", nb
);
409 printf("# angles: %s\n", na
);
410 printf("# propers: %s\n", np
);
411 printf("# impropers: %s\n", ni
);
412 printf("# H-bonds (10-12): %s\n", nhb
);
413 printf("# equivalent 6-12: %s\n", neq
);
414 printf("# LJ (6-12): %s\n", nlj
);
417 printf("; Found:\n") > ffnb
;
418 printf("; # atoms: %s\n", nat
) > ffnb
;
419 printf("; # H-bonds (10-12): %s\n", nhb
) > ffnb
;
420 printf("; # equivalent 6-12: %s\n", neq
) > ffnb
;
421 printf("; # LJ (6-12): %s\n", nlj
) > ffnb
;
422 printf("\n") > ffbon
;
423 printf("; Found:\n") > ffbon
;
424 printf("; # bonds: %s\n", nb
) > ffbon
;
425 printf("; # angles: %s\n", na
) > ffbon
;
426 printf("; # propers: %s\n", np
) > ffbon
;
427 printf("; # impropers: %s\n", ni
) > ffbon
;