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