Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / src / contrib / xmdrun.c
1 /*
2  * $Id$
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 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * Glycine aRginine prOline Methionine Alanine Cystine Serine
35  */
36 static char *SRCID_xmdrun_c = "$Id$";
37 #include <stdio.h>
38 #include <string.h>
39 #include <time.h>
40 #include <math.h>
41 #include "sysstuff.h"
42 #include "string2.h"
43 #include "nrnb.h"
44 #include "network.h"
45 #include "confio.h"
46 #include "binio.h"
47 #include "copyrite.h"
48 #include "smalloc.h"
49 #include "main.h"
50 #include "pbc.h"
51 #include "force.h"
52 #include "macros.h"
53 #include "names.h"
54 #include "mdrun.h"
55 #include "fatal.h"
56 #include "txtdump.h"
57 #include "typedefs.h"
58 #include "update.h"
59 #include "random.h"
60 #include "vec.h"
61 #include "filenm.h"
62 #include "statutil.h"
63 #include "tgroup.h"
64 #include "vcm.h"
65 #include "trnio.h"
66 #include "ebin.h"
67 #include "mdebin.h"
68 #include "disre.h"
69 #include "dummies.h"
70 #include "init_sh.h"
71 #include "do_gct.h"
72 #include "physics.h"
73 #include "sim_util.h"
74 #include "block_tx.h"
75 #include "rdgroup.h"
76 #include "glaasje.h"
77 #include "edsam.h"
78 #include "calcmu.h"
79 #include "ionize.h" 
80
81 static t_commrec *cr_msim;
82
83 t_commrec *init_msim(t_commrec *cr,int nfile,t_filenm fnm[])
84 {
85   t_commrec *cr_new;
86   int  i,ftp;
87   char *buf;
88   
89   cr_msim = cr;
90   snew(cr_new,1);
91   cr_new->nodeid = 0;
92   cr_new->nnodes = 1;
93   cr_new->left   = cr->left;
94   cr_new->right  = cr->right;
95   
96   /* Patch file names (except log which has been done already) */
97   for(i=0; (i<nfile); i++) {
98     /* Because of possible multiple extensions per type we must look 
99      * at the actual file name 
100      */
101     ftp = fn2ftp(fnm[i].fn);
102     if (ftp != efLOG) {
103 #ifdef DEBUGPAR
104       fprintf(stderr,"Old file name: %s",fnm[i].fn);
105 #endif
106       buf = par_fn(fnm[i].fn,ftp,cr);
107       sfree(fnm[i].fn);
108       fnm[i].fn = strdup(buf);
109 #ifdef DEBUGPAR
110       fprintf(stderr,", new: %s\n",fnm[i].fn);
111 #endif
112     }
113   }
114   
115   return cr_new;
116 }
117
118 real mol_dipole(int k0,int k1,atom_id ma[],rvec x[],real q[])
119 {
120   int  k,kk,m;
121   rvec mu;
122   
123   clear_rvec(mu);
124   for(k=k0; (k<k1); k++) {
125     kk = ma[k];
126     for(m=0; (m<DIM); m++) 
127       mu[m] += q[kk]*x[kk][m];
128   }
129   return norm(mu);  /* Dipole moment of this molecule in e nm */
130 }
131
132 real calc_mu_aver(t_commrec *cr,t_nsborder *nsb,rvec x[],real q[],rvec mu,
133                   t_topology *top,t_mdatoms *md,int gnx,atom_id grpindex[])
134 {
135   int     i,start,end;
136   real    mu_ave;
137   t_atom  *atom;
138   t_block *mols;
139   
140   start = START(nsb);
141   end   = start + HOMENR(nsb);  
142   
143   atom = top->atoms.atom;
144   mols = &(top->blocks[ebMOLS]);
145   /*
146   clear_rvec(mu);
147   for(i=start; (i<end); i++)
148     for(m=0; (m<DIM); m++)
149       mu[m] += q[i]*x[i][m];
150   if (PAR(cr)) {
151     gmx_sum(DIM,mu,cr);
152   }
153   */
154   /* I guess we have to parallelise this one! */
155
156   if (gnx > 0) {
157     mu_ave = 0.0;
158     for(i=0; (i<gnx); i++) {
159       int gi = grpindex[i];
160       mu_ave += mol_dipole(mols->index[gi],mols->index[gi+1],mols->a,x,q);
161     }
162     
163     return(mu_ave/gnx);
164   }
165   else
166     return 0;
167 }
168
169 #define XMDRUN
170 #include "../mdlib/md.c"
171 #include "../kernel/mdrun.c"