ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/branches/sync4pymol12/src/mengine/src/egeom.c
Revision: 93
Committed: Sat Jan 17 23:24:55 2009 UTC (13 years, 5 months ago) by wdelano
File size: 60082 byte(s)
Log Message:
branch created
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5
6 #include "energies.h"
7 #include "bonds_ff.h"
8 #include "derivs.h"
9 #include "hess.h"
10 #include "field.h"
11 #include "fix.h"
12
13 EXTERN struct t_minim_values {
14 int iprint, ndc, nconst;
15 float dielc;
16 } minim_values;
17 int find_bond(int,int);
18 int find_fixed_bond(int,int);
19 void egeom(void);
20 void egeom1(void);
21 void egeom2(int);
22
23 // ============================================
24 void egeom()
25 {
26 int i;
27 int ia, ib, ic, id;
28 double xr, yr, zr, rik, rik2;
29 double xia,yia,zia, xib,yib,zib, xic,yic,zic, xid,yid,zid;
30 double xab,yab,zab, xcb,ycb,zcb, rab2,rcb2, rcb;
31 double dot, cosine,angle, af1, af2;
32 double xba,yba,zba, xdc,ydc,zdc, xt,yt,zt,xu,yu,zu;
33 double xtu,ytu,ztu, rt2, ru2, rtru, sine, tf1,tf2;
34 double t1, t2, df1, df2,target;
35 double dt, dt2, e;
36
37 if (minim_values.iprint)
38 {
39 fprintf(pcmlogfile,"\nFixed Distance Terms \n");
40 fprintf(pcmlogfile," At1 At2 R BLen Bconst Eb\n");
41 }
42 // restrained atoms
43 for (i=0; i < restrain_atom.natom_restrain; i++)
44 {
45 ia = restrain_atom.katom_restrain[i];
46 if (atom[ia].use)
47 {
48 xr = yr = zr = 0.0;
49 xr = atom[ia].x - restrain_atom.restrain_position[i][0];
50 yr = atom[ia].y - restrain_atom.restrain_position[i][1];
51 zr = atom[ia].z - restrain_atom.restrain_position[i][2];
52 dt2 = (xr*xr + yr*yr + zr*zr);
53 e = units.bndunit *restrain_atom.restrain_const[i]*dt2;
54 energies.egeom += e;
55 }
56 }
57 // fixed distances
58 for (i=0; i < fx_dist.ndfix; i++)
59 {
60 ia = fx_dist.kdfix[i][0];
61 ib = fx_dist.kdfix[i][1];
62 if ( atom[ia].use || atom[ib].use )
63 {
64 xr = atom[ia].x - atom[ib].x;
65 yr = atom[ia].y - atom[ib].y;
66 zr = atom[ia].z - atom[ib].z;
67 rik2 = xr*xr + yr*yr + zr*zr;
68 rik = sqrt(rik2);
69 df1 = fx_dist.min_dist[i];
70 df2 = fx_dist.max_dist[i];
71 target = rik;
72 if (rik < df1) target = df1;
73 if (rik > df2) target = df2;
74 dt = rik - target;
75
76 dt2 = dt*dt;
77 e = units.bndunit *fx_dist.fdconst[i]*dt2;
78
79 energies.egeom += e;
80 atom[ia].energy += e;
81 atom[ib].energy += e;
82 if (minim_values.iprint)
83 fprintf(pcmlogfile,"Fixed Dist: %2s(%-3d) - %2s(%-3d) %-8.3f %-8.3f %-8.3f %-8.3f = %-8.4f\n",atom[ia].name,ia,atom[ib].name
84 ,ib, rik, fx_dist.min_dist[i],fx_dist.max_dist[i], fx_dist.fdconst[i],e);
85 }
86 }
87 // fixed angle
88 for (i=0; i < fx_angle.nafix; i++)
89 {
90 ia = fx_angle.kafix[i][0];
91 ib = fx_angle.kafix[i][1];
92 ic = fx_angle.kafix[i][2];
93 if (atom[ia].use || atom[ib].use || atom[ic].use)
94 {
95 xia = atom[ia].x;
96 yia = atom[ia].y;
97 zia = atom[ia].z;
98 xib = atom[ib].x;
99 yib = atom[ib].y;
100 zib = atom[ib].z;
101 xic = atom[ic].x;
102 yic = atom[ic].y;
103 zic = atom[ic].z;
104 xab = xia - xib;
105 yab = yia - yib;
106 zab = zia - zib;
107 xcb = xic - xib;
108 ycb = yic - yib;
109 zcb = zic - zib;
110 rab2 = xab*xab + yab*yab + zab*zab;
111 rcb2 = xcb*xcb + ycb*ycb + zcb*zcb;
112 if (rab2 > 0.00001 && rcb2 > 0.00001)
113 {
114 dot = xab*xcb + yab*ycb + zab*zcb;
115 cosine = dot /sqrt(rab2*rcb2);
116 if (cosine > 1.0)
117 cosine = 1.0;
118 if (cosine < -1.0)
119 cosine = -1.0;
120 angle = radian*acos(cosine);
121 af1 = fx_angle.min_ang[i];
122 af2 = fx_angle.max_ang[i];
123 target = angle;
124 if (angle < af1) target = af1;
125 if (angle > af2) target = af2;
126 dt = angle - target;
127 dt2 = dt*dt;
128 e = units.angunit*fx_angle.faconst[i]*dt2;
129 energies.egeom += e;
130 atom[ia].energy += e;
131 atom[ib].energy += e;
132 atom[ic].energy += e;
133 if (minim_values.iprint)
134 fprintf(pcmlogfile,"Fixed Angle: %2s(%-3d) - %2s(%-3d) %-8.3f %-8.3f %-8.3f %-8.3f = %-8.4f\n",atom[ia].name,ia,atom[ib].name
135 ,ib, atom[ic].name,ic, angle, fx_angle.min_ang[i],fx_angle.max_ang[i], fx_angle.faconst[i],e);
136 }
137 }
138 }
139 // fixed torsion
140 for (i=0; i < fx_torsion.ntfix; i++)
141 {
142 ia = fx_torsion.ktfix[i][0];
143 ib = fx_torsion.ktfix[i][1];
144 ic = fx_torsion.ktfix[i][2];
145 id = fx_torsion.ktfix[i][3];
146 if (atom[ia].use || atom[ib].use || atom[ic].use)
147 {
148 xia = atom[ia].x;
149 yia = atom[ia].y;
150 zia = atom[ia].z;
151 xib = atom[ib].x;
152 yib = atom[ib].y;
153 zib = atom[ib].z;
154 xic = atom[ic].x;
155 yic = atom[ic].y;
156 zic = atom[ic].z;
157 xid = atom[id].x;
158 yid = atom[id].y;
159 zid = atom[id].z;
160 xba = xib - xia;
161 yba = yib - yia;
162 zba = zib - zia;
163 xcb = xic - xib;
164 ycb = yic - yib;
165 zcb = zic - zib;
166 xdc = xid - xic;
167 ydc = yid - yic;
168 zdc = zid - zic;
169 xt = yba*zcb - ycb*zba;
170 yt = zba*xcb - zcb*xba;
171 zt = xba*ycb - xcb*yba;
172 xu = ycb*zdc - ydc*zcb;
173 yu = zcb*xdc - zdc*xcb;
174 zu = xcb*ydc - xdc*ycb;
175 xtu = yt*zu - yu*zt;
176 ytu = zt*xu - zu*xt;
177 ztu = xt*yu - xu*yt;
178 rt2 = xt*xt + yt*yt + zt*zt;
179 ru2 = xu*xu + yu*yu + zu*zu;
180 rtru = sqrt(rt2 * ru2);
181 if (rtru > 0.0001)
182 {
183 rcb = sqrt(xcb*xcb + ycb*ycb + zcb*zcb);
184 cosine = (xt*xu + yt*yu + zt*zu) / rtru;
185 sine = (xcb*xtu + ycb*ytu + zcb*ztu) / (rcb*rtru);
186 if (cosine > 1.0) cosine = 1.0;
187 if (cosine < -1.0) cosine = -1.0;
188 angle = radian*acos(cosine);
189 if (sine < 0.0) angle = -angle;
190 tf1 = fx_torsion.min_tor[i];
191 tf2 = fx_torsion.max_tor[i];
192 if (angle > tf1 && angle < tf2)
193 target = angle;
194 else if ( (angle > tf1) && (tf1 > tf2))
195 target = angle;
196 else if ( (angle < tf2) && (tf1 > tf2))
197 target = angle;
198 else
199 {
200 t1 = angle - tf1;
201 t2 = angle - tf2;
202 if (t1 > 180.0)
203 t1 -= 360.0;
204 else if (t1 < -180.0)
205 t1 += 360.0;
206 if (t2 > 180.0)
207 t2 -= 360.0;
208 else if (t2 < -180.0)
209 t2 += 360.0;
210 if (fabs(t1) < fabs(t2))
211 target = tf1;
212 else
213 target = tf2;
214 }
215 dt = angle - target;
216 if (dt > 180.0) dt -= 360.0;
217 if (dt < -180.0) dt += 360.0;
218 dt2 = dt*dt;
219 e = units.torsunit*dt2*fx_torsion.ftconst[i];
220 energies.egeom += e;
221 }
222 }
223 }
224 }
225 // =====================================================
226 void egeom1()
227 {
228 int i;
229 int ia, ib, ic, id;
230 double xr, yr, zr, rik, rik2;
231 double xia,yia,zia, xib,yib,zib, xic,yic,zic, xid,yid,zid;
232 double xab,yab,zab, xcb,ycb,zcb, rab2,rcb2, rcb;
233 double dot, cosine,angle, af1, af2;
234 double xba,yba,zba, xdc,ydc,zdc, xt,yt,zt,xu,yu,zu;
235 double xtu,ytu,ztu, rt2, ru2, rtru, sine, tf1,tf2;
236 double xp,yp,zp, rp, xca,yca,zca, xdb,ydb,zdb;
237 double t1, t2, df1, df2,target;
238 double dt, dt2, e;
239 double de, deddt, dedx, dedy,dedz, terma,termc;
240 double dedphi,dedxt,dedyt,dedzt,dedxu,dedyu,dedzu;
241 double dedxia,dedyia,dedzia;
242 double dedxib,dedyib,dedzib;
243 double dedxic,dedyic,dedzic;
244 double dedxid,dedyid,dedzid;
245
246 // restrained atoms
247 for (i=0; i < restrain_atom.natom_restrain; i++)
248 {
249 ia = restrain_atom.katom_restrain[i];
250 if (atom[ia].use)
251 {
252 xr = yr = zr = 0.0;
253 xr = atom[ia].x - restrain_atom.restrain_position[i][0];
254 yr = atom[ia].y - restrain_atom.restrain_position[i][1];
255 zr = atom[ia].z - restrain_atom.restrain_position[i][2];
256 rik2 = (xr*xr + yr*yr + zr*zr);
257 dt2 = rik2;
258 e = units.bndunit *restrain_atom.restrain_const[i]*dt2;
259 energies.egeom += e;
260
261 rik = sqrt(rik2);
262 dt = rik;
263 if (rik < 0.00001) rik = 1.0;
264 de = 2.0*units.bndunit *restrain_atom.restrain_const[i]*dt/rik;
265 dedx = de*xr;
266 dedy = de*yr;
267 dedz = de*zr;
268 deriv.degeom[ia][0] += dedx;
269 deriv.degeom[ia][1] += dedy;
270 deriv.degeom[ia][2] += dedz;
271 }
272 }
273 // fixed distances
274 for (i=0; i < fx_dist.ndfix; i++)
275 {
276 ia = fx_dist.kdfix[i][0];
277 ib = fx_dist.kdfix[i][1];
278 if ( atom[ia].use || atom[ib].use )
279 {
280 xr = atom[ia].x - atom[ib].x;
281 yr = atom[ia].y - atom[ib].y;
282 zr = atom[ia].z - atom[ib].z;
283 rik2 = xr*xr + yr*yr + zr*zr;
284 rik = sqrt(rik2);
285 df1 = fx_dist.min_dist[i];
286 df2 = fx_dist.max_dist[i];
287 target = rik;
288 if (rik < df1) target = df1;
289 if (rik > df2) target = df2;
290 dt = rik - target;
291
292 dt2 = dt*dt;
293 e = units.bndunit *fx_dist.fdconst[i]*dt2;
294 if (rik == 0.0) rik = 1.0;
295 energies.egeom += e;
296
297 de = 2.0*units.bndunit *fx_dist.fdconst[i]*dt/rik;
298 dedx = de*xr;
299 dedy = de*yr;
300 dedz = de*zr;
301 deriv.degeom[ia][0] += dedx;
302 deriv.degeom[ia][1] += dedy;
303 deriv.degeom[ia][2] += dedz;
304 deriv.degeom[ib][0] -= dedx;
305 deriv.degeom[ib][1] -= dedy;
306 deriv.degeom[ib][2] -= dedz;
307 }
308 }
309 // fixed angle
310 for (i=0; i < fx_angle.nafix; i++)
311 {
312 ia = fx_angle.kafix[i][0];
313 ib = fx_angle.kafix[i][1];
314 ic = fx_angle.kafix[i][2];
315 if (atom[ia].use || atom[ib].use || atom[ic].use)
316 {
317 xia = atom[ia].x;
318 yia = atom[ia].y;
319 zia = atom[ia].z;
320 xib = atom[ib].x;
321 yib = atom[ib].y;
322 zib = atom[ib].z;
323 xic = atom[ic].x;
324 yic = atom[ic].y;
325 zic = atom[ic].z;
326 xab = xia - xib;
327 yab = yia - yib;
328 zab = zia - zib;
329 xcb = xic - xib;
330 ycb = yic - yib;
331 zcb = zic - zib;
332 rab2 = xab*xab + yab*yab + zab*zab;
333 rcb2 = xcb*xcb + ycb*ycb + zcb*zcb;
334 if (rab2 > 0.00001 && rcb2 > 0.00001)
335 {
336 xp = ycb*zab - zcb*yab;
337 yp = zcb*xab - xcb*zab;
338 zp = xcb*yab - ycb*xab;
339 rp = sqrt(xp*xp + yp*yp + zp*zp);
340 if (rp < 0.00001) rp = 0.00001;
341 dot = xab*xcb + yab*ycb + zab*zcb;
342 cosine = dot /sqrt(rab2*rcb2);
343 if (cosine > 1.0)
344 cosine = 1.0;
345 if (cosine < -1.0)
346 cosine = -1.0;
347 angle = radian*acos(cosine);
348 af1 = fx_angle.min_ang[i];
349 af2 = fx_angle.max_ang[i];
350 target = angle;
351 if (angle < af1) target = af1;
352 if (angle > af2) target = af2;
353 dt = angle - target;
354 dt2 = dt*dt;
355 e = units.angunit*fx_angle.faconst[i]*dt2;
356 energies.egeom += e;
357
358 deddt = 2.0*units.angunit*fx_angle.faconst[i]*dt*radian;
359 terma = -deddt/(rab2*rp);
360 termc = deddt/(rcb2*rp);
361 dedxia = terma * (yab*zp-zab*yp);
362 dedyia = terma * (zab*xp-xab*zp);
363 dedzia = terma * (xab*yp-yab*xp);
364 dedxic = termc * (ycb*zp-zcb*yp);
365 dedyic = termc * (zcb*xp-xcb*zp);
366 dedzic = termc * (xcb*yp-ycb*xp);
367 dedxib = -dedxia - dedxic;
368 dedyib = -dedyia - dedyic;
369 dedzib = -dedzia - dedzic;
370 deriv.degeom[ia][0] += dedxia;
371 deriv.degeom[ia][1] += dedyia;
372 deriv.degeom[ia][2] += dedzia;
373 deriv.degeom[ib][0] += dedxib;
374 deriv.degeom[ib][1] += dedyib;
375 deriv.degeom[ib][2] += dedzib;
376 deriv.degeom[ic][0] += dedxic;
377 deriv.degeom[ic][1] += dedyic;
378 deriv.degeom[ic][2] += dedzic;
379 }
380 }
381 }
382 // fixed torsion
383 for (i=0; i < fx_torsion.ntfix; i++)
384 {
385 ia = fx_torsion.ktfix[i][0];
386 ib = fx_torsion.ktfix[i][1];
387 ic = fx_torsion.ktfix[i][2];
388 id = fx_torsion.ktfix[i][3];
389 if (atom[ia].use || atom[ib].use || atom[ic].use)
390 {
391 xia = atom[ia].x;
392 yia = atom[ia].y;
393 zia = atom[ia].z;
394 xib = atom[ib].x;
395 yib = atom[ib].y;
396 zib = atom[ib].z;
397 xic = atom[ic].x;
398 yic = atom[ic].y;
399 zic = atom[ic].z;
400 xid = atom[id].x;
401 yid = atom[id].y;
402 zid = atom[id].z;
403 xba = xib - xia;
404 yba = yib - yia;
405 zba = zib - zia;
406 xcb = xic - xib;
407 ycb = yic - yib;
408 zcb = zic - zib;
409 xdc = xid - xic;
410 ydc = yid - yic;
411 zdc = zid - zic;
412 xt = yba*zcb - ycb*zba;
413 yt = zba*xcb - zcb*xba;
414 zt = xba*ycb - xcb*yba;
415 xu = ycb*zdc - ydc*zcb;
416 yu = zcb*xdc - zdc*xcb;
417 zu = xcb*ydc - xdc*ycb;
418 xtu = yt*zu - yu*zt;
419 ytu = zt*xu - zu*xt;
420 ztu = xt*yu - xu*yt;
421 rt2 = xt*xt + yt*yt + zt*zt;
422 ru2 = xu*xu + yu*yu + zu*zu;
423 rtru = sqrt(rt2 * ru2);
424 if (rtru > 0.0001)
425 {
426 rcb = sqrt(xcb*xcb + ycb*ycb + zcb*zcb);
427 cosine = (xt*xu + yt*yu + zt*zu) / rtru;
428 sine = (xcb*xtu + ycb*ytu + zcb*ztu) / (rcb*rtru);
429 if (cosine > 1.0) cosine = 1.0;
430 if (cosine < -1.0) cosine = -1.0;
431 angle = radian*acos(cosine);
432 if (sine < 0.0) angle = -angle;
433 tf1 = fx_torsion.min_tor[i];
434 tf2 = fx_torsion.max_tor[i];
435 if (angle > tf1 && angle < tf2)
436 target = angle;
437 else if ( (angle > tf1) && (tf1 > tf2))
438 target = angle;
439 else if ( (angle < tf2) && (tf1 > tf2))
440 target = angle;
441 else
442 {
443 t1 = angle - tf1;
444 t2 = angle - tf2;
445 if (t1 > 180.0)
446 t1 -= 360.0;
447 else if (t1 < -180.0)
448 t1 += 360.0;
449 if (t2 > 180.0)
450 t2 -= 360.0;
451 else if (t2 < -180.0)
452 t2 += 360.0;
453 if (fabs(t1) < fabs(t2))
454 target = tf1;
455 else
456 target = tf2;
457 }
458 dt = angle - target;
459 if (dt > 180.0) dt -= 360.0;
460 if (dt < -180.0) dt += 360.0;
461 dt2 = dt*dt;
462 e = units.torsunit*dt2*fx_torsion.ftconst[i];
463 energies.egeom += e;
464
465 dedphi = 2.0*units.torsunit*fx_torsion.ftconst[i]*dt*radian;
466 xca = xic - xia;
467 yca = yic - yia;
468 zca = zic - zia;
469 xdb = xid - xib;
470 ydb = yid - yib;
471 zdb = zid - zib;
472 dedxt = dedphi * (yt*zcb - ycb*zt) / (rt2*rcb);
473 dedyt = dedphi * (zt*xcb - zcb*xt) / (rt2*rcb);
474 dedzt = dedphi * (xt*ycb - xcb*yt) / (rt2*rcb);
475 dedxu = -dedphi * (yu*zcb - ycb*zu) / (ru2*rcb);
476 dedyu = -dedphi * (zu*xcb - zcb*xu) / (ru2*rcb);
477 dedzu = -dedphi * (xu*ycb - xcb*yu) / (ru2*rcb);
478
479 dedxia = zcb*dedyt - ycb*dedzt;
480 dedyia = xcb*dedzt - zcb*dedxt;
481 dedzia = ycb*dedxt - xcb*dedyt;
482 dedxib = yca*dedzt - zca*dedyt + zdc*dedyu - ydc*dedzu;
483 dedyib = zca*dedxt - xca*dedzt + xdc*dedzu - zdc*dedxu;
484 dedzib = xca*dedyt - yca*dedxt + ydc*dedxu - xdc*dedyu;
485 dedxic = zba*dedyt - yba*dedzt + ydb*dedzu - zdb*dedyu;
486 dedyic = xba*dedzt - zba*dedxt + zdb*dedxu - xdb*dedzu;
487 dedzic = yba*dedxt - xba*dedyt + xdb*dedyu - ydb*dedxu;
488 dedxid = zcb*dedyu - ycb*dedzu;
489 dedyid = xcb*dedzu - zcb*dedxu;
490 dedzid = ycb*dedxu - xcb*dedyu;
491
492 deriv.degeom[ia][0] += dedxia;
493 deriv.degeom[ia][1] += dedyia;
494 deriv.degeom[ia][2] += dedzia;
495 deriv.degeom[ib][0] += dedxib;
496 deriv.degeom[ib][1] += dedyib;
497 deriv.degeom[ib][2] += dedzib;
498 deriv.degeom[ic][0] += dedxic;
499 deriv.degeom[ic][1] += dedyic;
500 deriv.degeom[ic][2] += dedzic;
501 deriv.degeom[id][0] += dedxid;
502 deriv.degeom[id][1] += dedyid;
503 deriv.degeom[id][2] += dedzid;
504 }
505 }
506 }
507 }
508 // ==========================================
509 void egeom2(int jatm)
510 {
511 int i,j, ia,ib,ic,id;
512 double xr, yr, zr, rik, rik2;
513 double xia,yia,zia, xib,yib,zib, xic,yic,zic, xid,yid,zid;
514 double xab,yab,zab, xcb,ycb,zcb, rab2,rcb2, rcb;
515 double dot, cosine,angle, af1, af2;
516 double xba,yba,zba, xdc,ydc,zdc, xt,yt,zt,xu,yu,zu;
517 double xtu,ytu,ztu, rt2, ru2, rtru, sine, tf1,tf2;
518 double xp,yp,zp, rp,rp2, xca,yca,zca, xdb,ydb,zdb;
519 double t1, t2, df1, df2,target;
520 double dt, dt2;
521 double de, deddt, terma,termc;
522 double dedphi;
523 double d2e[3][3], d2eddt2, d2edphi2;
524 double term,termx,termy,termz;
525 double xrab,yrab,zrab;
526 double xrcb,yrcb,zrcb;
527 double xabp,yabp,zabp;
528 double xcbp,ycbp,zcbp;
529 double ddtdxia,ddtdyia,ddtdzia;
530 double ddtdxib,ddtdyib,ddtdzib;
531 double ddtdxic,ddtdyic,ddtdzic;
532 double dphidxt,dphidyt,dphidzt;
533 double dphidxu,dphidyu,dphidzu;
534 double dphidxia,dphidyia,dphidzia;
535 double dphidxib,dphidyib,dphidzib;
536 double dphidxic,dphidyic,dphidzic;
537 double dphidxid,dphidyid,dphidzid;
538 double xycb2,xzcb2,yzcb2;
539 double rcbxt,rcbyt,rcbzt,rcbt2;
540 double rcbxu,rcbyu,rcbzu,rcbu2;
541 double dphidxibt,dphidyibt,dphidzibt;
542 double dphidxibu,dphidyibu,dphidzibu;
543 double dphidxict,dphidyict,dphidzict;
544 double dphidxicu,dphidyicu,dphidzicu;
545 double dxiaxia,dyiayia,dziazia;
546 double dxibxib,dyibyib,dzibzib;
547 double dxicxic,dyicyic,dziczic;
548 double dxidxid,dyidyid,dzidzid;
549 double dxiayia,dxiazia,dyiazia;
550 double dxibyib,dxibzib,dyibzib;
551 double dxicyic,dxiczic,dyiczic;
552 double dxidyid,dxidzid,dyidzid;
553 double dxiaxib,dxiayib,dxiazib;
554 double dyiaxib,dyiayib,dyiazib;
555 double dziaxib,dziayib,dziazib;
556 double dxiaxic,dxiayic,dxiazic;
557 double dyiaxic,dyiayic,dyiazic;
558 double dziaxic,dziayic,dziazic;
559 double dxiaxid,dxiayid,dxiazid;
560 double dyiaxid,dyiayid,dyiazid;
561 double dziaxid,dziayid,dziazid;
562 double dxibxia,dxibyia,dxibzia;
563 double dyibxia,dyibyia,dyibzia;
564 double dzibxia,dzibyia,dzibzia;
565 double dxibxic,dxibyic,dxibzic;
566 double dyibxic,dyibyic,dyibzic;
567 double dzibxic,dzibyic,dzibzic;
568 double dxibxid,dxibyid,dxibzid;
569 double dyibxid,dyibyid,dyibzid;
570 double dzibxid,dzibyid,dzibzid;
571 double dxicxid,dxicyid,dxiczid;
572 double dyicxid,dyicyid,dyiczid;
573 double dzicxid,dzicyid,dziczid;
574
575 // restrained atoms
576 for (i=0; i < restrain_atom.natom_restrain; i++)
577 {
578 ia = restrain_atom.katom_restrain[i];
579 if (ia == jatm && atom[ia].use)
580 {
581 xr = yr = zr = 0.0;
582 xr = atom[ia].x - restrain_atom.restrain_position[i][0];
583 yr = atom[ia].y - restrain_atom.restrain_position[i][1];
584 zr = atom[ia].z - restrain_atom.restrain_position[i][2];
585 rik2 = (xr*xr + yr*yr + zr*zr);
586 dt2 = rik2;
587 rik = sqrt(rik2);
588 dt = rik;
589 deddt = 2.0*units.bndunit *restrain_atom.restrain_const[i];
590 if (dt == 0.0) deddt = 0.0;
591 if (rik < 0.00001)
592 {
593 de = deddt;
594 term = 0.0;
595 } else
596 {
597 de = deddt *dt/rik;
598 term = (deddt-de)/rik2;
599 }
600 de = deddt*dt/rik;
601 term = (deddt-de) / rik2;
602 termx = term * xr;
603 termy = term * yr;
604 termz = term * zr;
605
606 d2e[0][0] = termx*xr + de;
607 d2e[0][1] = termx*yr;
608 d2e[0][2] = termx*zr;
609 d2e[1][0] = d2e[0][0];
610 d2e[1][1] = termy*yr + de;
611 d2e[1][2] = termy*zr;
612 d2e[2][0] = d2e[0][2];
613 d2e[2][1] = d2e[1][2];
614 d2e[2][2] = termz*zr + de;
615
616 for (j=0; j < 3; j++)
617 {
618 hess.hessx[ia][j] += d2e[j][0];
619 hess.hessy[ia][j] += d2e[j][1];
620 hess.hessz[ia][j] += d2e[j][2];
621 }
622 }
623 }
624 // fixed distance
625 for (i=0; i < fx_dist.ndfix; i++)
626 {
627 ia = fx_dist.kdfix[i][0];
628 ib = fx_dist.kdfix[i][1];
629 if ( jatm == ia || jatm == ib )
630 {
631 if (jatm == ib)
632 {
633 ib = ia;
634 ia = jatm;
635 }
636 xr = atom[ia].x - atom[ib].x;
637 yr = atom[ia].y - atom[ib].y;
638 zr = atom[ia].z - atom[ib].z;
639 rik2 = xr*xr + yr*yr + zr*zr;
640 rik = sqrt(rik2);
641 df1 = fx_dist.min_dist[i];
642 df2 = fx_dist.max_dist[i];
643 target = rik;
644 if (rik < df1) target = df1;
645 if (rik > df2) target = df2;
646 dt = rik - target;
647 dt2 = dt*dt;
648 deddt = 2.0*units.bndunit *fx_dist.fdconst[i];
649 if (dt == 0.0) deddt = 0.0;
650 if (rik < 0.00001)
651 {
652 rik = 0.0001;
653 rik2 = rik*rik;
654 }
655 de = deddt*dt/rik;
656 term = (deddt-de) / rik2;
657 termx = term * xr;
658 termy = term * yr;
659 termz = term * zr;
660
661 d2e[0][0] = termx*xr + de;
662 d2e[0][1] = termx*yr;
663 d2e[0][2] = termx*zr;
664 d2e[1][0] = d2e[0][0];
665 d2e[1][1] = termy*yr + de;
666 d2e[1][2] = termy*zr;
667 d2e[2][0] = d2e[0][2];
668 d2e[2][1] = d2e[1][2];
669 d2e[2][2] = termz*zr + de;
670
671 for (j=0; j < 3; j++)
672 {
673 hess.hessx[ia][j] += d2e[j][0];
674 hess.hessy[ia][j] += d2e[j][1];
675 hess.hessz[ia][j] += d2e[j][2];
676 hess.hessx[ib][j] -= d2e[j][0];
677 hess.hessy[ib][j] -= d2e[j][1];
678 hess.hessz[ib][j] -= d2e[j][2];
679 }
680 }
681 }
682 // fixed angle
683 for (i=0; i < fx_angle.nafix; i++)
684 {
685 ia = fx_angle.kafix[i][0];
686 ib = fx_angle.kafix[i][1];
687 ic = fx_angle.kafix[i][2];
688 if (ia == jatm || ib == jatm || ic == jatm)
689 {
690 xia = atom[ia].x;
691 yia = atom[ia].y;
692 zia = atom[ia].z;
693 xib = atom[ib].x;
694 yib = atom[ib].y;
695 zib = atom[ib].z;
696 xic = atom[ic].x;
697 yic = atom[ic].y;
698 zic = atom[ic].z;
699 xab = xia - xib;
700 yab = yia - yib;
701 zab = zia - zib;
702 xcb = xic - xib;
703 ycb = yic - yib;
704 zcb = zic - zib;
705 rab2 = xab*xab + yab*yab + zab*zab;
706 rcb2 = xcb*xcb + ycb*ycb + zcb*zcb;
707 if (rab2 > 0.00001 && rcb2 > 0.00001)
708 {
709 xp = ycb*zab - zcb*yab;
710 yp = zcb*xab - xcb*zab;
711 zp = xcb*yab - ycb*xab;
712 rp = sqrt(xp*xp + yp*yp + zp*zp);
713 if (rp < 0.00001) rp = 0.00001;
714 dot = xab*xcb + yab*ycb + zab*zcb;
715 cosine = dot /sqrt(rab2*rcb2);
716 if (cosine > 1.0)
717 cosine = 1.0;
718 if (cosine < -1.0)
719 cosine = -1.0;
720 angle = radian*acos(cosine);
721 af1 = fx_angle.min_ang[i];
722 af2 = fx_angle.max_ang[i];
723 target = angle;
724 if (angle < af1) target = af1;
725 if (angle > af2) target = af2;
726 dt = angle - target;
727 dt2 = dt*dt;
728 deddt = 2.0*units.angunit*fx_angle.faconst[i]*dt*radian;
729 d2eddt2 = 2.0*units.angunit*fx_angle.faconst[i]*radian*radian;
730 if (dt == 0.0) d2edphi2 = 0.0;
731
732 terma = -1.0/(rab2*rp);
733 termc = 1.0/(rcb2*rp);
734 ddtdxia = terma * (yab*zp-zab*yp);
735 ddtdyia = terma * (zab*xp-xab*zp);
736 ddtdzia = terma * (xab*yp-yab*xp);
737 ddtdxic = termc * (ycb*zp-zcb*yp);
738 ddtdyic = termc * (zcb*xp-xcb*zp);
739 ddtdzic = termc * (xcb*yp-ycb*xp);
740 ddtdxib = -ddtdxia - ddtdxic;
741 ddtdyib = -ddtdyia - ddtdyic;
742 ddtdzib = -ddtdzia - ddtdzic;
743 xrab = 2.00 * xab / rab2;
744 yrab = 2.00 * yab / rab2;
745 zrab = 2.00 * zab / rab2;
746 xrcb = 2.00 * xcb / rcb2;
747 yrcb = 2.00 * ycb / rcb2;
748 zrcb = 2.00 * zcb / rcb2;
749 rp2 = 1.00 / (rp*rp);
750 xabp = (yab*zp-zab*yp) * rp2;
751 yabp = (zab*xp-xab*zp) * rp2;
752 zabp = (xab*yp-yab*xp) * rp2;
753 xcbp = (ycb*zp-zcb*yp) * rp2;
754 ycbp = (zcb*xp-xcb*zp) * rp2;
755 zcbp = (xcb*yp-ycb*xp) * rp2;
756
757 dxiaxia = terma*(xab*xcb-dot) + ddtdxia*(xcbp-xrab);
758 dxiayia = terma*(zp+yab*xcb) + ddtdxia*(ycbp-yrab);
759 dxiazia = terma*(zab*xcb-yp) + ddtdxia*(zcbp-zrab);
760 dyiayia = terma*(yab*ycb-dot) + ddtdyia*(ycbp-yrab);
761 dyiazia = terma*(xp+zab*ycb) + ddtdyia*(zcbp-zrab);
762 dziazia = terma*(zab*zcb-dot) + ddtdzia*(zcbp-zrab);
763 dxicxic = termc*(dot-xab*xcb) - ddtdxic*(xabp+xrcb);
764 dxicyic = termc*(zp-ycb*xab) - ddtdxic*(yabp+yrcb);
765 dxiczic = -termc*(yp+zcb*xab) - ddtdxic*(zabp+zrcb);
766 dyicyic = termc*(dot-yab*ycb) - ddtdyic*(yabp+yrcb);
767 dyiczic = termc*(xp-zcb*yab) - ddtdyic*(zabp+zrcb);
768 dziczic = termc*(dot-zab*zcb) - ddtdzic*(zabp+zrcb);
769 dxiaxic = terma*(yab*yab+zab*zab) - ddtdxia*xabp;
770 dxiayic = -terma*xab*yab - ddtdxia*yabp;
771 dxiazic = -terma*xab*zab - ddtdxia*zabp;
772 dyiaxic = -terma*xab*yab - ddtdyia*xabp;
773 dyiayic = terma*(xab*xab+zab*zab) - ddtdyia*yabp;
774 dyiazic = -terma*yab*zab - ddtdyia*zabp;
775 dziaxic = -terma*xab*zab - ddtdzia*xabp;
776 dziayic = -terma*yab*zab - ddtdzia*yabp;
777 dziazic = terma*(xab*xab+yab*yab) - ddtdzia*zabp;
778
779 dxibxia = -dxiaxia - dxiaxic;
780 dxibyia = -dxiayia - dyiaxic;
781 dxibzia = -dxiazia - dziaxic;
782 dyibxia = -dxiayia - dxiayic;
783 dyibyia = -dyiayia - dyiayic;
784 dyibzia = -dyiazia - dziayic;
785 dzibxia = -dxiazia - dxiazic;
786 dzibyia = -dyiazia - dyiazic;
787 dzibzia = -dziazia - dziazic;
788 dxibxic = -dxicxic - dxiaxic;
789 dxibyic = -dxicyic - dxiayic;
790 dxibzic = -dxiczic - dxiazic;
791 dyibxic = -dxicyic - dyiaxic;
792 dyibyic = -dyicyic - dyiayic;
793 dyibzic = -dyiczic - dyiazic;
794 dzibxic = -dxiczic - dziaxic;
795 dzibyic = -dyiczic - dziayic;
796 dzibzic = -dziczic - dziazic;
797 dxibxib = -dxibxia - dxibxic;
798 dxibyib = -dxibyia - dxibyic;
799 dxibzib = -dxibzia - dxibzic;
800 dyibyib = -dyibyia - dyibyic;
801 dyibzib = -dyibzia - dyibzic;
802 dzibzib = -dzibzia - dzibzic;
803
804 if (ia == jatm)
805 {
806 hess.hessx[ia][0] += deddt*dxiaxia + d2eddt2*ddtdxia*ddtdxia;
807 hess.hessx[ia][1] += deddt*dxiayia + d2eddt2*ddtdxia*ddtdyia;
808 hess.hessx[ia][2] += deddt*dxiazia + d2eddt2*ddtdxia*ddtdzia;
809 hess.hessy[ia][0] += deddt*dxiayia + d2eddt2*ddtdyia*ddtdxia;
810 hess.hessy[ia][1] += deddt*dyiayia + d2eddt2*ddtdyia*ddtdyia;
811 hess.hessy[ia][2] += deddt*dyiazia + d2eddt2*ddtdyia*ddtdzia;
812 hess.hessz[ia][0] += deddt*dxiazia + d2eddt2*ddtdzia*ddtdxia;
813 hess.hessz[ia][1] += deddt*dyiazia + d2eddt2*ddtdzia*ddtdyia;
814 hess.hessz[ia][2] += deddt*dziazia + d2eddt2*ddtdzia*ddtdzia;
815 hess.hessx[ib][0] += deddt*dxibxia + d2eddt2*ddtdxia*ddtdxib;
816 hess.hessx[ib][1] += deddt*dyibxia + d2eddt2*ddtdxia*ddtdyib;
817 hess.hessx[ib][2] += deddt*dzibxia + d2eddt2*ddtdxia*ddtdzib;
818 hess.hessy[ib][0] += deddt*dxibyia + d2eddt2*ddtdyia*ddtdxib;
819 hess.hessy[ib][1] += deddt*dyibyia + d2eddt2*ddtdyia*ddtdyib;
820 hess.hessy[ib][2] += deddt*dzibyia + d2eddt2*ddtdyia*ddtdzib;
821 hess.hessz[ib][0] += deddt*dxibzia + d2eddt2*ddtdzia*ddtdxib;
822 hess.hessz[ib][1] += deddt*dyibzia + d2eddt2*ddtdzia*ddtdyib;
823 hess.hessz[ib][2] += deddt*dzibzia + d2eddt2*ddtdzia*ddtdzib;
824 hess.hessx[ic][0] += deddt*dxiaxic + d2eddt2*ddtdxia*ddtdxic;
825 hess.hessx[ic][1] += deddt*dxiayic + d2eddt2*ddtdxia*ddtdyic;
826 hess.hessx[ic][2] += deddt*dxiazic + d2eddt2*ddtdxia*ddtdzic;
827 hess.hessy[ic][0] += deddt*dyiaxic + d2eddt2*ddtdyia*ddtdxic;
828 hess.hessy[ic][1] += deddt*dyiayic + d2eddt2*ddtdyia*ddtdyic;
829 hess.hessy[ic][2] += deddt*dyiazic + d2eddt2*ddtdyia*ddtdzic;
830 hess.hessz[ic][0] += deddt*dziaxic + d2eddt2*ddtdzia*ddtdxic;
831 hess.hessz[ic][1] += deddt*dziayic + d2eddt2*ddtdzia*ddtdyic;
832 hess.hessz[ic][2] += deddt*dziazic + d2eddt2*ddtdzia*ddtdzic;
833 } else if (ib == jatm)
834 {
835 hess.hessx[ib][0] += deddt*dxibxib + d2eddt2*ddtdxib*ddtdxib;
836 hess.hessx[ib][1] += deddt*dxibyib + d2eddt2*ddtdxib*ddtdyib;
837 hess.hessx[ib][2] += deddt*dxibzib + d2eddt2*ddtdxib*ddtdzib;
838 hess.hessy[ib][0] += deddt*dxibyib + d2eddt2*ddtdyib*ddtdxib;
839 hess.hessy[ib][1] += deddt*dyibyib + d2eddt2*ddtdyib*ddtdyib;
840 hess.hessy[ib][2] += deddt*dyibzib + d2eddt2*ddtdyib*ddtdzib;
841 hess.hessz[ib][0] += deddt*dxibzib + d2eddt2*ddtdzib*ddtdxib;
842 hess.hessz[ib][1] += deddt*dyibzib + d2eddt2*ddtdzib*ddtdyib;
843 hess.hessz[ib][2] += deddt*dzibzib + d2eddt2*ddtdzib*ddtdzib;
844 hess.hessx[ia][0] += deddt*dxibxia + d2eddt2*ddtdxib*ddtdxia;
845 hess.hessx[ia][1] += deddt*dxibyia + d2eddt2*ddtdxib*ddtdyia;
846 hess.hessx[ia][2] += deddt*dxibzia + d2eddt2*ddtdxib*ddtdzia;
847 hess.hessy[ia][0] += deddt*dyibxia + d2eddt2*ddtdyib*ddtdxia;
848 hess.hessy[ia][1] += deddt*dyibyia + d2eddt2*ddtdyib*ddtdyia;
849 hess.hessy[ia][2] += deddt*dyibzia + d2eddt2*ddtdyib*ddtdzia;
850 hess.hessz[ia][0] += deddt*dzibxia + d2eddt2*ddtdzib*ddtdxia;
851 hess.hessz[ia][1] += deddt*dzibyia + d2eddt2*ddtdzib*ddtdyia;
852 hess.hessz[ia][2] += deddt*dzibzia + d2eddt2*ddtdzib*ddtdzia;
853 hess.hessx[ic][0] += deddt*dxibxic + d2eddt2*ddtdxib*ddtdxic;
854 hess.hessx[ic][1] += deddt*dxibyic + d2eddt2*ddtdxib*ddtdyic;
855 hess.hessx[ic][2] += deddt*dxibzic + d2eddt2*ddtdxib*ddtdzic;
856 hess.hessy[ic][0] += deddt*dyibxic + d2eddt2*ddtdyib*ddtdxic;
857 hess.hessy[ic][1] += deddt*dyibyic + d2eddt2*ddtdyib*ddtdyic;
858 hess.hessy[ic][2] += deddt*dyibzic + d2eddt2*ddtdyib*ddtdzic;
859 hess.hessz[ic][0] += deddt*dzibxic + d2eddt2*ddtdzib*ddtdxic;
860 hess.hessz[ic][1] += deddt*dzibyic + d2eddt2*ddtdzib*ddtdyic;
861 hess.hessz[ic][2] += deddt*dzibzic + d2eddt2*ddtdzib*ddtdzic;
862 }else if (ic == jatm)
863 {
864 hess.hessx[ic][0] += deddt*dxicxic + d2eddt2*ddtdxic*ddtdxic;
865 hess.hessx[ic][1] += deddt*dxicyic + d2eddt2*ddtdxic*ddtdyic;
866 hess.hessx[ic][2] += deddt*dxiczic + d2eddt2*ddtdxic*ddtdzic;
867 hess.hessy[ic][0] += deddt*dxicyic + d2eddt2*ddtdyic*ddtdxic;
868 hess.hessy[ic][1] += deddt*dyicyic + d2eddt2*ddtdyic*ddtdyic;
869 hess.hessy[ic][2] += deddt*dyiczic + d2eddt2*ddtdyic*ddtdzic;
870 hess.hessz[ic][0] += deddt*dxiczic + d2eddt2*ddtdzic*ddtdxic;
871 hess.hessz[ic][1] += deddt*dyiczic + d2eddt2*ddtdzic*ddtdyic;
872 hess.hessz[ic][2] += deddt*dziczic + d2eddt2*ddtdzic*ddtdzic;
873 hess.hessx[ib][0] += deddt*dxibxic + d2eddt2*ddtdxic*ddtdxib;
874 hess.hessx[ib][1] += deddt*dyibxic + d2eddt2*ddtdxic*ddtdyib;
875 hess.hessx[ib][2] += deddt*dzibxic + d2eddt2*ddtdxic*ddtdzib;
876 hess.hessy[ib][0] += deddt*dxibyic + d2eddt2*ddtdyic*ddtdxib;
877 hess.hessy[ib][1] += deddt*dyibyic + d2eddt2*ddtdyic*ddtdyib;
878 hess.hessy[ib][2] += deddt*dzibyic + d2eddt2*ddtdyic*ddtdzib;
879 hess.hessz[ib][0] += deddt*dxibzic + d2eddt2*ddtdzic*ddtdxib;
880 hess.hessz[ib][1] += deddt*dyibzic + d2eddt2*ddtdzic*ddtdyib;
881 hess.hessz[ib][2] += deddt*dzibzic + d2eddt2*ddtdzic*ddtdzib;
882 hess.hessx[ia][0] += deddt*dxiaxic + d2eddt2*ddtdxic*ddtdxia;
883 hess.hessx[ia][1] += deddt*dyiaxic + d2eddt2*ddtdxic*ddtdyia;
884 hess.hessx[ia][2] += deddt*dziaxic + d2eddt2*ddtdxic*ddtdzia;
885 hess.hessy[ia][0] += deddt*dxiayic + d2eddt2*ddtdyic*ddtdxia;
886 hess.hessy[ia][1] += deddt*dyiayic + d2eddt2*ddtdyic*ddtdyia;
887 hess.hessy[ia][2] += deddt*dziayic + d2eddt2*ddtdyic*ddtdzia;
888 hess.hessz[ia][0] += deddt*dxiazic + d2eddt2*ddtdzic*ddtdxia;
889 hess.hessz[ia][1] += deddt*dyiazic + d2eddt2*ddtdzic*ddtdyia;
890 hess.hessz[ia][2] += deddt*dziazic + d2eddt2*ddtdzic*ddtdzia;
891 }
892 }
893 }
894 }
895 // fixed torsion
896 for (i=0; i < fx_torsion.ntfix; i++)
897 {
898 ia = fx_torsion.ktfix[i][0];
899 ib = fx_torsion.ktfix[i][1];
900 ic = fx_torsion.ktfix[i][2];
901 id = fx_torsion.ktfix[i][3];
902 if (ia == jatm || ib == jatm || ic == jatm || id == jatm )
903 {
904 xia = atom[ia].x;
905 yia = atom[ia].y;
906 zia = atom[ia].z;
907 xib = atom[ib].x;
908 yib = atom[ib].y;
909 zib = atom[ib].z;
910 xic = atom[ic].x;
911 yic = atom[ic].y;
912 zic = atom[ic].z;
913 xid = atom[id].x;
914 yid = atom[id].y;
915 zid = atom[id].z;
916 xba = xib - xia;
917 yba = yib - yia;
918 zba = zib - zia;
919 xcb = xic - xib;
920 ycb = yic - yib;
921 zcb = zic - zib;
922 xdc = xid - xic;
923 ydc = yid - yic;
924 zdc = zid - zic;
925 xt = yba*zcb - ycb*zba;
926 yt = zba*xcb - zcb*xba;
927 zt = xba*ycb - xcb*yba;
928 xu = ycb*zdc - ydc*zcb;
929 yu = zcb*xdc - zdc*xcb;
930 zu = xcb*ydc - xdc*ycb;
931 xtu = yt*zu - yu*zt;
932 ytu = zt*xu - zu*xt;
933 ztu = xt*yu - xu*yt;
934 rt2 = xt*xt + yt*yt + zt*zt;
935 ru2 = xu*xu + yu*yu + zu*zu;
936 rtru = sqrt(rt2 * ru2);
937 if (rtru > 0.0001)
938 {
939 rcb = sqrt(xcb*xcb + ycb*ycb + zcb*zcb);
940 cosine = (xt*xu + yt*yu + zt*zu) / rtru;
941 sine = (xcb*xtu + ycb*ytu + zcb*ztu) / (rcb*rtru);
942 if (cosine > 1.0) cosine = 1.0;
943 if (cosine < -1.0) cosine = -1.0;
944 angle = radian*acos(cosine);
945 if (sine < 0.0) angle = -angle;
946 tf1 = fx_torsion.min_tor[i];
947 tf2 = fx_torsion.max_tor[i];
948 if (angle > tf1 && angle < tf2)
949 target = angle;
950 else if ( (angle > tf1) && (tf1 > tf2))
951 target = angle;
952 else if ( (angle < tf2) && (tf1 > tf2))
953 target = angle;
954 else
955 {
956 t1 = angle - tf1;
957 t2 = angle - tf2;
958 if (t1 > 180.0)
959 t1 -= 360.0;
960 else if (t1 < -180.0)
961 t1 += 360.0;
962 if (t2 > 180.0)
963 t2 -= 360.0;
964 else if (t2 < -180.0)
965 t2 += 360.0;
966 if (fabs(t1) < fabs(t2))
967 target = tf1;
968 else
969 target = tf2;
970 }
971 dt = angle - target;
972 if (dt > 180.0) dt -= 360.0;
973 if (dt < -180.0) dt += 360.0;
974 dt2 = dt*dt;
975 dedphi = 2.0*units.torsunit*fx_torsion.ftconst[i]*dt;
976 d2edphi2 = 2.0*units.torsunit*fx_torsion.ftconst[i]*radian*radian;
977 if (dt < 0.000001) d2edphi2 = 0.0;
978
979 xca = xic - xia;
980 yca = yic - yia;
981 zca = zic - zia;
982 xdb = xid - xib;
983 ydb = yid - yib;
984 zdb = zid - zib;
985 dphidxt = (yt*zcb - ycb*zt) / (rt2*rcb);
986 dphidyt = (zt*xcb - zcb*xt) / (rt2*rcb);
987 dphidzt = (xt*ycb - xcb*yt) / (rt2*rcb);
988 dphidxu = -(yu*zcb - ycb*zu) / (ru2*rcb);
989 dphidyu = -(zu*xcb - zcb*xu) / (ru2*rcb);
990 dphidzu = -(xu*ycb - xcb*yu) / (ru2*rcb);
991
992 xycb2 = xcb*xcb + ycb*ycb;
993 xzcb2 = xcb*xcb + zcb*zcb;
994 yzcb2 = ycb*ycb + zcb*zcb;
995 rcbxt = -2.00 * rcb * dphidxt;
996 rcbyt = -2.00 * rcb * dphidyt;
997 rcbzt = -2.00 * rcb * dphidzt;
998 rcbt2 = rcb * rt2;
999 rcbxu = 2.00 * rcb * dphidxu;
1000 rcbyu = 2.00 * rcb * dphidyu;
1001 rcbzu = 2.00 * rcb * dphidzu;
1002 rcbu2 = rcb * ru2;
1003 dphidxibt = yca*dphidzt - zca*dphidyt;
1004 dphidxibu = zdc*dphidyu - ydc*dphidzu;
1005 dphidyibt = zca*dphidxt - xca*dphidzt;
1006 dphidyibu = xdc*dphidzu - zdc*dphidxu;
1007 dphidzibt = xca*dphidyt - yca*dphidxt;
1008 dphidzibu = ydc*dphidxu - xdc*dphidyu;
1009 dphidxict = zba*dphidyt - yba*dphidzt;
1010 dphidxicu = ydb*dphidzu - zdb*dphidyu;
1011 dphidyict = xba*dphidzt - zba*dphidxt;
1012 dphidyicu = zdb*dphidxu - xdb*dphidzu;
1013 dphidzict = yba*dphidxt - xba*dphidyt;
1014 dphidzicu = xdb*dphidyu - ydb*dphidxu;
1015
1016 dphidxia = zcb*dphidyt - ycb*dphidzt;
1017 dphidyia = xcb*dphidzt - zcb*dphidxt;
1018 dphidzia = ycb*dphidxt - xcb*dphidyt;
1019 dphidxib = dphidxibt + dphidxibu;
1020 dphidyib = dphidyibt + dphidyibu;
1021 dphidzib = dphidzibt + dphidzibu;
1022 dphidxic = dphidxict + dphidxicu;
1023 dphidyic = dphidyict + dphidyicu;
1024 dphidzic = dphidzict + dphidzicu;
1025 dphidxid = zcb*dphidyu - ycb*dphidzu;
1026 dphidyid = xcb*dphidzu - zcb*dphidxu;
1027 dphidzid = ycb*dphidxu - xcb*dphidyu;
1028
1029 dxiaxia = rcbxt*dphidxia;
1030 dxiayia = rcbxt*dphidyia - zcb*rcb/rt2;
1031 dxiazia = rcbxt*dphidzia + ycb*rcb/rt2;
1032 dxiaxic = rcbxt*dphidxict + xcb*xt/rcbt2;
1033 dxiayic = rcbxt*dphidyict - dphidzt - (xba*zcb*xcb+zba*yzcb2)/rcbt2;
1034 dxiazic = rcbxt*dphidzict + dphidyt + (xba*ycb*xcb+yba*yzcb2)/rcbt2;
1035 dxiaxid = 0.00;
1036 dxiayid = 0.00;
1037 dxiazid = 0.00;
1038 dyiayia = rcbyt*dphidyia;
1039 dyiazia = rcbyt*dphidzia - xcb*rcb/rt2;
1040 dyiaxib = rcbyt*dphidxibt - dphidzt - (yca*zcb*ycb+zca*xzcb2)/rcbt2;
1041 dyiaxic = rcbyt*dphidxict + dphidzt + (yba*zcb*ycb+zba*xzcb2)/rcbt2;
1042 dyiayic = rcbyt*dphidyict + ycb*yt/rcbt2;
1043 dyiazic = rcbyt*dphidzict - dphidxt - (yba*xcb*ycb+xba*xzcb2)/rcbt2;
1044 dyiaxid = 0.00;
1045 dyiayid = 0.00;
1046 dyiazid = 0.00;
1047 dziazia = rcbzt*dphidzia;
1048 dziaxib = rcbzt*dphidxibt + dphidyt + (zca*ycb*zcb+yca*xycb2)/rcbt2;
1049 dziayib = rcbzt*dphidyibt - dphidxt - (zca*xcb*zcb+xca*xycb2)/rcbt2;
1050 dziaxic = rcbzt*dphidxict - dphidyt - (zba*ycb*zcb+yba*xycb2)/rcbt2;
1051 dziayic = rcbzt*dphidyict + dphidxt + (zba*xcb*zcb+xba*xycb2)/rcbt2;
1052 dziazic = rcbzt*dphidzict + zcb*zt/rcbt2;
1053 dziaxid = 0.00;
1054 dziayid = 0.00;
1055 dziazid = 0.00;
1056 dxibxic = -xcb*dphidxib/(rcb*rcb) - (yca*(zba*xcb+yt)-zca*(yba*xcb-zt))/rcbt2
1057 - 2.00*(yt*zba-yba*zt)*dphidxibt/rt2 - (zdc*(ydb*xcb+zu)-ydc*(zdb*xcb-yu))/rcbu2
1058 + 2.00*(yu*zdb-ydb*zu)*dphidxibu/ru2;
1059 dxibyic = -ycb*dphidxib/(rcb*rcb) + dphidzt + dphidzu
1060 - (yca*(zba*ycb-xt)+zca*(xba*xcb+zcb*zba))/rcbt2
1061 - 2.00*(zt*xba-zba*xt)*dphidxibt/rt2
1062 + (zdc*(xdb*xcb+zcb*zdb)+ydc*(zdb*ycb+xu))/rcbu2
1063 + 2.00*(zu*xdb-zdb*xu)*dphidxibu/ru2;
1064 dxibxid = rcbxu*dphidxibu + xcb*xu/rcbu2;
1065 dxibyid = rcbyu*dphidxibu - dphidzu - (ydc*zcb*ycb+zdc*xzcb2)/rcbu2;
1066 dxibzid = rcbzu*dphidxibu + dphidyu + (zdc*ycb*zcb+ydc*xycb2)/rcbu2;
1067 dyibzib = ycb*dphidzib/(rcb*rcb) - (xca*(xca*xcb+zcb*zca)+yca*(ycb*xca+zt))/rcbt2
1068 - 2.00*(xt*zca-xca*zt)*dphidzibt/rt2
1069 + (ydc*(xdc*ycb-zu)+xdc*(xdc*xcb+zcb*zdc))/rcbu2
1070 + 2.00*(xu*zdc-xdc*zu)*dphidzibu/ru2;
1071 dyibxic = -xcb*dphidyib/(rcb*rcb) - dphidzt - dphidzu + (xca*(zba*xcb+yt)+zca*(zba*zcb+ycb*yba))/rcbt2
1072 - 2.00*(yt*zba-yba*zt)*dphidyibt/rt2
1073 - (zdc*(zdb*zcb+ycb*ydb)+xdc*(zdb*xcb-yu))/rcbu2
1074 + 2.00*(yu*zdb-ydb*zu)*dphidyibu/ru2;
1075 dyibyic = -ycb*dphidyib/(rcb*rcb) - (zca*(xba*ycb+zt)-xca*(zba*ycb-xt))/rcbt2
1076 - 2.00*(zt*xba-zba*xt)*dphidyibt/rt2
1077 - (xdc*(zdb*ycb+xu)-zdc*(xdb*ycb-zu))/rcbu2
1078 + 2.00*(zu*xdb-zdb*xu)*dphidyibu/ru2;
1079 dyibxid = rcbxu*dphidyibu + dphidzu + (xdc*zcb*xcb+zdc*yzcb2)/rcbu2;
1080 dyibyid = rcbyu*dphidyibu + ycb*yu/rcbu2;
1081 dyibzid = rcbzu*dphidyibu - dphidxu - (zdc*xcb*zcb+xdc*xycb2)/rcbu2;
1082 dzibxic = -xcb*dphidzib/(rcb*rcb) + dphidyt + dphidyu - (xca*(yba*xcb-zt)+yca*(zba*zcb+ycb*yba))/rcbt2
1083 - 2.00*(yt*zba-yba*zt)*dphidzibt/rt2
1084 + (ydc*(zdb*zcb+ycb*ydb)+xdc*(ydb*xcb+zu))/rcbu2
1085 + 2.00*(yu*zdb-ydb*zu)*dphidzibu/ru2;
1086 dzibzic = -zcb*dphidzib/(rcb*rcb) - (xca*(yba*zcb+xt)-yca*(xba*zcb-yt))/rcbt2
1087 - 2.00*(xt*yba-xba*yt)*dphidzibt/rt2
1088 - (ydc*(xdb*zcb+yu)-xdc*(ydb*zcb-xu))/rcbu2
1089 + 2.00*(xu*ydb-xdb*yu)*dphidzibu/ru2;
1090 dzibxid = rcbxu*dphidzibu - dphidyu - (xdc*ycb*xcb+ydc*yzcb2)/rcbu2;
1091 dzibyid = rcbyu*dphidzibu + dphidxu + (ydc*xcb*ycb+xdc*xzcb2)/rcbu2;
1092 dzibzid = rcbzu*dphidzibu + zcb*zu/rcbu2;
1093 dxicxid = rcbxu*dphidxicu - xcb*(zdb*ycb-ydb*zcb)/rcbu2;
1094 dxicyid = rcbyu*dphidxicu + dphidzu + (ydb*zcb*ycb+zdb*xzcb2)/rcbu2;
1095 dxiczid = rcbzu*dphidxicu - dphidyu - (zdb*ycb*zcb+ydb*xycb2)/rcbu2;
1096 dyicxid = rcbxu*dphidyicu - dphidzu - (xdb*zcb*xcb+zdb*yzcb2)/rcbu2;
1097 dyicyid = rcbyu*dphidyicu - ycb*(xdb*zcb-zdb*xcb)/rcbu2;
1098 dyiczid = rcbzu*dphidyicu + dphidxu + (zdb*xcb*zcb+xdb*xycb2)/rcbu2;
1099 dzicxid = rcbxu*dphidzicu + dphidyu + (xdb*ycb*xcb+ydb*yzcb2)/rcbu2;
1100 dzicyid = rcbyu*dphidzicu - dphidxu - (ydb*xcb*ycb+xdb*xzcb2)/rcbu2;
1101 dziczid = rcbzu*dphidzicu - zcb*(ydb*xcb-xdb*ycb)/rcbu2;
1102 dxidxid = rcbxu*dphidxid;
1103 dxidyid = rcbxu*dphidyid + zcb*rcb/ru2;
1104 dxidzid = rcbxu*dphidzid - ycb*rcb/ru2;
1105 dyidyid = rcbyu*dphidyid;
1106 dyidzid = rcbyu*dphidzid + xcb*rcb/ru2;
1107 dzidzid = rcbzu*dphidzid;
1108
1109 dxiaxib = -dxiaxia - dxiaxic - dxiaxid;
1110 dxiayib = -dxiayia - dxiayic - dxiayid;
1111 dxiazib = -dxiazia - dxiazic - dxiazid;
1112 dyiayib = -dyiayia - dyiayic - dyiayid;
1113 dyiazib = -dyiazia - dyiazic - dyiazid;
1114 dziazib = -dziazia - dziazic - dziazid;
1115 dxibxib = -dxiaxib - dxibxic - dxibxid;
1116 dxibyib = -dyiaxib - dxibyic - dxibyid;
1117 dxibzib = -dxiazib - dzibxic - dzibxid;
1118 dxibzic = -dziaxib - dxibzib - dxibzid;
1119 dyibyib = -dyiayib - dyibyic - dyibyid;
1120 dyibzic = -dziayib - dyibzib - dyibzid;
1121 dzibzib = -dziazib - dzibzic - dzibzid;
1122 dzibyic = -dyiazib - dyibzib - dzibyid;
1123 dxicxic = -dxiaxic - dxibxic - dxicxid;
1124 dxicyic = -dyiaxic - dyibxic - dxicyid;
1125 dxiczic = -dziaxic - dzibxic - dxiczid;
1126 dyicyic = -dyiayic - dyibyic - dyicyid;
1127 dyiczic = -dziayic - dzibyic - dyiczid;
1128 dziczic = -dziazic - dzibzic - dziczid;
1129 if (jatm == ia)
1130 {
1131 hess.hessx[ia][0] += dedphi*dxiaxia + d2edphi2*dphidxia*dphidxia;
1132 hess.hessy[ia][0] += dedphi*dxiayia + d2edphi2*dphidxia*dphidyia;
1133 hess.hessz[ia][0] += dedphi*dxiazia + d2edphi2*dphidxia*dphidzia;
1134 hess.hessx[ia][1] += dedphi*dxiayia + d2edphi2*dphidxia*dphidyia;
1135 hess.hessy[ia][1] += dedphi*dyiayia + d2edphi2*dphidyia*dphidyia;
1136 hess.hessz[ia][1] += dedphi*dyiazia + d2edphi2*dphidyia*dphidzia;
1137 hess.hessx[ia][2] += dedphi*dxiazia + d2edphi2*dphidxia*dphidzia;
1138 hess.hessy[ia][2] += dedphi*dyiazia + d2edphi2*dphidyia*dphidzia;
1139 hess.hessz[ia][2] += dedphi*dziazia + d2edphi2*dphidzia*dphidzia;
1140 hess.hessx[ib][0] += dedphi*dxiaxib + d2edphi2*dphidxia*dphidxib;
1141 hess.hessy[ib][0] += dedphi*dyiaxib + d2edphi2*dphidyia*dphidxib;
1142 hess.hessz[ib][0] += dedphi*dziaxib + d2edphi2*dphidzia*dphidxib;
1143 hess.hessx[ib][1] += dedphi*dxiayib + d2edphi2*dphidxia*dphidyib;
1144 hess.hessy[ib][1] += dedphi*dyiayib + d2edphi2*dphidyia*dphidyib;
1145 hess.hessz[ib][1] += dedphi*dziayib + d2edphi2*dphidzia*dphidyib;
1146 hess.hessx[ib][2] += dedphi*dxiazib + d2edphi2*dphidxia*dphidzib;
1147 hess.hessy[ib][2] += dedphi*dyiazib + d2edphi2*dphidyia*dphidzib;
1148 hess.hessz[ib][2] += dedphi*dziazib + d2edphi2*dphidzia*dphidzib;
1149 hess.hessx[ic][0] += dedphi*dxiaxic + d2edphi2*dphidxia*dphidxic;
1150 hess.hessy[ic][0] += dedphi*dyiaxic + d2edphi2*dphidyia*dphidxic;
1151 hess.hessz[ic][0] += dedphi*dziaxic + d2edphi2*dphidzia*dphidxic;
1152 hess.hessx[ic][1] += dedphi*dxiayic + d2edphi2*dphidxia*dphidyic;
1153 hess.hessy[ic][1] += dedphi*dyiayic + d2edphi2*dphidyia*dphidyic;
1154 hess.hessz[ic][1] += dedphi*dziayic + d2edphi2*dphidzia*dphidyic;
1155 hess.hessx[ic][2] += dedphi*dxiazic + d2edphi2*dphidxia*dphidzic;
1156 hess.hessy[ic][2] += dedphi*dyiazic + d2edphi2*dphidyia*dphidzic;
1157 hess.hessz[ic][2] += dedphi*dziazic + d2edphi2*dphidzia*dphidzic;
1158 hess.hessx[id][0] += dedphi*dxiaxid + d2edphi2*dphidxia*dphidxid;
1159 hess.hessy[id][0] += dedphi*dyiaxid + d2edphi2*dphidyia*dphidxid;
1160 hess.hessz[id][0] += dedphi*dziaxid + d2edphi2*dphidzia*dphidxid;
1161 hess.hessx[id][1] += dedphi*dxiayid + d2edphi2*dphidxia*dphidyid;
1162 hess.hessy[id][1] += dedphi*dyiayid + d2edphi2*dphidyia*dphidyid;
1163 hess.hessz[id][1] += dedphi*dziayid + d2edphi2*dphidzia*dphidyid;
1164 hess.hessx[id][2] += dedphi*dxiazid + d2edphi2*dphidxia*dphidzid;
1165 hess.hessy[id][2] += dedphi*dyiazid + d2edphi2*dphidyia*dphidzid;
1166 hess.hessz[id][2] += dedphi*dziazid + d2edphi2*dphidzia*dphidzid;
1167 }else if (jatm == ib)
1168 {
1169 hess.hessx[ib][0] += dedphi*dxibxib + d2edphi2*dphidxib*dphidxib;
1170 hess.hessy[ib][0] += dedphi*dxibyib + d2edphi2*dphidxib*dphidyib;
1171 hess.hessz[ib][0] += dedphi*dxibzib + d2edphi2*dphidxib*dphidzib;
1172 hess.hessx[ib][1] += dedphi*dxibyib + d2edphi2*dphidxib*dphidyib;
1173 hess.hessy[ib][1] += dedphi*dyibyib + d2edphi2*dphidyib*dphidyib;
1174 hess.hessz[ib][1] += dedphi*dyibzib + d2edphi2*dphidyib*dphidzib;
1175 hess.hessx[ib][2] += dedphi*dxibzib + d2edphi2*dphidxib*dphidzib;
1176 hess.hessy[ib][2] += dedphi*dyibzib + d2edphi2*dphidyib*dphidzib;
1177 hess.hessz[ib][2] += dedphi*dzibzib + d2edphi2*dphidzib*dphidzib;
1178 hess.hessx[ia][0] += dedphi*dxiaxib + d2edphi2*dphidxib*dphidxia;
1179 hess.hessy[ia][0] += dedphi*dxiayib + d2edphi2*dphidyib*dphidxia;
1180 hess.hessz[ia][0] += dedphi*dxiazib + d2edphi2*dphidzib*dphidxia;
1181 hess.hessx[ia][1] += dedphi*dyiaxib + d2edphi2*dphidxib*dphidyia;
1182 hess.hessy[ia][1] += dedphi*dyiayib + d2edphi2*dphidyib*dphidyia;
1183 hess.hessz[ia][1] += dedphi*dyiazib + d2edphi2*dphidzib*dphidyia;
1184 hess.hessx[ia][2] += dedphi*dziaxib + d2edphi2*dphidxib*dphidzia;
1185 hess.hessy[ia][2] += dedphi*dziayib + d2edphi2*dphidyib*dphidzia;
1186 hess.hessz[ia][2] += dedphi*dziazib + d2edphi2*dphidzib*dphidzia;
1187 hess.hessx[ic][0] += dedphi*dxibxic + d2edphi2*dphidxib*dphidxic;
1188 hess.hessy[ic][0] += dedphi*dyibxic + d2edphi2*dphidyib*dphidxic;
1189 hess.hessz[ic][0] += dedphi*dzibxic + d2edphi2*dphidzib*dphidxic;
1190 hess.hessx[ic][1] += dedphi*dxibyic + d2edphi2*dphidxib*dphidyic;
1191 hess.hessy[ic][1] += dedphi*dyibyic + d2edphi2*dphidyib*dphidyic;
1192 hess.hessz[ic][1] += dedphi*dzibyic + d2edphi2*dphidzib*dphidyic;
1193 hess.hessx[ic][2] += dedphi*dxibzic + d2edphi2*dphidxib*dphidzic;
1194 hess.hessy[ic][2] += dedphi*dyibzic + d2edphi2*dphidyib*dphidzic;
1195 hess.hessz[ic][2] += dedphi*dzibzic + d2edphi2*dphidzib*dphidzic;
1196 hess.hessx[id][0] += dedphi*dxibxid + d2edphi2*dphidxib*dphidxid;
1197 hess.hessy[id][0] += dedphi*dyibxid + d2edphi2*dphidyib*dphidxid;
1198 hess.hessz[id][0] += dedphi*dzibxid + d2edphi2*dphidzib*dphidxid;
1199 hess.hessx[id][1] += dedphi*dxibyid + d2edphi2*dphidxib*dphidyid;
1200 hess.hessy[id][1] += dedphi*dyibyid + d2edphi2*dphidyib*dphidyid;
1201 hess.hessz[id][1] += dedphi*dzibyid + d2edphi2*dphidzib*dphidyid;
1202 hess.hessx[id][2] += dedphi*dxibzid + d2edphi2*dphidxib*dphidzid;
1203 hess.hessy[id][2] += dedphi*dyibzid + d2edphi2*dphidyib*dphidzid;
1204 hess.hessz[id][2] += dedphi*dzibzid + d2edphi2*dphidzib*dphidzid;
1205 }else if (jatm == ic)
1206 {
1207 hess.hessx[ic][0] += dedphi*dxicxic + d2edphi2*dphidxic*dphidxic;
1208 hess.hessy[ic][0] += dedphi*dxicyic + d2edphi2*dphidxic*dphidyic;
1209 hess.hessz[ic][0] += dedphi*dxiczic + d2edphi2*dphidxic*dphidzic;
1210 hess.hessx[ic][1] += dedphi*dxicyic + d2edphi2*dphidxic*dphidyic;
1211 hess.hessy[ic][1] += dedphi*dyicyic + d2edphi2*dphidyic*dphidyic;
1212 hess.hessz[ic][1] += dedphi*dyiczic + d2edphi2*dphidyic*dphidzic;
1213 hess.hessx[ic][2] += dedphi*dxiczic + d2edphi2*dphidxic*dphidzic;
1214 hess.hessy[ic][2] += dedphi*dyiczic + d2edphi2*dphidyic*dphidzic;
1215 hess.hessz[ic][2] += dedphi*dziczic + d2edphi2*dphidzic*dphidzic;
1216 hess.hessx[ia][0] += dedphi*dxiaxic + d2edphi2*dphidxic*dphidxia;
1217 hess.hessy[ia][0] += dedphi*dxiayic + d2edphi2*dphidyic*dphidxia;
1218 hess.hessz[ia][0] += dedphi*dxiazic + d2edphi2*dphidzic*dphidxia;
1219 hess.hessx[ia][1] += dedphi*dyiaxic + d2edphi2*dphidxic*dphidyia;
1220 hess.hessy[ia][1] += dedphi*dyiayic + d2edphi2*dphidyic*dphidyia;
1221 hess.hessz[ia][1] += dedphi*dyiazic + d2edphi2*dphidzic*dphidyia;
1222 hess.hessx[ia][2] += dedphi*dziaxic + d2edphi2*dphidxic*dphidzia;
1223 hess.hessy[ia][2] += dedphi*dziayic + d2edphi2*dphidyic*dphidzia;
1224 hess.hessz[ia][2] += dedphi*dziazic + d2edphi2*dphidzic*dphidzia;
1225 hess.hessx[ib][0] += dedphi*dxibxic + d2edphi2*dphidxic*dphidxib;
1226 hess.hessy[ib][0] += dedphi*dxibyic + d2edphi2*dphidyic*dphidxib;
1227 hess.hessz[ib][0] += dedphi*dxibzic + d2edphi2*dphidzic*dphidxib;
1228 hess.hessx[ib][1] += dedphi*dyibxic + d2edphi2*dphidxic*dphidyib;
1229 hess.hessy[ib][1] += dedphi*dyibyic + d2edphi2*dphidyic*dphidyib;
1230 hess.hessz[ib][1] += dedphi*dyibzic + d2edphi2*dphidzic*dphidyib;
1231 hess.hessx[ib][2] += dedphi*dzibxic + d2edphi2*dphidxic*dphidzib;
1232 hess.hessy[ib][2] += dedphi*dzibyic + d2edphi2*dphidyic*dphidzib;
1233 hess.hessz[ib][2] += dedphi*dzibzic + d2edphi2*dphidzic*dphidzib;
1234 hess.hessx[id][0] += dedphi*dxicxid + d2edphi2*dphidxic*dphidxid;
1235 hess.hessy[id][0] += dedphi*dyicxid + d2edphi2*dphidyic*dphidxid;
1236 hess.hessz[id][0] += dedphi*dzicxid + d2edphi2*dphidzic*dphidxid;
1237 hess.hessx[id][1] += dedphi*dxicyid + d2edphi2*dphidxic*dphidyid;
1238 hess.hessy[id][1] += dedphi*dyicyid + d2edphi2*dphidyic*dphidyid;
1239 hess.hessz[id][1] += dedphi*dzicyid + d2edphi2*dphidzic*dphidyid;
1240 hess.hessx[id][2] += dedphi*dxiczid + d2edphi2*dphidxic*dphidzid;
1241 hess.hessy[id][2] += dedphi*dyiczid + d2edphi2*dphidyic*dphidzid;
1242 hess.hessz[id][2] += dedphi*dziczid + d2edphi2*dphidzic*dphidzid;
1243 }else if (jatm == id)
1244 {
1245 hess.hessx[id][0] += dedphi*dxidxid + d2edphi2*dphidxid*dphidxid;
1246 hess.hessy[id][0] += dedphi*dxidyid + d2edphi2*dphidxid*dphidyid;
1247 hess.hessz[id][0] += dedphi*dxidzid + d2edphi2*dphidxid*dphidzid;
1248 hess.hessx[id][1] += dedphi*dxidyid + d2edphi2*dphidxid*dphidyid;
1249 hess.hessy[id][1] += dedphi*dyidyid + d2edphi2*dphidyid*dphidyid;
1250 hess.hessz[id][1] += dedphi*dyidzid + d2edphi2*dphidyid*dphidzid;
1251 hess.hessx[id][2] += dedphi*dxidzid + d2edphi2*dphidxid*dphidzid;
1252 hess.hessy[id][2] += dedphi*dyidzid + d2edphi2*dphidyid*dphidzid;
1253 hess.hessz[id][2] += dedphi*dzidzid + d2edphi2*dphidzid*dphidzid;
1254 hess.hessx[ia][0] += dedphi*dxiaxid + d2edphi2*dphidxid*dphidxia;
1255 hess.hessy[ia][0] += dedphi*dxiayid + d2edphi2*dphidyid*dphidxia;
1256 hess.hessz[ia][0] += dedphi*dxiazid + d2edphi2*dphidzid*dphidxia;
1257 hess.hessx[ia][1] += dedphi*dyiaxid + d2edphi2*dphidxid*dphidyia;
1258 hess.hessy[ia][1] += dedphi*dyiayid + d2edphi2*dphidyid*dphidyia;
1259 hess.hessz[ia][1] += dedphi*dyiazid + d2edphi2*dphidzid*dphidyia;
1260 hess.hessx[ia][2] += dedphi*dziaxid + d2edphi2*dphidxid*dphidzia;
1261 hess.hessy[ia][2] += dedphi*dziayid + d2edphi2*dphidyid*dphidzia;
1262 hess.hessz[ia][2] += dedphi*dziazid + d2edphi2*dphidzid*dphidzia;
1263 hess.hessx[ib][0] += dedphi*dxibxid + d2edphi2*dphidxid*dphidxib;
1264 hess.hessy[ib][0] += dedphi*dxibyid + d2edphi2*dphidyid*dphidxib;
1265 hess.hessz[ib][0] += dedphi*dxibzid + d2edphi2*dphidzid*dphidxib;
1266 hess.hessx[ib][1] += dedphi*dyibxid + d2edphi2*dphidxid*dphidyib;
1267 hess.hessy[ib][1] += dedphi*dyibyid + d2edphi2*dphidyid*dphidyib;
1268 hess.hessz[ib][1] += dedphi*dyibzid + d2edphi2*dphidzid*dphidyib;
1269 hess.hessx[ib][2] += dedphi*dzibxid + d2edphi2*dphidxid*dphidzib;
1270 hess.hessy[ib][2] += dedphi*dzibyid + d2edphi2*dphidyid*dphidzib;
1271 hess.hessz[ib][2] += dedphi*dzibzid + d2edphi2*dphidzid*dphidzib;
1272 hess.hessx[ic][0] += dedphi*dxicxid + d2edphi2*dphidxid*dphidxic;
1273 hess.hessy[ic][0] += dedphi*dxicyid + d2edphi2*dphidyid*dphidxic;
1274 hess.hessz[ic][0] += dedphi*dxiczid + d2edphi2*dphidzid*dphidxic;
1275 hess.hessx[ic][1] += dedphi*dyicxid + d2edphi2*dphidxid*dphidyic;
1276 hess.hessy[ic][1] += dedphi*dyicyid + d2edphi2*dphidyid*dphidyic;
1277 hess.hessz[ic][1] += dedphi*dyiczid + d2edphi2*dphidzid*dphidyic;
1278 hess.hessx[ic][2] += dedphi*dzicxid + d2edphi2*dphidxid*dphidzic;
1279 hess.hessy[ic][2] += dedphi*dzicyid + d2edphi2*dphidyid*dphidzic;
1280 hess.hessz[ic][2] += dedphi*dziczid + d2edphi2*dphidzid*dphidzic;
1281 }
1282 }
1283 }
1284 }
1285 }