Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / src / contrib / mkyaw.c
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 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * Gromacs Runs On Most of All Computer Systems
35  */
36 static char *SRCID_mkyaw_c = "$Id$";
37 #include <math.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include "assert.h"
41 #include "pdbio.h"
42 #include "confio.h"
43 #include "symtab.h"
44 #include "smalloc.h"
45 #include "symtab.h"
46 #include "macros.h"
47 #include "copyrite.h"
48 #include "statutil.h"
49 #include "string2.h"
50 #include "strdb.h"
51 #include "rdgroup.h"
52 #include "vec.h"
53 #include "typedefs.h"
54 #include "gbutil.h"
55 #include "strdb.h"
56 #include "rdgroup.h"
57 #include "physics.h"
58 #include "atomprop.h"
59
60 void copy_atom(t_symtab *tab,t_atoms *a1,int i1,t_atoms *a2,int i2,
61                rvec xin[],rvec xout[],rvec vin[],rvec vout[])
62 {
63   a2->atom[i2]     = a1->atom[i1];
64   a2->atomname[i2] = put_symtab(tab,*a1->atomname[i1]);
65   a2->resname[a2->atom[i2].resnr] =
66     put_symtab(tab,*a1->resname[a1->atom[i1].resnr]);
67   copy_rvec(xin[i1],xout[i2]);
68   copy_rvec(vin[i1],vout[i2]);
69 }
70
71 int main(int argc, char *argv[])
72 {
73   t_symtab tab;
74   static char *desc[] = {
75     "mkyaw adds to an existing conf file for every OW atom an DW and SW",
76     "after the hydrogens (or the inverse with the -back option)."
77   };
78   static bool bBack=FALSE,bDW=TRUE;
79   t_pargs pa[] = {
80     { "-back",   FALSE, etBOOL, &bBack, 
81       "Remove SW and DW" },
82     { "-dw",     FALSE, etBOOL, &bDW,
83       "Use both dummy and shell" }
84   };
85 #define NPA asize(pa)
86   t_filenm fnm[] = {
87     { efSTX, "-f", NULL, ffREAD },
88     { efSTO, "-o", NULL, ffWRITE }
89   };
90 #define NFILE asize(fnm)
91   int  i,iout,now,natom;
92   rvec *xin,*vin,*xout,*vout;
93   matrix box;
94   t_atoms atoms,aout;
95   char *infile,*outfile,title[256];
96   
97   CopyRight(stderr,argv[0]);
98   parse_common_args(&argc,argv,0,FALSE,NFILE,fnm,NPA,pa,
99                     asize(desc),desc,0,NULL);
100
101   infile  = ftp2fn(efSTX,NFILE,fnm);
102   outfile = ftp2fn(efSTO,NFILE,fnm);
103   
104   get_stx_coordnum(infile,&natom);
105   init_t_atoms(&atoms,natom,TRUE);
106   snew(xin,natom);
107   snew(vin,natom);
108   read_stx_conf(infile,title,&atoms,xin,vin,box);
109   printf("Read %d atoms\n",atoms.nr); 
110   open_symtab(&tab);
111   if (!bBack) {
112     now = 0;
113     for(i=0; (i<natom-2); ) {
114       if ((strstr(*atoms.atomname[i],"OW")   != NULL) &&
115           (strstr(*atoms.atomname[i+1],"HW") != NULL) &&
116           (strstr(*atoms.atomname[i+2],"HW") != NULL)) {
117         now++;
118         i+=3;
119       }
120       else
121         i++;
122     }
123     fprintf(stderr,"There are %d water molecules\n",now);
124     init_t_atoms(&aout,natom+2*now,TRUE);
125     snew(xout,natom+2*now);
126     snew(vout,natom+2*now);
127     for(i=iout=0; (i<natom); i++) {
128       copy_atom(&tab,&atoms,i,&aout,iout,xin,xout,vin,vout);
129       iout++;
130       if (i >= 2) {
131         if (strstr(*atoms.atomname[i-2],"OW") != NULL) {
132           if (bDW) {
133             copy_atom(&tab,&atoms,i-2,&aout,iout,xin,xout,vin,vout);
134             aout.atomname[iout] = put_symtab(&tab,"DW");
135             iout++;
136           }
137           copy_atom(&tab,&atoms,i-2,&aout,iout,xin,xout,vin,vout);
138           aout.atomname[iout] = put_symtab(&tab,"SW");
139           iout++;
140         }
141       }
142     }
143     aout.nr = iout;
144     close_symtab(&tab);
145     fprintf(stderr,"iout = %d\n",iout);
146     write_sto_conf(outfile,"Gravity Sucks",&aout,xout,vout,box); 
147   }
148
149   thanx(stderr);
150   
151   return 0;
152 }