# [gmx-developers] cg code

Graham Smith smithgr at cancer.org.uk
Tue May 28 21:45:20 CEST 2002

```Hi -

I was getting the error
Fatal error: ci = -2147483648 should be in 0 .. 799 [FILE nsgrid.c, LINE
210]

when doing a cg minimization and traced it to a numerical overflow where w
is first assigned in do_cg in minimize.c (line 411). I managed to fix it,
though in my particular case it didn't help much as w^2 went negative a
few steps later and I had to move over to steepest decents anyway.

So

(a) it might be useful to know (though you probably do already) that the
ci = -2147483648 error, which I've seen a few times on the mailing lists,
can be a consequence of the coordinates x being set to -nan before a call
to do_force, which is what was happening in my case. Obviously the do_cg
overflow can't be the source of the errors that were reported when doing
steepest decents or md though.

(b) If you think it's worth modifying the code, this avoids the overflow:
(block at line 409+ of minimize.c)

real aoz, boz, abozz ;

/* find stepsize smin in interval a-b */
zet = 3.0 * (EpotA-EpotB) / (b-a) + gpa + gpb;
aoz = (gpa/zet) ;
boz = (gpb/zet) ;
abozz = aoz * boz ;
if (abozz > 1.0) {
fprintf(stderr,"Negative w^2: z^2 * %20.12e\n",1.0-abozz);
fprintf(stderr,"z= %20.12e\n",zet);
fprintf(stderr,"gpa= %20.12e, gpb= %20.12e\n",gpa,gpb);
fprintf(stderr,"a= %20.12e, b= %20.12e\n",a,b);
fprintf(stderr,"EpotA= %20.12e, EpotB= %20.12e\n",EpotA,EpotB);
fprintf(stderr,"Negative number for sqrt encountered (%f)\n",w);
fprintf(stderr,"Terminating minimization\n");
break;
}
w    = zet * sqrt(1.0-abozz);
smin = b - ((gpb+w-zet)*(b-a))/((gpb-gpa)+2.0*w);

########################################################################

Dr. Graham R. Smith, 		       Department of Biological Sciences,
Biomolecular Modelling Laboratory,     Biochemistry Building,
Cancer Research UK, 		       Imperial College of Science,
44 Lincoln's Inn Fields, 	        Technology & Medicine,
London WC2A 3PX,		       London SW7 2AZ,
U.K. 				       U.K.
Tel: +44-(0)20 7269 3348 	       Tel: +44-(0)20 7594 5737
email: graham.smith at cancer.org.uk
URL: http://www.bmm.icnet.uk/~smithgr

```