2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
62 int gmx_sans(int argc,char *argv[])
64 const char *desc[] = {
65 "This is simple tool to compute SANS spectra using Debye formula",
66 "It currently uses topology file (since it need to assigne element for each atom)",
68 "[TT]-pr[tt] Computes normalized g(r) function",
70 "[TT]-sq[tt] Computes SANS intensity curve for needed q diapason",
72 "[TT]-startq[tt] Starting q value in nm",
74 "[TT]-endq[tt] Ending q value in nm",
76 "[TT]-qstep[tt] Stepping in q space",
78 "Note: When using Debye direct method computational cost increases as",
79 "1/2 * N * (N - 1) where N is atom number in group of interest"
81 static gmx_bool bPBC=TRUE;
82 static real binwidth=0.2,grid=0.05; /* bins shouldnt be smaller then bond (~0.1nm) length */
83 static real start_q=0.0, end_q=2.0, q_step=0.01;
84 static real mcover=-1;
85 static unsigned int seed=0;
86 static int nthreads=-1;
88 static const char *emode[]= { NULL, "direct", "mc", NULL };
89 static const char *emethod[]={ NULL, "debye", "fft", NULL };
91 gmx_nentron_atomic_structurefactors_t *gnsf;
97 { "-bin", FALSE, etREAL, {&binwidth},
98 "[HIDDEN]Binwidth (nm)" },
99 { "-mode", FALSE, etENUM, {emode},
100 "Mode for sans spectra calculation" },
101 { "-mcover", FALSE, etREAL, {&mcover},
102 "Monte-Carlo coverage should be -1(default) or (0,1]"},
103 { "-method", FALSE, etENUM, {emethod},
104 "[HIDDEN]Method for sans spectra calculation" },
105 { "-pbc", FALSE, etBOOL, {&bPBC},
106 "Use periodic boundary conditions for computing distances" },
107 { "-grid", FALSE, etREAL, {&grid},
108 "[HIDDEN]Grid spacing (in nm) for FFTs" },
109 {"-startq", FALSE, etREAL, {&start_q},
110 "Starting q (1/nm) "},
111 {"-endq", FALSE, etREAL, {&end_q},
113 { "-qstep", FALSE, etREAL, {&q_step},
114 "Stepping in q (1/nm)"},
115 { "-seed", FALSE, etINT, {&seed},
116 "Random seed for Monte-Carlo"},
118 { "-nt", FALSE, etINT, {&nthreads},
119 "Number of threads to start"},
123 const char *fnTPX,*fnNDX,*fnDAT=NULL;
125 t_topology *top=NULL;
127 gmx_rmpbc_t gpbc=NULL;
129 gmx_bool bFFT=FALSE, bDEBYE=FALSE;
141 gmx_radial_distribution_histogram_t *pr=NULL;
142 gmx_static_structurefator_t *sq=NULL;
145 #define NFILE asize(fnm)
148 { efTPX, "-s", NULL, ffREAD },
149 { efNDX, NULL, NULL, ffOPTRD },
150 { efDAT, "-d", "nsfactor", ffOPTRD },
151 { efXVG, "-sq", "sq", ffWRITE },
152 { efXVG, "-pr", "pr", ffWRITE }
155 nthreads = gmx_omp_get_max_threads();
157 CopyRight(stderr,argv[0]);
158 parse_common_args(&argc,argv,PCA_BE_NICE,
159 NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL,&oenv);
161 /* check that binwidth not smaller than smallers distance */
162 check_binwidth(binwidth);
163 check_mcover(mcover);
165 /* setting number of omp threads globaly */
166 gmx_omp_set_num_threads(nthreads);
168 /* Now try to parse opts for modes */
169 switch(emethod[0][0]) {
172 switch(emode[0][0]) {
190 if (!bDEBYE && !bFFT)
191 gmx_fatal(FARGS,"Unknown method. Set pr or fft!\n");
192 /* Try to read files */
193 fnDAT = ftp2fn(efDAT,NFILE,fnm);
194 fnTPX = ftp2fn(efTPX,NFILE,fnm);
196 gnsf = gmx_neutronstructurefactors_init(fnDAT);
197 fprintf(stderr,"Read %d atom names from %s with neutron scattering parameters\n\n",gnsf->nratoms,fnDAT);
203 bTPX=read_tps_conf(fnTPX,title,top,&ePBC,&x,NULL,box,TRUE);
205 printf("\nPlease select group for SANS spectra calculation:\n");
206 get_index(&(top->atoms),ftp2fn_null(efNDX,NFILE,fnm),1,&isize,&index,grpname);
208 gsans = gmx_sans_init(top,gnsf);
210 /* Prepare reference frame */
212 gpbc = gmx_rmpbc_init(&top->idef,ePBC,top->atoms.nr,box);
213 gmx_rmpbc(gpbc,top->atoms.nr,box,x);
216 natoms=top->atoms.nr;
220 fprintf(stderr,"Using Monte Carlo Debye method to calculate spectrum\n");
222 fprintf(stderr,"Using direct Debye method to calculate spectrum\n");
225 gmx_fatal(FARGS,"Not implented!");
227 gmx_fatal(FARGS,"Whats this!");
230 /* realy calc p(r) */
231 pr = calc_radial_distribution_histogram(gsans,x,box,index,isize,binwidth,bMC,mcover,seed);
234 fp = xvgropen(opt2fn_null("-pr",NFILE,fnm),"G(r)","Distance (nm)","Probability",oenv);
235 for(i=0;i<pr->grn;i++)
236 fprintf(fp,"%10.6lf%10.6lf\n",pr->r[i],pr->gr[i]);
240 sq = convert_histogram_to_intensity_curve(pr,start_q,end_q,q_step);
241 fp = xvgropen(opt2fn_null("-sq",NFILE,fnm),"I(q)","q (nm^-1)","s(q)/s(0)",oenv);
242 for(i=0;i<sq->qn;i++) {
243 fprintf(fp,"%10.6lf%10.6lf\n",sq->q[i],sq->s[i]);
249 please_cite(stdout,"Garmay2012");