3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
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
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
35 /* This file is completely threadsafe - keep it that way! */
48 #include "fflibutil.h"
49 #include "gmx_fatal.h"
52 /* There are 11 types of adding hydrogens, numbered from
53 * 1 thru 11. Each of these has a specific number of
54 * control atoms, that determine how the hydrogens are added.
55 * Here these number are given. Because arrays start at 0 an
56 * extra dummy for index 0 is added
58 const int ncontrol[] = { -1, 3, 3, 3, 3, 4, 3, 1, 3, 3, 1, 1 };
59 #define maxcontrol asize(ncontrol)
61 int compaddh(const void *a, const void *b)
65 ah = (t_hackblock *)a;
66 bh = (t_hackblock *)b;
67 return gmx_strcasecmp(ah->name, bh->name);
70 void print_ab(FILE *out, t_hack *hack, char *nname)
74 fprintf(out, "%d\t%d\t%s", hack->nr, hack->tp, nname);
75 for (i = 0; (i < hack->nctl); i++)
77 fprintf(out, "\t%s", hack->a[i]);
83 void read_ab(char *line, const char *fn, t_hack *hack)
89 ns = sscanf(line, "%d%d%s%s%s%s%s", &nh, &tp, hn, a[0], a[1], a[2], a[3]);
92 gmx_fatal(FARGS, "wrong format in input file %s on line\n%s\n", fn, line);
97 if ((tp < 1) || (tp >= maxcontrol))
99 gmx_fatal(FARGS, "Error in hdb file %s:\nH-type should be in 1-%d. Offending line:\n%s", fn, maxcontrol-1, line);
103 if ((hack->nctl != ncontrol[hack->tp]) && (ncontrol[hack->tp] != -1))
105 gmx_fatal(FARGS, "Error in hdb file %s:\nWrong number of control atoms (%d iso %d) on line:\n%s\n", fn, hack->nctl, ncontrol[hack->tp], line);
107 for (i = 0; (i < hack->nctl); i++)
109 hack->a[i] = strdup(a[i]);
116 hack->nname = strdup(hn);
120 for (i = 0; i < DIM; i++)
122 hack->newx[i] = NOTSET;
126 static void read_h_db_file(const char *hfn, int *nahptr, t_hackblock **ah)
129 char filebase[STRLEN], line[STRLEN], buf[STRLEN];
135 fprintf(debug, "Hydrogen Database (%s):\n", hfn);
138 fflib_filename_base(hfn, filebase, STRLEN);
139 /* Currently filebase is read and set, but not used.
140 * hdb entries from any hdb file and be applied to rtp entries
144 in = fflib_open(hfn);
148 while (fgets2(line, STRLEN-1, in))
150 if (sscanf(line, "%s%n", buf, &n) != 1)
152 fprintf(stderr, "Error in hdb file: nah = %d\nline = '%s'\n",
158 fprintf(debug, "%s", buf);
161 clear_t_hackblock(&aah[nah]);
162 aah[nah].name = strdup(buf);
163 aah[nah].filebase = strdup(filebase);
165 if (sscanf(line+n, "%d", &nab) == 1)
169 fprintf(debug, " %d\n", nab);
171 snew(aah[nah].hack, nab);
172 aah[nah].nhack = nab;
173 for (i = 0; (i < nab); i++)
177 gmx_fatal(FARGS, "Expected %d lines of hydrogens, found only %d "
178 "while reading Hydrogen Database %s residue %s",
179 nab, i-1, aah[nah].name, hfn);
181 if (NULL == fgets(buf, STRLEN, in))
183 gmx_fatal(FARGS, "Error reading from file %s", hfn);
185 read_ab(buf, hfn, &(aah[nah].hack[i]));
192 /* Sort the list (necessary to be able to use bsearch */
193 qsort(aah, nah, (size_t)sizeof(**ah), compaddh);
197 dump_h_db(hfn,nah,aah);
204 int read_h_db(const char *ffdir, t_hackblock **ah)
211 /* Read the hydrogen database file(s).
212 * Do not generate an error when no files are found.
214 nhdbf = fflib_search_file_end(ffdir, ".hdb", FALSE, &hdbf);
217 for (f = 0; f < nhdbf; f++)
219 read_h_db_file(hdbf[f], &nah, ah);
227 t_hackblock *search_h_db(int nh, t_hackblock ah[], char *key)
229 t_hackblock ahkey, *result;
238 result = (t_hackblock *)bsearch(&ahkey, ah, nh, (size_t)sizeof(ah[0]), compaddh);