Framework for printing help for selections.
[gromacs/adressmacs.git] / src / gmxlib / rmpbc.c
blob785f95cac8622ecb190a54f8ab2dd05f47d5e3f5
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 * GROningen Mixture of Alchemy and Childrens' Stories
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include "sysstuff.h"
40 #include "typedefs.h"
41 #include "smalloc.h"
42 #include "mshift.h"
43 #include "pbc.h"
44 #include "gstat.h"
45 #include "futil.h"
46 #include "vec.h"
48 typedef struct {
49 int natoms;
50 t_graph *gr;
51 } multi_graph;
54 void rm_pbc(t_idef *idef,int ePBC,int natoms,matrix box,rvec x[],rvec x_s[])
56 static int ngraph=0;
57 static multi_graph *mgraph=NULL;
58 static bool bFirst=TRUE;
59 rvec sv[SHIFTS];
60 int n,i;
61 bool bNeedToCopy;
63 if (ePBC == -1)
64 ePBC = guess_ePBC(box);
66 bNeedToCopy = (x != x_s);
68 if (ePBC != epbcNONE) {
69 if (idef->ntypes!=-1) {
70 n=-1;
71 for(i=0; i<ngraph; i++)
72 if (mgraph[i].natoms==natoms)
73 n=i;
74 if (n==-1) {
75 /* make a new graph if there isn't one with this number of atoms */
76 n=ngraph;
77 ngraph++;
78 srenew(mgraph,ngraph);
79 mgraph[n].natoms=natoms;
80 mgraph[n].gr=mk_graph(NULL,idef,0,natoms,FALSE,FALSE);
82 mk_mshift(stdout,mgraph[n].gr,ePBC,box,x);
83 calc_shifts(box,sv);
84 shift_x(mgraph[n].gr,box,x,x_s);
85 bNeedToCopy=FALSE;
86 } else if (bFirst) {
87 fprintf(stderr,
88 "\nWarning: if there are broken molecules in the trajectory file,\n"
89 " they can not be made whole without a run input file\n\n");
90 bFirst=FALSE;
93 if (bNeedToCopy)
94 for (i=0; i<natoms; i++)
95 copy_rvec(x[i],x_s[i]);
98 void rm_gropbc(t_atoms *atoms,rvec x[],matrix box)
100 real dist;
101 int n,m,d;
103 /* check periodic boundary */
104 for(n=1;(n<atoms->nr);n++) {
105 for(m=DIM-1; m>=0; m--) {
106 dist = x[n][m]-x[n-1][m];
107 if (fabs(dist) > 0.9*box[m][m]) {
108 if ( dist > 0 )
109 for(d=0; d<=m; d++)
110 x[n][d] -= box[m][d];
111 else
112 for(d=0; d<=m; d++)
113 x[n][d] += box[m][d];