Fixed make_edi.c
[gromacs/rigid-bodies.git] / src / tools / gmx_principal.c
blob5cd9d72d7043e3745aaf86827044c1c57791429b
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
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.
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.
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.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Green Red Orange Magenta Azure Cyan Skyblue
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include <math.h>
40 #include <string.h>
42 #include "statutil.h"
43 #include "sysstuff.h"
44 #include "typedefs.h"
45 #include "smalloc.h"
46 #include "macros.h"
47 #include "vec.h"
48 #include "pbc.h"
49 #include "copyrite.h"
50 #include "futil.h"
51 #include "statutil.h"
52 #include "index.h"
53 #include "mshift.h"
54 #include "xvgr.h"
55 #include "princ.h"
56 #include "rmpbc.h"
57 #include "txtdump.h"
58 #include "tpxio.h"
59 #include "gstat.h"
60 #include "gmx_ana.h"
63 void
64 calc_principal_axes(t_topology * top,
65 rvec * x,
66 atom_id * index,
67 int n,
68 matrix axes,
69 rvec inertia)
71 rvec xcm;
73 sub_xcm(x,n,index,top->atoms.atom,xcm,FALSE);
74 principal_comp(n,index,top->atoms.atom,x,axes,inertia);
77 int gmx_principal(int argc,char *argv[])
79 const char *desc[] = {
80 "g_principal calculates the three principal axes of inertia for a group",
81 "of atoms.",
83 static bool foo = FALSE;
85 t_pargs pa[] = {
86 { "-foo", FALSE, etBOOL, {&foo}, "Dummy option to avoid empty array" }
88 int status;
89 t_topology top;
90 int ePBC;
91 real t;
92 rvec * x;
94 int natoms;
95 char *grpname,title[256];
96 int i,j,m,gnx,nam,mol;
97 atom_id *index;
98 rvec a1,a2,a3,moi;
99 FILE * axis1;
100 FILE * axis2;
101 FILE * axis3;
102 FILE * fmoi;
103 matrix axes,box;
104 output_env_t oenv;
106 t_filenm fnm[] = {
107 { efTRX, "-f", NULL, ffREAD },
108 { efTPS, NULL, NULL, ffREAD },
109 { efNDX, NULL, NULL, ffOPTRD },
110 { efDAT, "-a1", "axis1", ffWRITE },
111 { efDAT, "-a2", "axis2", ffWRITE },
112 { efDAT, "-a3", "axis3", ffWRITE },
113 { efDAT, "-om", "moi", ffWRITE }
115 #define NFILE asize(fnm)
117 CopyRight(stderr,argv[0]);
118 parse_common_args(&argc,argv,
119 PCA_CAN_TIME | PCA_TIME_UNIT | PCA_CAN_VIEW | PCA_BE_NICE,
120 NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL,&oenv);
122 axis1=ffopen(opt2fn("-a1",NFILE,fnm),"w");
123 axis2=ffopen(opt2fn("-a2",NFILE,fnm),"w");
124 axis3=ffopen(opt2fn("-a3",NFILE,fnm),"w");
125 fmoi =ffopen(opt2fn("-om",NFILE,fnm),"w");
127 read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,NULL,NULL,box,TRUE);
129 get_index(&top.atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&gnx,&index,&grpname);
131 natoms=read_first_x(oenv,&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box);
135 rm_pbc(&(top.idef),ePBC,natoms,box,x,x);
136 calc_principal_axes(&top,x,index,gnx,axes,moi);
138 fprintf(axis1,"%15.10f %15.10f %15.10f %15.10f\n",t,axes[XX][XX],axes[YY][XX],axes[ZZ][XX]);
139 fprintf(axis2,"%15.10f %15.10f %15.10f %15.10f\n",t,axes[XX][YY],axes[YY][YY],axes[ZZ][YY]);
140 fprintf(axis3,"%15.10f %15.10f %15.10f %15.10f\n",t,axes[XX][ZZ],axes[YY][ZZ],axes[ZZ][ZZ]);
141 fprintf(fmoi, "%15.10f %15.10f %15.10f %15.10f\n",t,moi[XX],moi[YY],moi[ZZ]);
143 while(read_next_x(oenv,status,&t,natoms,x,box));
145 close_trj(status);
146 ffclose(axis1);
147 ffclose(axis2);
148 ffclose(axis3);
149 ffclose(fmoi);
151 thanx(stderr);
153 return 0;