Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / kernel / readadress.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009 Christoph Junghans, Brad Lambeth.
5  * Copyright (c) 2012,2013, by the GROMACS development team, led by
6  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
7  * others, as listed in the AUTHORS file in the top-level source
8  * directory and at http://www.gromacs.org.
9  *
10  * GROMACS is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation; either version 2.1
13  * of the License, or (at your option) any later version.
14  *
15  * GROMACS is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with GROMACS; if not, see
22  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24  *
25  * If you want to redistribute modifications to GROMACS, please
26  * consider that scientific software is very special. Version
27  * control is crucial - bugs must be traceable. We will be happy to
28  * consider code for inclusion in the official distribution, but
29  * derived work must not be called official GROMACS. Details are found
30  * in the README & COPYING files - if they are missing, get the
31  * official version at http://www.gromacs.org.
32  *
33  * To help us fund GROMACS development, we humbly ask that you cite
34  * the research papers on the package. Check out http://www.gromacs.org.
35  */
36
37 #include "readir.h"
38 #include "names.h"
39 #include "smalloc.h"
40 #include "gmx_fatal.h"
41
42 #define MAXPTR 254
43
44 static char adress_refs[STRLEN],adress_tf_grp_names[STRLEN], adress_cg_grp_names[STRLEN];
45
46 void read_adressparams(int *ninp_p,t_inpfile **inp_p,t_adress *adress, warninp_t wi)
47 {
48   int     nadress_refs,i;
49   const char *tmp;
50   char    *ptr1[MAXPTR];
51
52
53   int    ninp;
54   t_inpfile *inp;
55
56   ninp   = *ninp_p;
57   inp    = *inp_p;
58
59   EETYPE("adress_type",                adress->type,         eAdresstype_names);
60   RTYPE ("adress_const_wf",            adress->const_wf,     1);
61   RTYPE ("adress_ex_width",            adress->ex_width,     0);
62   RTYPE ("adress_hy_width",            adress->hy_width,     0);
63   RTYPE ("adress_ex_forcecap",         adress->ex_forcecap,     0);
64   EETYPE("adress_interface_correction",adress->icor,         eAdressICtype_names);
65   EETYPE("adress_site",                adress->site,         eAdressSITEtype_names);
66   STYPE ("adress_reference_coords",    adress_refs,             NULL);
67   STYPE ("adress_tf_grp_names",        adress_tf_grp_names,     NULL);
68   STYPE ("adress_cg_grp_names",        adress_cg_grp_names,     NULL);
69   EETYPE("adress_do_hybridpairs",      adress->do_hybridpairs, yesno_names);
70   
71   nadress_refs = str_nelem(adress_refs,MAXPTR,ptr1);
72
73   for(i=0; (i<nadress_refs); i++) /*read vector components*/
74     adress->refs[i]=strtod(ptr1[i],NULL);
75   for( ;(i<DIM); i++) /*remaining undefined components of the vector set to zero*/
76     adress->refs[i]=0;
77
78   *ninp_p   = ninp;
79   *inp_p    = inp;
80 }
81
82 void do_adress_index(t_adress *adress, gmx_groups_t *groups,char **gnames,t_grpopts *opts,warninp_t wi){
83   int nr,i,j,k;
84   char    *ptr1[MAXPTR];
85   int     nadress_cg_grp_names, nadress_tf_grp_names;
86     
87   /* AdResS coarse grained groups input */
88   
89   nr = groups->grps[egcENER].nr;
90   snew(adress->group_explicit, nr);
91   for (i=0; i <nr; i++){
92       adress->group_explicit[i] = TRUE;
93   }
94   adress->n_energy_grps = nr;
95
96   nadress_cg_grp_names = str_nelem(adress_cg_grp_names,MAXPTR,ptr1);
97
98   if (nadress_cg_grp_names > 0){
99         for (i=0; i <nadress_cg_grp_names; i++){
100             /* search for the group name mathching the tf group name */
101             k = 0;
102             while ((k < nr) &&
103                  gmx_strcasecmp(ptr1[i],(char*)(gnames[groups->grps[egcENER].nm_ind[k]])))
104               k++;
105             if (k==nr) gmx_fatal(FARGS,"Adress cg energy group %s not found\n",ptr1[i]);
106             adress->group_explicit[k] = FALSE;
107             printf ("AdResS: Energy group %s is treated as coarse-grained \n",
108               (char*)(gnames[groups->grps[egcENER].nm_ind[k]]));
109     }
110         /* set energy group exclusions between all coarse-grained and explicit groups */
111       for (j = 0; j < nr; j++) {
112             for (k = 0; k < nr; k++) {
113                 if (!(adress->group_explicit[k] == adress->group_explicit[j])){
114                     opts->egp_flags[nr * j + k] |= EGP_EXCL;
115                     if (debug) fprintf(debug,"AdResS excl %s %s \n",
116                         (char*)(gnames[groups->grps[egcENER].nm_ind[j]]),
117                         (char*)(gnames[groups->grps[egcENER].nm_ind[k]]));
118                 }
119             }
120       }
121   }else{
122       warning(wi,"For an AdResS simulation at least one coarse-grained energy group has to be specified in adress_cg_grp_names");
123   }
124
125
126   /* AdResS multiple tf tables input */
127   nadress_tf_grp_names = str_nelem(adress_tf_grp_names,MAXPTR,ptr1);
128   adress->n_tf_grps = nadress_tf_grp_names;
129   snew(adress->tf_table_index, nadress_tf_grp_names);
130
131   nr = groups->grps[egcENER].nr;
132
133   if (nadress_tf_grp_names > 0){
134         for (i=0; i <nadress_tf_grp_names; i++){
135             /* search for the group name mathching the tf group name */
136             k = 0;
137             while ((k < nr) &&
138                  gmx_strcasecmp(ptr1[i],(char*)(gnames[groups->grps[egcENER].nm_ind[k]])))
139               k++;
140             if (k==nr) gmx_fatal(FARGS,"Adress tf energy group %s not found\n",ptr1[i]);
141             
142             adress->tf_table_index[i] = k;
143             if (debug) fprintf(debug,"found tf group %s id %d \n",ptr1[i], k);
144             if (adress->group_explicit[k]){
145                 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]);
146             }
147
148     }
149   }
150   /* end AdResS multiple tf tables input */
151    
152   
153 }