4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * GROningen Mixture of Alchemy and Childrens' Stories
32 static char *SRCID_protonate_c
= "$Id$";
44 #include "hackblock.h"
46 int main (int argc
,char *argv
[])
48 static char *desc
[] = {
49 "[TT]protonate[tt] reads (a) conformation(s) and adds all missing",
50 "hydrogens as defined in [TT]ffgmx2.hdb[tt]. If only [TT]-s[tt] is",
51 "specified, this conformation will be protonated, if also [TT]-f[tt]",
52 "is specified, the conformation(s) will be read from this file",
53 "which can be either a single conformation or a trajectory.",
55 "If a pdb file is supplied, residue names might not correspond to",
56 "to the GROMACS naming conventions, in which case these residues will",
57 "probably not be properly protonated.",
59 "If an index file is specified, please note that the atom numbers",
60 "should correspond to the [BB]protonated[bb] state."
67 t_atoms
*atoms
,*iatoms
;
73 int nidx
,natoms
,natoms_out
;
79 { efTPS
, NULL
, NULL
, ffREAD
},
80 { efTRX
, "-f", NULL
, ffOPTRD
},
81 { efNDX
, NULL
, NULL
, ffOPTRD
},
82 { efTRX
, "-o", "protonated", ffWRITE
}
84 #define NFILE asize(fnm)
86 CopyRight(stderr
,argv
[0]);
87 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,
88 NFILE
,fnm
,0,NULL
,asize(desc
),desc
,0,NULL
);
90 infile
=opt2fn("-s",NFILE
,fnm
);
91 read_tps_conf(infile
,title
,&top
,&x
,NULL
,box
,FALSE
);
93 printf("Select group to process:\n");
94 get_index(atoms
,ftp2fn_null(efNDX
,NFILE
,fnm
),1,&nidx
,&index
,&grpnm
);
95 bReadMultiple
= opt2bSet("-f",NFILE
,fnm
);
97 infile
= opt2fn("-f",NFILE
,fnm
);
98 if ( !read_first_frame(&status
, infile
, &fr
, TRX_NEED_X
) )
99 fatal_error(0,"cannot read coordinate file %s",infile
);
102 clear_trxframe(&fr
,TRUE
);
103 fr
.natoms
= atoms
->nr
;
109 copy_mat(box
, fr
.box
);
115 fatal_error(0,"no atoms in coordinate file %s",infile
);
116 if ( natoms
> atoms
->nr
)
117 fatal_error(0,"topology with %d atoms does not match "
118 "coordinates with %d atoms",atoms
->nr
,natoms
);
119 for(i
=0; i
<nidx
; i
++)
120 if (index
[i
] > natoms
)
121 fatal_error(0,"An atom number in group %s is larger than the number of "
122 "atoms (%d) in the coordinate file %s",grpnm
,natoms
,infile
);
124 /* get indexed copy of atoms */
126 init_t_atoms(iatoms
,nidx
,FALSE
);
127 snew(iatoms
->atom
, iatoms
->nr
);
129 for(i
=0; i
<nidx
; i
++) {
130 iatoms
->atom
[i
] = atoms
->atom
[index
[i
]];
131 iatoms
->atomname
[i
] = atoms
->atomname
[index
[i
]];
132 if ( i
>0 && (atoms
->atom
[index
[i
]].resnr
!=atoms
->atom
[index
[i
-1]].resnr
) )
134 iatoms
->atom
[i
].resnr
= resnr
;
135 iatoms
->resname
[resnr
] = atoms
->resname
[atoms
->atom
[index
[i
]].resnr
];
136 iatoms
->nres
= max(iatoms
->nres
, iatoms
->atom
[i
].resnr
+1);
139 init_t_protonate(&protdata
);
141 out
= open_trx(opt2fn("-o",NFILE
,fnm
),"w");
145 if (debug
) fprintf(debug
,"FRAME %d (%d %g)\n",frame
,fr
.step
,fr
.time
);
146 /* get indexed copy of x */
147 for(i
=0; i
<nidx
; i
++)
148 copy_rvec(fr
.x
[index
[i
]], ix
[i
]);
150 natoms_out
= protonate(&iatoms
, &ix
, &protdata
);
152 /* setup output frame */
154 frout
.natoms
= natoms_out
;
156 frout
.atoms
= iatoms
;
160 write_trxframe(out
,&frout
);
162 } while ( bReadMultiple
&& read_next_frame(status
, &fr
) );