Merge release-4-6 into master
[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     adress->refs[i]=strtod(ptr1[i],NULL);
74   for( ;(i<DIM); i++) /*remaining undefined components of the vector set to zero*/
75     adress->refs[i]=0;
76 }
77
78 void do_adress_index(t_adress *adress, gmx_groups_t *groups,char **gnames,t_grpopts *opts,warninp_t wi){
79   int nr,i,j,k;
80   char    *ptr1[MAXPTR];
81   int     nadress_cg_grp_names, nadress_tf_grp_names;
82     
83   /* AdResS coarse grained groups input */
84   
85   nr = groups->grps[egcENER].nr;
86   snew(adress->group_explicit, nr);
87   for (i=0; i <nr; i++){
88       adress->group_explicit[i] = TRUE;
89   }
90   adress->n_energy_grps = nr;
91
92   nadress_cg_grp_names = str_nelem(adress_cg_grp_names,MAXPTR,ptr1);
93
94   if (nadress_cg_grp_names > 0){
95         for (i=0; i <nadress_cg_grp_names; i++){
96             /* search for the group name mathching the tf group name */
97             k = 0;
98             while ((k < nr) &&
99                  gmx_strcasecmp(ptr1[i],(char*)(gnames[groups->grps[egcENER].nm_ind[k]])))
100               k++;
101             if (k==nr) gmx_fatal(FARGS,"Adress cg energy group %s not found\n",ptr1[i]);
102             adress->group_explicit[k] = FALSE;
103             printf ("AdResS: Energy group %s is treated as coarse-grained \n",
104               (char*)(gnames[groups->grps[egcENER].nm_ind[k]]));
105     }
106         /* set energy group exclusions between all coarse-grained and explicit groups */
107       for (j = 0; j < nr; j++) {
108             for (k = 0; k < nr; k++) {
109                 if (!(adress->group_explicit[k] == adress->group_explicit[j])){
110                     opts->egp_flags[nr * j + k] |= EGP_EXCL;
111                     if (debug) fprintf(debug,"AdResS excl %s %s \n",
112                         (char*)(gnames[groups->grps[egcENER].nm_ind[j]]),
113                         (char*)(gnames[groups->grps[egcENER].nm_ind[k]]));
114                 }
115             }
116       }
117   }else{
118       warning(wi,"For an AdResS simulation at least one coarse-grained energy group has to be specified in adress_cg_grp_names");
119   }
120
121
122   /* AdResS multiple tf tables input */
123   nadress_tf_grp_names = str_nelem(adress_tf_grp_names,MAXPTR,ptr1);
124   adress->n_tf_grps = nadress_tf_grp_names;
125   snew(adress->tf_table_index, nadress_tf_grp_names);
126
127   nr = groups->grps[egcENER].nr;
128
129   if (nadress_tf_grp_names > 0){
130         for (i=0; i <nadress_tf_grp_names; i++){
131             /* search for the group name mathching the tf group name */
132             k = 0;
133             while ((k < nr) &&
134                  gmx_strcasecmp(ptr1[i],(char*)(gnames[groups->grps[egcENER].nm_ind[k]])))
135               k++;
136             if (k==nr) gmx_fatal(FARGS,"Adress tf energy group %s not found\n",ptr1[i]);
137             
138             adress->tf_table_index[i] = k;
139             if (debug) fprintf(debug,"found tf group %s id %d \n",ptr1[i], k);
140             if (adress->group_explicit[k]){
141                 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]);
142             }
143
144     }
145   }
146   /* end AdResS multiple tf tables input */
147    
148   
149 }