[gmx-users] renumber topology (.top) file

Anton Feenstra feenstra at chem.vu.nl
Thu Mar 20 12:03:32 CET 2003


Hi all,


I've just written a short awk script that reads a topology file (.top) and
prints out a new topology file (.top). All atoms in the new topology will 
be re-numbered consecutively, and all interaction definitions will be 
re-numbered accordingly. Atom 'numbers' in the input file can be any text 
string. This alows you to add e.g. hydrogen atom with number '2b' and then
add a bond from '2' to '2b', or to swap two atoms.

I've uploaded the file to the contributions page (www.gromacs.org/contributions),
but since it's less than 2k, I'll attach it to this mail, too.

-- 
Groetjes,

Anton
 _____________ _______________________________________________________
|             |                                                       |
|  _   _  ___,| K. Anton Feenstra                                     |
| / \ / \'| | | Dept. of Pharmacochem. - Vrije Universiteit Amsterdam |
|(   |   )| | | De Boelelaan 1083 - 1081 HV Amsterdam - Netherlands   |
| \_/ \_/ | | | Room P275  Tel: +31 20 44 47608  Fax: +31 20 44 47610 |
|             | Feenstra at chem.vu.nl - www.chem.vu.nl/~feenstra/       |
|             | "You Can Always Go On Ricky Lake" (Offspring)         |
|_____________|_______________________________________________________|
-------------- next part --------------
#!/usr/bin/awk -f

BEGIN {
  nratoms["bonds"]                  = 2;
  nratoms["angles"]                 = 3;
  nratoms["dihedrals"]              = 4;
  nratoms["pairs"]                  = 2;
  nratoms["dummies2"]               = 3;
  nratoms["dummies3"]               = 4;
  nratoms["dummies4"]               = 5;
  nratoms["exclusions"]             = -1;
  nratoms["constraints"]            = 2;
  nratoms["settles"]                = 1;
  nratoms["position_restraints"]    = 1;
  nratoms["angle_restraints"]       = 4;
  nratoms["angle_restraints_z"]     = 2;
  nratoms["distance_restraints"]    = 2;
  nratoms["orientation_restraints"] = 2;
  anr = 1;
  nerror=0;
}

/^[ \t]*[;#]/ || !NF { 
  print;
  next;
}

/^[ \t]*\[/ && /\][ \t]*$/ {
  block = $0; 
  sub("^[ \t]*\[[ \t]*","",block);
  sub("[ \t]*\][ \t]*$","",block);
  printf("[ %s ]\n", block);
  next;
}

block=="atoms" {
  label = $1;
  if (atomnr[label]) {
    printf("; ERROR: duplicate atom label '%s' for atom #%d (already used for atom #%d)\n", label, anr, atomnr[label]);
    nerror++;
  }
  printf ("%6d %-6s %6d %-6s %-6s %-6d %10g %10g\n", 
	  anr, $2, $3, $4, $5, $6, $7, $8);
  atomnr[label] = anr;
  anr++;
  next;
}
#     1    CH3      1    OCT     C1      1          0     15.035
#    1     2     3     4     1    gd_17

{
  nrat = nratoms[block];
  if (nrat==-1)
    nrat = NF;
  for(i=1; i<=nrat; i++) {
    anr = atomnr[$i]
    if ( !anr ) {
      printf("; ERROR: undefined atom label '%s'\n", $i);
    nerror++;
      anr = -1;
    }
    $i = anr;
  }
  for(i=1; i<=NF; i++)
    printf(" %5s", $i);
  printf("\n");
}

{ next; }

END {
  if (nerror) {
    printf("\n");
    printf("; ERROR: there were %d errors\n", nerror);
    printf("\n");
  }
  exit nerror;
}

# last line


More information about the gromacs.org_gmx-users mailing list