Merge branch 'master' of git://git.gromacs.org/gromacs
[gromacs/adressmacs.git] / src / kernel / rtp2xml.c
blob86ff101c6f4f29bf8568c5df2b41a4b011e60878
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include <time.h>
40 #include <ctype.h>
41 #include "sysstuff.h"
42 #include "typedefs.h"
43 #include "smalloc.h"
44 #include "copyrite.h"
45 #include "string2.h"
46 #include "confio.h"
47 #include "symtab.h"
48 #include "vec.h"
49 #include "statutil.h"
50 #include "futil.h"
51 #include "gmx_fatal.h"
52 #include "pdbio.h"
53 #include "toputil.h"
54 #include "h_db.h"
55 #include "physics.h"
56 #include "pgutil.h"
57 #include "calch.h"
58 #include "resall.h"
59 #include "pdb2top.h"
60 #include "ter_db.h"
61 #include "strdb.h"
62 #include "txtdump.h"
63 #include "gbutil.h"
64 #include "genhydro.h"
65 #include "readinp.h"
66 #include "xlate.h"
67 #include "specbond.h"
68 #include "index.h"
69 #include "hizzie.h"
71 static void dump_res(FILE *fp,int indent,t_restp *restp,int nah,
72 t_hackblock *ah,int nres_long,char **res_long)
74 char *rtype[ebtsNR] = { "rbond", "rangle", "rdihedral", "rimproper" };
75 int ntype[ebtsNR] = { 2, 3, 4, 4 };
76 int i,j,k,nn;
77 char *tmp,descr[128];
79 descr[0] = '\0';
80 for(nn=0; (nn < nres_long) && (strstr(res_long[nn],restp->resname) == NULL); nn++)
82 if (nn < nres_long) {
83 tmp = res_long[nn] + strlen(restp->resname);
84 while (*tmp && isspace(*tmp)) {
85 tmp++;
87 if (strlen(tmp) > 0)
88 strcpy(descr,tmp);
91 pr_indent(fp,indent);
92 fprintf(fp,"<residue restype=\"%s\" longname=\"%s\">\n",restp->resname,descr);
93 indent += 2;
95 for(i=0; (i<restp->natom); i++) {
96 pr_indent(fp,indent);
97 fprintf(fp,"<ratom name=\"%s\">\n",*restp->atomname[i]);
99 for(i=0; (i<ebtsNR); i++) {
100 for(j=0; (j<restp->rb[i].nb); j++) {
101 pr_indent(fp,indent);
102 fprintf(fp,"<%s",rtype[i]);
103 for(k=0; (k<ntype[i]); k++)
104 fprintf(fp," a%d=\"%s\"",k+1,restp->rb[i].b[j].a[k]);
105 fprintf(fp,"/>\n");
108 for(i=0; (i<nah); i++) {
109 if (strcmp(restp->resname,ah[i].name) == 0) {
110 for(j=0; (j<ah[i].nhack); j++) {
111 pr_indent(fp,indent);
112 if ((ah[i].hack[j].a[0][0] == 'O') || (ah[i].hack[j].a[0][0] == 'N'))
113 fprintf(fp,"<raddh hclass=\"polar\" ");
114 else
115 fprintf(fp,"<raddh hclass=\"aliphatic\"");
116 fprintf(fp," addgeom=\"%d\" addnum=\"%d\"",
117 ah[i].hack[j].tp,ah[i].hack[j].nr);
118 fprintf(fp," addto=\"%s",ah[i].hack[j].a[0]);
119 for(k=1; ((k <= 3) && (ah[i].hack[j].a[k] > 0)); k++)
120 fprintf(fp," %s",ah[i].hack[j].a[k]);
121 fprintf(fp,"\"/>\n");
123 break;
126 indent -= 2;
127 pr_indent(fp,indent);
128 fprintf(fp,"</residue>\n\n");
131 static void dump_hack_add(FILE *fp,int indent,t_hack *hack)
133 pr_indent(fp,indent);
134 fprintf(fp,"<modadd addname=\"%s\" addgeom=\"%d\" addto=\"%s %s %s\"/>\n",
135 hack->nname,hack->tp,hack->a[0],hack->a[1],hack->a[2]);
138 static void dump_hack_del(FILE *fp,int indent,t_hack *hack)
140 pr_indent(fp,indent);
141 fprintf(fp,"<moddelete delname=\"%s\"/>\n",hack->oname);
144 static void dump_hack_rep(FILE *fp,int indent,t_hack *hack)
146 pr_indent(fp,indent);
147 fprintf(fp,"<modreplace oldname=\"%s\" newname=\"%s\"/>\n",hack->oname,hack->nname);
150 static void dump_mod(FILE *fp,int indent,t_hackblock *tdb,t_atomtype *atype)
152 int i,j,k;
154 pr_indent(fp,indent);
155 fprintf(fp,"<moddef modtype=\"%s\"\n",tdb->name);
156 indent += 2;
157 for(j=0; (j<tdb->nhack); j++) {
158 if (tdb->hack[j].oname == NULL)
159 dump_hack_add(fp,indent,&(tdb->hack[j]));
160 else if (tdb->hack[j].nname == NULL)
161 dump_hack_del(fp,indent,&(tdb->hack[j]));
162 else
163 dump_hack_rep(fp,indent,&(tdb->hack[j]));
165 indent -= 2;
166 pr_indent(fp,indent);
167 fprintf(fp,"</moddef>\n\n");
170 static void dump_mods(FILE *fp,int indent,
171 int n,t_hackblock tdb[],t_atomtype *atype)
173 int i,j;
175 for(i=0; (i<n); i++)
176 dump_mod(fp,indent,&(tdb[i]),atype);
179 static void do_specbonds(FILE *fp,int indent)
181 t_specbond *sb;
182 int i,nsb;
184 pr_indent(fp,indent);
185 fprintf(fp,"<linkdef linktype=\"peptide\" restype=\"* *\" atomprev=\"C\" atomnext=\"N\" refdist=\"0.133\"/>\n");
186 sb = get_specbonds(&nsb);
187 for(i=0; (i<nsb); i++) {
188 pr_indent(fp,indent);
189 fprintf(fp,"<linkdef linktype=\"unknown\" restype=\"%s %s\" atomprev=\"%s\" atomnext=\"%s\" refdist=\"%g\"/>\n",
190 sb[i].res1,sb[i].res2,sb[i].atom1,sb[i].atom2,sb[i].length);
192 done_specbonds(nsb,sb);
193 sfree(sb);
194 fprintf(fp,"\n");
197 int main(int argc, char *argv[])
199 static char *desc[] = {
200 "This program reads an rtp file and dumps an xml file."
203 typedef struct {
204 char chain;
205 int start;
206 int natom;
207 gmx_bool bAllWat;
208 int nterpairs;
209 int *chainstart;
210 } t_pdbchain;
212 typedef struct {
213 char chain;
214 gmx_bool bAllWat;
215 int nterpairs;
216 int *chainstart;
217 t_hackblock **ntdb;
218 t_hackblock **ctdb;
219 int *rN;
220 int *rC;
221 t_atoms *pdba;
222 rvec *x;
223 } t_chain;
225 FILE *fp;
226 int natom,nres;
227 t_atoms pdba_all,*pdba;
228 t_atoms *atoms;
229 t_block *block;
230 int chain,nch,maxch,nwaterchain;
231 t_pdbchain *pdb_ch;
232 t_chain *chains,*cc;
233 char **res_long;
234 int nres_long;
235 char *ff;
236 int i,j,k,l,nrtp;
237 int *swap_index,si;
238 int bts[ebtsNR];
239 t_restp *restp;
240 t_hackblock *ah;
241 t_symtab symtab;
242 t_atomtype *atype;
243 char fn[256],*top_fn,itp_fn[STRLEN],posre_fn[STRLEN],buf_fn[STRLEN];
244 char molname[STRLEN],title[STRLEN];
245 char *c;
246 int nah,nNtdb,nCtdb;
247 t_hackblock *ntdb,*ctdb;
248 int nssbonds;
249 t_ssbond *ssbonds;
250 rvec *pdbx,*x;
251 gmx_bool bUsed,bDummies=FALSE,bWat,bPrevWat=FALSE,bITP,bDummyAromatics=FALSE;
252 real mHmult=0;
253 int nrexcl;
254 gmx_bool bAlldih,bH14,bRemoveDih;
256 CopyRight(stderr,argv[0]);
258 ff = strdup("ffgmx2");
260 /* Read long residue names */
261 nres_long = get_file("res-long.dat",&res_long);
263 /* Read atomtypes... */
264 atype=read_atype(ff,&symtab);
266 /* read residue database */
267 printf("Reading residue database... (%s)\n",ff);
268 nrtp=read_resall(ff,bts,&restp,atype,&symtab,&bAlldih,&nrexcl,&bH14,&bRemoveDih);
270 /* read hydrogen database */
271 nah=read_h_db(ff,&ah);
273 /* Read Termini database... */
274 nNtdb=read_ter_db(ff,'n',&ntdb,atype);
275 nCtdb=read_ter_db(ff,'c',&ctdb,atype);
277 fp=gmx_fio_fopen("residues.xml","w");
278 /* fprintf(fp,"<?xml version=\"1.0\"?>\n");
279 fprintf(fp,"<!DOCTYPE residues SYSTEM \"residues.dtd\">\n"); */
280 fprintf(fp,"\n<residues>\n");
281 for(i=0; (i<nrtp); i++) {
282 dump_res(fp,2,&(restp[i]),nah,ah,nres_long,res_long);
284 do_specbonds(fp,2);
285 dump_mods(fp,2,nNtdb,ntdb,atype);
286 dump_mods(fp,2,nCtdb,ctdb,atype);
287 fprintf(fp,"</residues>\n");
288 gmx_fio_fclose(fp);
290 thanx(stderr);
292 return 0;