Merge branch 'release-4-6'
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / readadress.c
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
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 4.6.0
11  * Written by Christoph Junghans, Brad Lambeth, and possibly others.
12  * Copyright (c) 2009 Christoph Junghans, Brad Lambeth.
13  * All rights reserved.
14
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.
19  *
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.
26  *
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.
29  *
30  * For more info, check our website at http://www.gromacs.org
31  *
32  * And Hey:
33  * GROningen Mixture of Alchemy and Childrens' Stories
34  */
35
36 #include "readir.h"
37 #include "names.h"
38 #include "smalloc.h"
39 #include "gmx_fatal.h"
40
41 #define MAXPTR 254
42
43 static char adress_refs[STRLEN], adress_tf_grp_names[STRLEN], adress_cg_grp_names[STRLEN];
44
45 void read_adressparams(int *ninp_p, t_inpfile **inp_p, t_adress *adress, warninp_t wi)
46 {
47     int         nadress_refs, i;
48     const char *tmp;
49     char       *ptr1[MAXPTR];
50
51
52     int        ninp;
53     t_inpfile *inp;
54
55     ninp   = *ninp_p;
56     inp    = *inp_p;
57
58     EETYPE("adress_type",                adress->type,         eAdresstype_names);
59     RTYPE ("adress_const_wf",            adress->const_wf,     1);
60     RTYPE ("adress_ex_width",            adress->ex_width,     0);
61     RTYPE ("adress_hy_width",            adress->hy_width,     0);
62     RTYPE ("adress_ex_forcecap",         adress->ex_forcecap,     0);
63     EETYPE("adress_interface_correction", adress->icor,         eAdressICtype_names);
64     EETYPE("adress_site",                adress->site,         eAdressSITEtype_names);
65     STYPE ("adress_reference_coords",    adress_refs,             NULL);
66     STYPE ("adress_tf_grp_names",        adress_tf_grp_names,     NULL);
67     STYPE ("adress_cg_grp_names",        adress_cg_grp_names,     NULL);
68     EETYPE("adress_do_hybridpairs",      adress->do_hybridpairs, yesno_names);
69
70     nadress_refs = str_nelem(adress_refs, MAXPTR, ptr1);
71
72     for (i = 0; (i < nadress_refs); i++) /*read vector components*/
73     {
74         adress->refs[i] = strtod(ptr1[i], NULL);
75     }
76     for (; (i < DIM); i++) /*remaining undefined components of the vector set to zero*/
77     {
78         adress->refs[i] = 0;
79     }
80
81     *ninp_p   = ninp;
82     *inp_p    = inp;
83 }
84
85 void do_adress_index(t_adress *adress, gmx_groups_t *groups, char **gnames, t_grpopts *opts, warninp_t wi)
86 {
87     int      nr, i, j, k;
88     char    *ptr1[MAXPTR];
89     int      nadress_cg_grp_names, nadress_tf_grp_names;
90
91     /* AdResS coarse grained groups input */
92
93     nr = groups->grps[egcENER].nr;
94     snew(adress->group_explicit, nr);
95     for (i = 0; i < nr; i++)
96     {
97         adress->group_explicit[i] = TRUE;
98     }
99     adress->n_energy_grps = nr;
100
101     nadress_cg_grp_names = str_nelem(adress_cg_grp_names, MAXPTR, ptr1);
102
103     if (nadress_cg_grp_names > 0)
104     {
105         for (i = 0; i < nadress_cg_grp_names; i++)
106         {
107             /* search for the group name mathching the tf group name */
108             k = 0;
109             while ((k < nr) &&
110                    gmx_strcasecmp(ptr1[i], (char*)(gnames[groups->grps[egcENER].nm_ind[k]])))
111             {
112                 k++;
113             }
114             if (k == nr)
115             {
116                 gmx_fatal(FARGS, "Adress cg energy group %s not found\n", ptr1[i]);
117             }
118             adress->group_explicit[k] = FALSE;
119             printf ("AdResS: Energy group %s is treated as coarse-grained \n",
120                     (char*)(gnames[groups->grps[egcENER].nm_ind[k]]));
121         }
122         /* set energy group exclusions between all coarse-grained and explicit groups */
123         for (j = 0; j < nr; j++)
124         {
125             for (k = 0; k < nr; k++)
126             {
127                 if (!(adress->group_explicit[k] == adress->group_explicit[j]))
128                 {
129                     opts->egp_flags[nr * j + k] |= EGP_EXCL;
130                     if (debug)
131                     {
132                         fprintf(debug, "AdResS excl %s %s \n",
133                                 (char*)(gnames[groups->grps[egcENER].nm_ind[j]]),
134                                 (char*)(gnames[groups->grps[egcENER].nm_ind[k]]));
135                     }
136                 }
137             }
138         }
139     }
140     else
141     {
142         warning(wi, "For an AdResS simulation at least one coarse-grained energy group has to be specified in adress_cg_grp_names");
143     }
144
145
146     /* AdResS multiple tf tables input */
147     nadress_tf_grp_names = str_nelem(adress_tf_grp_names, MAXPTR, ptr1);
148     adress->n_tf_grps    = nadress_tf_grp_names;
149     snew(adress->tf_table_index, nadress_tf_grp_names);
150
151     nr = groups->grps[egcENER].nr;
152
153     if (nadress_tf_grp_names > 0)
154     {
155         for (i = 0; i < nadress_tf_grp_names; i++)
156         {
157             /* search for the group name mathching the tf group name */
158             k = 0;
159             while ((k < nr) &&
160                    gmx_strcasecmp(ptr1[i], (char*)(gnames[groups->grps[egcENER].nm_ind[k]])))
161             {
162                 k++;
163             }
164             if (k == nr)
165             {
166                 gmx_fatal(FARGS, "Adress tf energy group %s not found\n", ptr1[i]);
167             }
168
169             adress->tf_table_index[i] = k;
170             if (debug)
171             {
172                 fprintf(debug, "found tf group %s id %d \n", ptr1[i], k);
173             }
174             if (adress->group_explicit[k])
175             {
176                 gmx_fatal(FARGS, "Thermodynamic force group %s is not a coarse-grained group in adress_cg_grp_names. The thermodynamic force has to act on the coarse-grained vsite of a molecule.\n", ptr1[i]);
177             }
178
179         }
180     }
181     /* end AdResS multiple tf tables input */
182
183
184 }