4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_clincs_c
= "$Id$";
37 void clincs(rvec
*x
,rvec
*xp
,int ncons
,
38 int *bla1
,int *bla2
,int *blnr
,int *blbnb
,real
*bllen
,
39 real
*blc
,real
*blcc
,real
*blm
,
40 int nit
,int nrec
,real
*invmass
,rvec
* r
,
41 real
*rhs1
,real
*rhs2
,real
*sol
,real wangle
,int *warn
,
45 real tmp0
,tmp1
,tmp2
,im1
,im2
,mvb
,rlen
,len
,wfac
,lam
;
46 real u0
,u1
,u2
,v0
,v1
,v2
;
51 /* Compute normalized i-j vectors */
52 for(b
=0;b
<ncons
;b
++) {
58 rlen
=invsqrt(tmp0
*tmp0
+tmp1
*tmp1
+tmp2
*tmp2
);
62 } /* 16 ncons flops */
64 for(b
=0;b
<ncons
;b
++) {
71 for(n
=blnr
[b
];n
<blnr
[b
+1];n
++) {
73 blm
[n
]=blcc
[n
]*(tmp0
*r
[k
][0]+tmp1
*r
[k
][1]+tmp2
*r
[k
][2]);
75 mvb
=blc
[b
]*(tmp0
*(xp
[i
][0]-xp
[j
][0])+
76 tmp1
*(xp
[i
][1]-xp
[j
][1])+
77 tmp2
*(xp
[i
][2]-xp
[j
][2])-len
);
82 /* Together: 24*ncons + 6*nrtot flops */
85 for(rec
=0;rec
<nrec
;rec
++) {
86 for(b
=0;b
<ncons
;b
++) {
88 for(n
=blnr
[b
];n
<blnr
[b
+1];n
++) {
90 mvb
=mvb
+blm
[n
]*rhs1
[j
];
98 } /* nrec*(ncons+2*nrtot) flops */
100 for(b
=0;b
<ncons
;b
++) {
110 u0
=xp
[i
][0]-tmp0
*im1
;
111 u1
=xp
[i
][1]-tmp1
*im1
;
112 u2
=xp
[i
][2]-tmp2
*im1
;
113 v0
=xp
[j
][0]+tmp0
*im2
;
114 v1
=xp
[j
][1]+tmp1
*im2
;
115 v2
=xp
[j
][2]+tmp2
*im2
;
122 } /* 16 ncons flops */
127 ******** Correction for centripetal effects ********
130 wfac
=cos(DEG2RAD
*wangle
);
133 for(it
=0; it
<nit
; it
++) {
135 for(b
=0;b
<ncons
;b
++) {
139 tmp0
=xp
[i
][0]-xp
[j
][0];
140 tmp1
=xp
[i
][1]-xp
[j
][1];
141 tmp2
=xp
[i
][2]-xp
[j
][2];
143 u0
=2.*u1
-(tmp0
*tmp0
+tmp1
*tmp1
+tmp2
*tmp2
);
144 if (u0
< wfac
*u1
) *warn
=b
;
146 mvb
=blc
[b
]*(len
-sqrt(u0
));
149 } /* 18*ncons flops */
151 for(rec
=0;rec
<nrec
;rec
++) {
152 for(b
=0;b
<ncons
;b
++) {
154 for(n
=blnr
[b
];n
<blnr
[b
+1];n
++) {
156 mvb
=mvb
+blm
[n
]*rhs1
[j
];
164 } /* nrec*(ncons+2*nrtot) flops */
166 for(b
=0;b
<ncons
;b
++) {
177 u0
=xp
[i
][0]-tmp0
*im1
;
178 u1
=xp
[i
][1]-tmp1
*im1
;
179 u2
=xp
[i
][2]-tmp2
*im1
;
180 v0
=xp
[j
][0]+tmp0
*im2
;
181 v1
=xp
[j
][1]+tmp1
*im2
;
182 v2
=xp
[j
][2]+tmp2
*im2
;
189 } /* 17 ncons flops */
190 } /* nit*ncons*(35+9*nrec) flops */
192 * 24*ncons + 6*nrtot + nrec*(ncons+2*nrtot)
193 * + nit * (18*ncons + nrec*(ncons+2*nrtot) + 17 ncons)
195 * (24+nrec)*ncons + (6+2*nrec)*nrtot
196 * + nit * ((35+nrec)*ncons + 2*nrec*nrtot)
198 * (59+nrec)*ncons + (6+4*nrec)*nrtot
202 void cconerr(real
*max
,real
*rms
,int *imax
,rvec
*xprime
,
203 int ncons
,int *bla1
,int *bla2
,real
*bllen
)
206 real len
,d
,ma
,ms
,tmp0
,tmp1
,tmp2
;
212 for(b
=0;b
<ncons
;b
++) {
215 tmp0
=xprime
[i
][0]-xprime
[j
][0];
216 tmp1
=xprime
[i
][1]-xprime
[j
][1];
217 tmp2
=xprime
[i
][2]-xprime
[j
][2];
218 len
=sqrt(tmp0
*tmp0
+tmp1
*tmp1
+tmp2
*tmp2
);
219 d
=fabs(len
/bllen
[b
]-1);
231 void lincs_warning(rvec
*x
,rvec
*xprime
,
232 int ncons
,int *bla1
,int *bla2
,real
*bllen
,real wangle
)
236 real wfac
,d0
,d1
,cosine
;
239 wfac
=cos(DEG2RAD
*wangle
);
241 sprintf(buf
,"bonds that rotated more than %g degrees:\n"
242 " atom 1 atom 2 angle previous, current, constraint length\n",
247 for(b
=0;b
<ncons
;b
++) {
250 rvec_sub(x
[i
],x
[j
],v0
);
251 rvec_sub(xprime
[i
],xprime
[j
],v1
);
254 cosine
=iprod(v0
,v1
)/(d0
*d1
);
256 sprintf(buf
," %6d %6d %5.1f %8.4f %8.4f %8.4f\n",
257 i
+1,j
+1,RAD2DEG
*acos(cosine
),d0
,d1
,bllen
[b
]);