[gmx-users] Amber run parameters conversion
Anton Feenstra
feenstra at chem.vu.nl
Wed Dec 4 13:32:12 CET 2002
Hi All,
Seeing the interest many people express for Amber/Gromacs conversions,
I thought I might share my latest script with you. It reads an Amber
mdin file (run parameters) and write a Gromacs .mdp file.
It is not complete; there is no way to convert some of the more elaborate
Amber features (that are nearly scripting languages) to Gromacs .mdp file.
It also doesn't handles freezing or restraining groups. It doesn warn
for most things it doesn't know about. Output is pretty verbose.
Since it's *really* small (12k) I'll attach it to this mail. If people
somewhat agree that it isn't useless I'll put it on 'contributions', too.
--
Groetjes,
Anton
________ ___________________________________________________________
| | Anton Feenstra |
| . | Dept. of Pharmacochemistry - Vrije Universiteit Amsterdam |
| |---- | De Boelelaan 1083 - 1081 HV Amsterdam - The Netherlands |
| |---- | Tel: +31 20 44 47608 - Fax: +31 20 44 47610 |
| ' __ | Feenstra at chem.vu.nl - http://www.chem.vu.nl/afdelingen/FAR|
| / \ |-----------------------------------------------------------|
| ( ) | Dept. of Biophysical Chemistry - University of Groningen |
| \__/ | Nijenborgh 4 - 9747 AG Groningen - The Netherlands |
| __ | Tel +31 50 363 4327 - Fax +31 50 363 4800 |
| / \ | K.A.Feenstra at chem.rug.nl - http://md.chem.rug.nl/~anton |
| ( ) |-----------------------------------------------------------|
| \__/ | "I Can't Shake It" (Dinosaur Jr) |
|________|___________________________________________________________|
-------------- next part --------------
#!/usr/bin/awk -f
# Amber2gmx 1.0
# Reads Amber parameter file (mdin) and converts to Gromacs .mdp file
# Version 1.0
# Copyright (c) 2002
# Anton Feenstra - Vrije Universiteit Amsterdam - The Netherlands
# strings:
function strip_space(s)
{
gsub(" ","",s);
return s;
}
function fix_newline(m,s)
{
gsub("\n","\n"s,m);
return m;
}
function outfile(fnm, n)
{
gsub("\\.in","",fnm);
if(n)
fnm = fnm n;
fnm = fnm".mdp";
return fnm;
}
# message:
function error(m)
{
nerr++;
print "ERROR: "fix_newline(m," ")".";
}
function warning(m)
{
nwarn++;
print "WARNING: "fix_newline(m," ")".";
}
function unimpl(m)
{
warning("Unimplemented feature: "m);
}
function note(m)
{
nnote++;
print "NOTE: "fix_newline(m," ")".";
}
# specific messages:
function unsupported_parameter(p,v,m)
{
warning("unsupported parameter '"p"' ("v", "m")");
}
function ignore_parameter(p,v,m)
{
note("ignoring parameter '"p"' ("v", "m")");
}
function set_fudge(p,v)
{
warning("in the '[ defaults ]' section of your .top file, \n"\
"set parameter 'Fudge"p"' to '"1/v"'");
}
function unsupported_parameter_value(p,v,m)
{
error("unsupported value '"v"' for '"p"' ("m")");
}
# maths:
function min(a,b)
{
return a<b?a:b;
}
function max(a,b)
{
return a>b?a:b;
}
# parsing:
function set_parameter(p, v)
{
# keep track of settings:
if (parameter_set[p]) warning("Duplicate parameter '"p"' ("v")");
parameter_set[p]=1;
# general flags
if (p=="timlim") ignore_parameter(p,v,"Time Limit in seconds");
else if (p=="imin") {
if (v==0) parm["integrator"] = "md";
else if (v==1) parm["integrator"] = "steep";
else unsupported_parameter_value(p,v);
}
else if (p=="nmropt") {
if (v!=0) unsupported_parameter_value(p,v,"NMR optimizations");
}
else if (p=="ntx") ignore_parameter(p,v,"Read coordinates");
else if (p=="irest") ignore_parameter(p,v,"Restart flag");
else if (p=="ntrx" ||
# output
p=="ntxo" ||
p=="ioutfm") ignore_parameter(p,v,"Coordinate format");
else if (p=="ntpr") parm["nstlog"] = v;
else if (p=="ntwr") parm["nstxout"] = parm["nstvout"] = v;
else if (p=="ntwx") parm["nstxtcout"] = v;
else if (p=="ntwv") {
if (parm["nstvout"]==0) parm["nstvout"] = v;
else parm["nstvout"] = min(parm["nstvout"],v);
}
else if (p=="ntwe") parm["nstenergy"] = v;
else if (p=="ntwxm" ||
p=="ntwvm" ||
p=="ntwem") ignore_parameter(p,v,"Output steps limit");
else if (p=="ntwprt") {
if (v<0) warning("Should write only solute atoms");
else if (v>0) warning("Should write only atoms 1-"v);
}
# potential function
else if (p=="ntf") ignore_parameter(p,v,"Force evaluation");
else if (p=="ntb") { parm["pbc"] = "xyz";
if (v==0) parm["pbc"] = "none";
else if (v==1) parm["Pcoupl"] = "No";
else if (v==2) parm["Pcoupl"] = "Yes";
else unsupported_parameter_value(p,v);
}
else if (p=="idiel") {
if (v!=1) unsupported_parameter_value(p,v,"Dielectric function");
}
else if (p=="dielc") parm["epsilon_r"] = v;
else if (p=="cut") parm["rcoulomb"] = parm["rvwd"] = v;
else if (p=="ntnb") {
if (v==0) parm["nstlist"] = 0;
else if (v==1) parm["nstlist"] = 25;
else unsupported_parameter_value(p,v);
}
else if (p=="nsnb") parm["nstlist"] = v;
else if (p=="ntid") unsupported_parameter(p,v,"Water pairlist");
else if (p=="scnb") set_fudge("LJ",v);
else if (p=="scee") set_fudge("QQ",v);
else if (p=="cut2nd") parm["rlist"] = v;
else if (p=="ichdna") {
if (v!=0) unsupported_parameter_value(p,v,"(Un)Charge end hydrogens");
}
# soft repulsion
else if (p=="isftrp") {
if (v!=0) unsupported_parameter_value(p,v,"Soft repulsions");
}
else if (p=="rwell") unsupported_parameter(p,v,"Soft repulsions");
# polarizability
else if (p=="ipol") {
if (v!=0) unsupported_parameter_value(p,v,"Polarizability");
}
else if (p=="n3b"||
p=="nion") unsupported_parameter(p,v,"");
# freeze and posre
else if (p=="ibelly") freeze = v;
else if (p=="ntr") posre = v;
# EM (and nrun and nstlim from MD section below)
else if (p=="maxcyc" ||
p=="ncyc"||
p=="nrun"||
p=="nstlim") {
gp = "nsteps";
if ( !parm[gp] ) parm[gp] = v; else parm[gp] *= v;
note("Parameter '"p"' ("v") incorporated into '"gp"' ("parm[gp] ")");
}
else if (p=="ntmin") {
if (v==0) if (parm["integrator"]!="md") parm["integrator"]="cg";
else if (v==1) unsupported_parameter_value(p,v);
else if (v==2) if (parm["integrator"]!="md") parm["integrator"]="steep";
else unsupported_parameter_value(p,v);
}
else if (p=="dx0") parm["emstep"] = v*A2nm;
else if (p=="dxm") ignore_parameter(p,v,"");
else if (p=="drms")
warning("Parameter '"p"' ("v", RMS of gradient, kcal/mol A)\n"\
"should be converted to 'emtol' (Max force, kJ/mol nm)");
# MD (nrun and nstlim are in EM section above)
else if (p=="ndfmin") ignore_parameter(p,v,"");
else if (p=="ntcm") {
if (v==0) parm["nstcomm"] = 0;
else if (v==1) parm["nstcomm"] = parm["nsteps"]*10;
else unsupported_parameter_value(p,v);
}
else if (p=="nscm") parm["nstcomm"] = v;
else if (p=="init") {
if (v==3) parm["gen_vel"] = "yes";
else if (v==4) parm["gen_vel"] = "no";
else unsupported_parameter_value(p,v);
}
else if (p=="t") parm["t_init"] = v;
else if (p=="dt") parm["dt"] = v;
# Temperature
else if (p=="temp0") reft = v;
else if (p=="tempi") tempi = v;
else if (p=="heat") heat = v;
else if (p=="ig") parm["gen_seed"] = v;
else if (p=="ntt") {
if ( v==0 || v==1 || v==5 ) {
if (v==0) parm["tcoupl"] = "no";
if (v==1 || v==5) parm["tcoupl"] = "berendsen";
if (v==1) {
parm["ref_t"] = "reft";
parm["tau_t"] = "tautp";
}
if (v==2 || v==5) {
parm["tc_grps"] = "Solute Solvent";
parm["ref_t"] = "reft reft";
}
if (v==2) parm["tau_t"] = "tautp 0";
if (v==5) parm["tau_t"] = "tautp tauts";
}
else
unsupported_parameter_value(p,v);
}
else if (p=="isolvp") ignore_parameter(p,v,"Last solute atom");
else if (p=="dtemp") unsupported_parameter(p,v,"");
else if (p=="tautp") tautp = v;
else if (p=="tauts") tauts = v;
else if (p=="vlimit") {
if (v!=0) unsupported_parameter_value(p,v,"Velocity Limit");
}
# 'peacs'
else if (p=="tauv0") {
if (v!=0) unsupported_parameter_value(p,v,"PEACS temperature algorithm");
}
else if (p=="tauv") ignore_parameter(p,v,"");
else if (p=="vzero") ignore_parameter(p,v,"");
# pressure
else if (p=="ntp") {
if (v==0) parm["pcoupl"] = "no";
else if (v==1) parm["pcoupl"] = "berendsen";
else if (v==2) {
parm["pcoupl"] = "berendsen";
parm["pcoupltype"] = "isotropic";
}
else unsupported_parameter_value(p,v);
}
else if (p=="comp") parm["compressibility"] = v*1e-6;
else if (p=="taup") parm["tau_p"] = v;
else if (p=="npscal") {
if (v!=0) unsupported_parameter_value(p,v,"");
}
# shake
else if (p=="ntc") {
if (v==0) parm["constraints"] = "none";
else if (v==1) parm["constraints"] = "hbonds";
else if (v==2) parm["constraints"] = "all-bonds";
else unsupported_parameter_value(p,v);
}
else if (p=="tol") parm["shake_tol"] = v;
# special water treatment
else if (p=="imgslt") {
if (v!=0) unsupported_parameter_value(p,v,"Solvent imaging");
}
else if (p=="iftres") {
if (v!=1) unsupported_parameter_value(p,v,"Intermolecular interactions");
}
else if (p=="jfastw"||
p=="watnam"||
p=="owtnam"||
p=="hwtnam1"||
p=="hwtnam2") ignore_parameter(p,v,"Fast water");
# pme
else if (p=="iewald") {
if (v==0) parm["coulombtype"] = "cut-off";
else if (v==1) {
parm["coulombtype"] = "PME";
warning("Special input parameters for PME (fftgrid) not converted");
}
else unsupported_parameter_value(p,v);
}
else if (p=="") parm[""] = v;
else if (p=="") {
if (v==0) parm[""] = v;
else if (v==1) parm[""] = v;
else unsupported_parameter_value(p,v);
}
else if (p=="") ignore_parameter(p,v,"");
else if (p=="") unsupported_parameter(p,v,"");
else if (p=="" ||
p=="") ignore_parameter(p,v,"");
else if (p=="") {
if (v!=0) unsupported_parameter_value(p,v,"");
}
else if (p=="") {
gp = "";
if ( !parm[gp] ) parm[gp] = v; else parm[gp] *= v;
note("Parameter '"p"' ("v") incorporated into '"gp"' ("parm[gp] ")");
}
else
error("unknown parameter '"p"' ("v")");
}
function post_process()
{
if (freeze) unimpl("Freeze groups");
if (posre) unimpl("Position restraints");
parm["gen_temp"] = tempi;
if (heat)
parm["gen_temp"] *= heat;
gsub("reft",reft,parm["ref_t"]);
gsub("tauts",tauts,parm["tau_t"]);
gsub("tautp",tautp,parm["tau_t"]);
}
function output(outfile)
{
print "Writing "outfile".";
print ";" > outfile;
print "; This file was converted by "PROGRAM" "VER" from "FILENAME > outfile;
print "; Copyright (c) 2002 Anton Feenstra" > outfile;
print ";" > outfile;
print "; parameters will not always be the verbatim translation" > outfile;
print "; CHECK PARAMETERS CAREFULLY BEFORE RUNNING!" > outfile;
print "; Amber default values are not considered" > outfile;
print "; Check mdout.mdp (from grompp) for Gromacs default values" > outfile;
print ";" > outfile;
print "; There were", nnote, "notes,", nwarn, "warnings and",
nerr, "errors during conversion" > outfile;
print ";" > outfile;
for(i in parm)
printf("%-20s = %s\n", i, parm[i]) > outfile;
}
function clear_parms()
{
for(i in parameter_set)
delete parameter_set[i];
for(i in parm)
delete parm[i];
}
# initialize:
BEGIN {
VER = "1.0";
PROGRAM = "amber2mdp"
print "This is "PROGRAM" Version "VER".";
print "Copyright (c) 2002 Anton Feenstra";
print "Anton Feenstra - Vrije Universiteit Amsterdam - The Netherlands";
print "";
print "Reads Amber parameter file (mdin) and converts to Gromacs .mdp file";
print "";
ncntrl = 0;
nwarn = 0;
nerr = 0;
# conversion parameters:
A2nm = 0.1;
}
FNR == 1 && NR != 1 {
print "There were", nnote, "notes, ", nwarn, "warnings and", nerr, "errors";
terr += nerr;
twarn += nwarn;
tnote += nnote;
nerr = 0;
nwarn = 0;
nnote = 0;
nctrl = 0;
}
# parse parameter block
! /^#/ {
gsub(" *= *","=");
gsub(", *"," ");
np = split ($0, parms, " ");
# print np, $0;
for(i=1; i<=np; i++) {
if ( substr(parms[i],1,1) == "&" ) {
pblock = block;
block = substr(parms[i],2);
if (block == "cntrl") {
print "Start of control block";
cntrl = 1;
}
else if (block == "end") {
if (ignore)
printf(")\n");
else if (cntrl) {
print "End of control block";
post_process();
output(outfile(FILENAME,nctrl));
clear_parms();
nctrl++;
}
else
print "End of block ("pblock").";
ignore = 0;
cntrl=0;
}
else {
printf("Skipping unknown block "block" (");
ignore = 1;
}
}
else if (ignore)
printf(" "parms[i]);
else if (cntrl) {
if (split(parms[i], words, " *= *")!=2)
error("wrong format: "parms[i]);
tolower(words[1]); tolower(words[2]);
set_parameter(words[1],words[2]);
}
else {
print "Skipping unknown line: "$0;
next;
}
}
}
# finalize
END {
print "There were", nnote, "notes, ", nwarn, "warnings and", nerr, "errors";
if (tnote || twarn || terr) {
print "";
print "In total:", tnote, "notes, ", twarn, "warnings and", terr, "errors";
}
}
#last line
More information about the gromacs.org_gmx-users
mailing list