changed reading hint
[gromacs/adressmacs.git] / src / local / mkyaw.c
blob19278414522ddb77ec097ee4628055620beb5573
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_mkyaw_c = "$Id$";
31 #include <math.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include "pdbio.h"
35 #include "confio.h"
36 #include "symtab.h"
37 #include "smalloc.h"
38 #include "symtab.h"
39 #include "macros.h"
40 #include "copyrite.h"
41 #include "statutil.h"
42 #include "string2.h"
43 #include "strdb.h"
44 #include "rdgroup.h"
45 #include "vec.h"
46 #include "typedefs.h"
47 #include "gbutil.h"
48 #include "strdb.h"
49 #include "rdgroup.h"
50 #include "physics.h"
51 #include "atomprop.h"
53 void copy_atom(t_symtab *tab,t_atoms *a1,int i1,t_atoms *a2,int i2,
54 rvec xin[],rvec xout[],rvec vin[],rvec vout[])
56 a2->atom[i2] = a1->atom[i1];
57 a2->atomname[i2] = put_symtab(tab,*a1->atomname[i1]);
58 a2->resname[a2->atom[i2].resnr] =
59 put_symtab(tab,*a1->resname[a1->atom[i1].resnr]);
60 copy_rvec(xin[i1],xout[i2]);
61 copy_rvec(vin[i1],vout[i2]);
64 int main(int argc, char *argv[])
66 t_symtab tab;
67 static char *desc[] = {
68 "mkyaw adds to an existing conf file for every OW atom an DW and SW",
69 "after the hydrogens (or the inverse with the -back option)."
71 static bool bBack = FALSE;
72 t_pargs pa[] = {
73 { "-back", FALSE, etBOOL, &bBack,
74 "Remove SW and DW" }
76 #define NPA asize(pa)
77 t_filenm fnm[] = {
78 { efSTX, "-f", NULL, ffREAD },
79 { efSTO, "-o", NULL, ffWRITE }
81 #define NFILE asize(fnm)
82 int i,iout,now,natom;
83 rvec *xin,*vin,*xout,*vout;
84 matrix box;
85 t_atoms atoms,aout;
86 char *infile,*outfile,title[256];
88 CopyRight(stderr,argv[0]);
89 parse_common_args(&argc,argv,0,FALSE,NFILE,fnm,NPA,pa,
90 asize(desc),desc,0,NULL);
92 infile = ftp2fn(efSTX,NFILE,fnm);
93 outfile = ftp2fn(efSTO,NFILE,fnm);
95 get_stx_coordnum(infile,&natom);
96 init_t_atoms(&atoms,natom,TRUE);
97 snew(xin,natom);
98 snew(vin,natom);
99 read_stx_conf(infile,title,&atoms,xin,vin,box);
100 printf("Read %d atoms\n",atoms.nr);
101 open_symtab(&tab);
102 if (!bBack) {
103 now = 0;
104 for(i=0; (i<natom-2); ) {
105 if ((strstr(*atoms.atomname[i],"OW") != NULL) &&
106 (strstr(*atoms.atomname[i+1],"HW") != NULL) &&
107 (strstr(*atoms.atomname[i+2],"HW") != NULL)) {
108 now++;
109 i+=3;
111 else
112 i++;
114 fprintf(stderr,"There are %d water molecules\n",now);
115 init_t_atoms(&aout,natom+2*now,TRUE);
116 snew(xout,natom+2*now);
117 snew(vout,natom+2*now);
118 for(i=iout=0; (i<natom); i++) {
119 copy_atom(&tab,&atoms,i,&aout,iout,xin,xout,vin,vout);
120 iout++;
121 if (i >= 2) {
122 if (strstr(*atoms.atomname[i-2],"OW") != NULL) {
123 copy_atom(&tab,&atoms,i-2,&aout,iout,xin,xout,vin,vout);
124 aout.atomname[iout] = put_symtab(&tab,"DW");
125 iout++;
126 copy_atom(&tab,&atoms,i-2,&aout,iout,xin,xout,vin,vout);
127 aout.atomname[iout] = put_symtab(&tab,"SW");
128 iout++;
132 close_symtab(&tab);
133 fprintf(stderr,"iout = %d\n",iout);
134 write_sto_conf(outfile,"Gravity Sucks",&aout,xout,vout,box);
137 thanx(stdout);
139 return 0;