/************************************************************************************************************* The MIT License Copyright (C) 2006-2019 David Dubbeldam, Sofia Calero, Thijs Vlugt, Donald E. Ellis, and Randall Q. Snurr. D.Dubbeldam@uva.nl http://www.uva.nl/profiel/d/u/d.dubbeldam/d.dubbeldam.html scaldia@upo.es http://www.upo.es/raspa/ t.j.h.vlugt@tudelft.nl http://homepage.tudelft.nl/v9k6y don-ellis@northwestern.edu http://dvworld.northwestern.edu/ snurr@northwestern.edu http://zeolites.cqe.northwestern.edu/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************************/ #include #include #include #include #include "potentials.h" #include "molecule.h" #include "cbmc.h" #include "utils.h" #include "internal_force.h" #include "ewald.h" #include "matrix.h" #include "spectra.h" #include "minimization.h" #include "rigid.h" REAL ReturnBondDistance(VECTOR posA,VECTOR posB) { VECTOR dr; REAL rr; dr.x=posA.x-posB.x; dr.y=posA.y-posB.y; dr.z=posA.z-posB.z; dr=ApplyBoundaryCondition(dr); rr=SQR(dr.x)+SQR(dr.y)+SQR(dr.z); return sqrt(rr); } REAL ReturnBendAngle(VECTOR posA,VECTOR posB,VECTOR posC) { REAL CosTheta; VECTOR e12,e32; REAL r12,r32; e12.x=posA.x-posB.x; e12.y=posA.y-posB.y; e12.z=posA.z-posB.z; e12=ApplyBoundaryCondition(e12); r12=sqrt(SQR(e12.x)+SQR(e12.y)+SQR(e12.z)); e12.x/=r12; e12.y/=r12; e12.z/=r12; e32.x=posC.x-posB.x; e32.y=posC.y-posB.y; e32.z=posC.z-posB.z; e32=ApplyBoundaryCondition(e32); r32=sqrt(SQR(e32.x)+SQR(e32.y)+SQR(e32.z)); e32.x/=r32; e32.y/=r32; e32.z/=r32; CosTheta=(e12.x*e32.x+e12.y*e32.y+e12.z*e32.z); return acos(CosTheta); } REAL ReturnDihedralAngle(VECTOR posA,VECTOR posB,VECTOR posC,VECTOR posD) { REAL rbc; VECTOR Dab,Dcb,Ddc,dr,ds; REAL dot_ab,dot_cd,r,s,sign; REAL CosPhi,Phi; VECTOR Pb,Pc; VECTOR vec_u,vec_v,vec_w; REAL u,w,v; vec_u.x=posB.x-posC.x; vec_u.y=posB.y-posC.y; vec_u.z=posB.z-posC.z; vec_u=ApplyBoundaryCondition(vec_u); u=sqrt(SQR(vec_u.x)+SQR(vec_u.y)+SQR(vec_u.z)); vec_v.x=posD.x-posC.x; vec_v.y=posD.y-posC.y; vec_v.z=posD.z-posC.z; vec_v=ApplyBoundaryCondition(vec_v); v=sqrt(SQR(vec_v.x)+SQR(vec_v.y)+SQR(vec_v.z)); vec_w.x=posA.x-posB.x; vec_w.y=posA.y-posB.y; vec_w.z=posA.z-posB.z; vec_w=ApplyBoundaryCondition(vec_w); w=sqrt(SQR(vec_w.x)+SQR(vec_w.y)+SQR(vec_w.z)); Dab.x=posA.x-posB.x; Dab.y=posA.y-posB.y; Dab.z=posA.z-posB.z; Dab=ApplyBoundaryCondition(Dab); Dcb.x=posC.x-posB.x; Dcb.y=posC.y-posB.y; Dcb.z=posC.z-posB.z; Dcb=ApplyBoundaryCondition(Dcb); rbc=sqrt(SQR(Dcb.x)+SQR(Dcb.y)+SQR(Dcb.z)); Dcb.x/=rbc; Dcb.y/=rbc; Dcb.z/=rbc; Ddc.x=posD.x-posC.x; Ddc.y=posD.y-posC.y; Ddc.z=posD.z-posC.z; Ddc=ApplyBoundaryCondition(Ddc); dot_ab=Dab.x*Dcb.x+Dab.y*Dcb.y+Dab.z*Dcb.z; dot_cd=Ddc.x*Dcb.x+Ddc.y*Dcb.y+Ddc.z*Dcb.z; dr.x=Dab.x-dot_ab*Dcb.x; dr.y=Dab.y-dot_ab*Dcb.y; dr.z=Dab.z-dot_ab*Dcb.z; r=sqrt(SQR(dr.x)+SQR(dr.y)+SQR(dr.z)); dr.x/=r; dr.y/=r; dr.z/=r; ds.x=Ddc.x-dot_cd*Dcb.x; ds.y=Ddc.y-dot_cd*Dcb.y; ds.z=Ddc.z-dot_cd*Dcb.z; s=sqrt(SQR(ds.x)+SQR(ds.y)+SQR(ds.z)); ds.x/=s; ds.y/=s; ds.z/=s; // compute Cos(Phi) // Phi is defined in protein convention Phi(trans)=Pi CosPhi=dr.x*ds.x+dr.y*ds.y+dr.z*ds.z; // Ensure CosPhi is between -1 and 1. CosPhi=SIGN(MIN2(fabs(CosPhi),(REAL)1.0),CosPhi); // potential defined in terms of 'phi' and therefore contains a singularity // the sign of the angle-phi is positive if (Rab x Rbc) x (Rbc x Rcd) is in the // same direction as Rbc, and negative otherwise Pb.x=Dab.z*Dcb.y-Dab.y*Dcb.z; Pb.y=Dab.x*Dcb.z-Dab.z*Dcb.x; Pb.z=Dab.y*Dcb.x-Dab.x*Dcb.y; Pc.x=Dcb.y*Ddc.z-Dcb.z*Ddc.y; Pc.y=Dcb.z*Ddc.x-Dcb.x*Ddc.z; Pc.z=Dcb.x*Ddc.y-Dcb.y*Ddc.x; sign=(Dcb.x*(Pc.z*Pb.y-Pc.y*Pb.z)+Dcb.y*(Pb.z*Pc.x-Pb.x*Pc.z) +Dcb.z*(Pc.y*Pb.x-Pc.x*Pb.y)); Phi=SIGN(acos(CosPhi),sign); return Phi; } REAL ReturnInversionBendAngle(VECTOR posA,VECTOR posB,VECTOR posC,VECTOR posD) { REAL r; VECTOR cross_product_dc,cross_product_ad,cross_product_ca; REAL dot_product; VECTOR Dab,Dcb,Ddb; REAL ChiA,ChiC,ChiD; Dab.x=posA.x-posB.x; Dab.y=posA.y-posB.y; Dab.z=posA.z-posB.z; Dab=ApplyBoundaryCondition(Dab); r=sqrt(SQR(Dab.x)+SQR(Dab.y)+SQR(Dab.z)); Dab.x/=r; Dab.y/=r; Dab.z/=r; Dcb.x=posC.x-posB.x; Dcb.y=posC.y-posB.y; Dcb.z=posC.z-posB.z; Dcb=ApplyBoundaryCondition(Dcb); r=sqrt(SQR(Dcb.x)+SQR(Dcb.y)+SQR(Dcb.z)); Dcb.x/=r; Dcb.y/=r; Dcb.z/=r; Ddb.x=posD.x-posB.x; Ddb.y=posD.y-posB.y; Ddb.z=posD.z-posB.z; Ddb=ApplyBoundaryCondition(Ddb); r=sqrt(SQR(Ddb.x)+SQR(Ddb.y)+SQR(Ddb.z)); Ddb.x/=r; Ddb.y/=r; Ddb.z/=r; cross_product_dc.x=Ddb.y*Dcb.z-Ddb.z*Dcb.y; cross_product_dc.y=Ddb.z*Dcb.x-Ddb.x*Dcb.z; cross_product_dc.z=Ddb.x*Dcb.y-Ddb.y*Dcb.x; dot_product=cross_product_dc.x*Dab.x+cross_product_dc.y*Dab.y+cross_product_dc.z*Dab.z; ChiA=asin(dot_product/sin(ReturnBendAngle(posC,posB,posD))); cross_product_ad.x=Dab.y*Ddb.z-Dab.z*Ddb.y; cross_product_ad.y=Dab.z*Ddb.x-Dab.x*Ddb.z; cross_product_ad.z=Dab.x*Ddb.y-Dab.y*Ddb.x; dot_product=cross_product_ad.x*Dcb.x+cross_product_ad.y*Dcb.y+cross_product_ad.z*Dcb.z; ChiC=asin(dot_product/sin(ReturnBendAngle(posA,posB,posD))); cross_product_ca.x=Dcb.y*Dab.z-Dcb.z*Dab.y; cross_product_ca.y=Dcb.z*Dab.x-Dcb.x*Dab.z; cross_product_ca.z=Dcb.x*Dab.y-Dcb.y*Dab.x; dot_product=cross_product_ca.x*Ddb.x+cross_product_ca.y*Ddb.y+cross_product_ca.z*Ddb.z; ChiD=asin(dot_product/sin(ReturnBendAngle(posA,posB,posC))); //return (ChiA+ChiC+ChiD)/3.0; return ChiA; } REAL ReturnOutOfPlaneDistance(VECTOR posA,VECTOR posB,VECTOR posC,VECTOR posD) { return 0.0; } // the Wilson vectors are the conversion from internal bond-distance derivative to Cartesian derivatives: d\phi\dr_{1,2} void ReturnWilsonVectorsBond(VECTOR posA,VECTOR posB,VECTOR *wa,VECTOR *wb) { VECTOR e12; REAL r12; e12.x=posA.x-posB.x; e12.y=posA.y-posB.y; e12.z=posA.z-posB.z; e12=ApplyBoundaryCondition(e12); r12=sqrt(SQR(e12.x)+SQR(e12.y)+SQR(e12.z)); e12.x/=r12; e12.y/=r12; e12.z/=r12; wa->x=e12.x; wa->y=e12.y; wa->z=e12.z; wb->x=-e12.x; wb->y=-e12.y; wb->z=-e12.z; } // the Wilson vectors are the conversion from internal theta-angle derivative to Cartesian derivatives: d\phi\dr_{1,2,3} void ReturnWilsonVectorsBend(VECTOR posA,VECTOR posB,VECTOR posC,VECTOR *wa,VECTOR *wb,VECTOR *wc) { VECTOR dtA,dtB,dtC; VECTOR e12,e32; REAL r12,r32; REAL CosTheta,SinTheta; e12.x=posA.x-posB.x; e12.y=posA.y-posB.y; e12.z=posA.z-posB.z; e12=ApplyBoundaryCondition(e12); r12=sqrt(SQR(e12.x)+SQR(e12.y)+SQR(e12.z)); e12.x/=r12; e12.y/=r12; e12.z/=r12; e32.x=posC.x-posB.x; e32.y=posC.y-posB.y; e32.z=posC.z-posB.z; e32=ApplyBoundaryCondition(e32); r32=sqrt(SQR(e32.x)+SQR(e32.y)+SQR(e32.z)); e32.x/=r32; e32.y/=r32; e32.z/=r32; CosTheta=(e12.x*e32.x+e12.y*e32.y+e12.z*e32.z); SinTheta=MAX2((REAL)1.0e-8,sqrt(1.0-SQR(CosTheta))); // Calculate the components of the derivatives. dtA.x=(CosTheta*e12.x-e32.x)/(r12*SinTheta); dtA.y=(CosTheta*e12.y-e32.y)/(r12*SinTheta); dtA.z=(CosTheta*e12.z-e32.z)/(r12*SinTheta); dtC.x=(CosTheta*e32.x-e12.x)/(r32*SinTheta); dtC.y=(CosTheta*e32.y-e12.y)/(r32*SinTheta); dtC.z=(CosTheta*e32.z-e12.z)/(r32*SinTheta); dtB.x=-(dtA.x+dtC.x); dtB.y=-(dtA.y+dtC.y); dtB.z=-(dtA.z+dtC.z); wa->x=dtA.x; wa->y=dtA.y; wa->z=dtA.z; wb->x=dtB.x; wb->y=dtB.y; wb->z=dtB.z; wc->x=dtC.x; wc->y=dtC.y; wc->z=dtC.z; } // the Wilson vectors are the conversion from internal phi-angle derivative to Cartesian derivatives: d\phi\dr_{1,2,3,4} void ReturnWilsonVectorsTorsion(VECTOR posA,VECTOR posB,VECTOR posC,VECTOR posD,VECTOR *wa,VECTOR *wb,VECTOR *wc,VECTOR *wd) { REAL CosTheta1,CosTheta2; REAL SinTheta1,SinTheta2; VECTOR e12,e23,e32,e34,e43; REAL r12,r23,r34,temp1,temp2; e12.x=posB.x-posA.x; e12.y=posB.y-posA.y; e12.z=posB.z-posA.z; e12=ApplyBoundaryCondition(e12); r12=sqrt(SQR(e12.x)+SQR(e12.y)+SQR(e12.z)); e12.x/=r12; e12.y/=r12; e12.z/=r12; e23.x=posC.x-posB.x; e23.y=posC.y-posB.y; e23.z=posC.z-posB.z; e23=ApplyBoundaryCondition(e23); r23=sqrt(SQR(e23.x)+SQR(e23.y)+SQR(e23.z)); e23.x/=r23; e23.y/=r23; e23.z/=r23; e32.x=-e23.x; e32.y=-e23.y; e32.z=-e23.z; e34.x=posD.x-posC.x; e34.y=posD.y-posC.y; e34.z=posD.z-posC.z; e34=ApplyBoundaryCondition(e34); r34=sqrt(SQR(e34.x)+SQR(e34.y)+SQR(e34.z)); e34.x/=r34; e34.y/=r34; e34.z/=r34; e43.x=-e34.x; e43.y=-e34.y; e43.z=-e34.z; CosTheta1=(e12.x*e32.x+e12.y*e32.y+e12.z*e32.z); SinTheta1=MAX2((REAL)1.0e-8,sqrt(1.0-SQR(CosTheta1))); CosTheta2=(e23.x*e43.x+e23.y*e43.y+e23.z*e43.z); SinTheta2=MAX2((REAL)1.0e-8,sqrt(1.0-SQR(CosTheta2))); temp1=1.0/(r12*SQR(SinTheta1)); wa->x=-temp1*(e12.y*e23.z-e12.z*e23.y); wa->y=-temp1*(e12.z*e23.x-e12.x*e23.z); wa->z=-temp1*(e12.x*e23.y-e12.y*e23.x); temp1=(r23-r12*CosTheta1)/(r23*r12*SQR(SinTheta1)); temp2=CosTheta2/(r23*SQR(SinTheta2)); wb->x=temp1*(e12.y*e23.z-e12.z*e23.y)+temp2*(e43.y*e32.z-e43.z*e32.y); wb->y=temp1*(e12.z*e23.x-e12.x*e23.z)+temp2*(e43.z*e32.x-e43.x*e32.z); wb->z=temp1*(e12.x*e23.y-e12.y*e23.x)+temp2*(e43.x*e32.y-e43.y*e32.x); temp1=(r23-r34*CosTheta2)/(r23*r34*SQR(SinTheta2)); temp2=CosTheta1/(r23*SQR(SinTheta1)); wc->x=temp1*(e43.y*e32.z-e43.z*e32.y)+temp2*(e12.y*e23.z-e12.z*e23.y); wc->y=temp1*(e43.z*e32.x-e43.x*e32.z)+temp2*(e12.z*e23.x-e12.x*e23.z); wc->z=temp1*(e43.x*e32.y-e43.y*e32.x)+temp2*(e12.x*e23.y-e12.y*e23.x); temp1=1.0/(r34*SQR(SinTheta2)); wd->x=-temp1*(e43.y*e32.z-e43.z*e32.y); wd->y=-temp1*(e43.z*e32.x-e43.x*e32.z); wd->z=-temp1*(e43.x*e32.y-e43.y*e32.x); } void ReturnWilsonVectorsInversionBend(VECTOR posA,VECTOR posB,VECTOR posC,VECTOR posD,VECTOR *wa,VECTOR *wb,VECTOR *wc,VECTOR *wd) { REAL rab,rbc,rbd; VECTOR cross_product_dc,cross_product_ad,cross_product_ca; REAL dot_product; REAL ThetaA,SinThetaA,CosThetaA,ChiA,CosChiA,TanChiA; REAL ThetaC,SinThetaC,CosThetaC,ChiC,CosChiC,TanChiC; REAL ThetaD,SinThetaD,CosThetaD,ChiD,CosChiD,TanChiD; VECTOR Dab,Dcb,Ddb; Dab.x=posA.x-posB.x; Dab.y=posA.y-posB.y; Dab.z=posA.z-posB.z; Dab=ApplyBoundaryCondition(Dab); rab=sqrt(SQR(Dab.x)+SQR(Dab.y)+SQR(Dab.z)); Dab.x/=rab; Dab.y/=rab; Dab.z/=rab; Dcb.x=posC.x-posB.x; Dcb.y=posC.y-posB.y; Dcb.z=posC.z-posB.z; Dcb=ApplyBoundaryCondition(Dcb); rbc=sqrt(SQR(Dcb.x)+SQR(Dcb.y)+SQR(Dcb.z)); Dcb.x/=rbc; Dcb.y/=rbc; Dcb.z/=rbc; Ddb.x=posD.x-posB.x; Ddb.y=posD.y-posB.y; Ddb.z=posD.z-posB.z; Ddb=ApplyBoundaryCondition(Ddb); rbd=sqrt(SQR(Ddb.x)+SQR(Ddb.y)+SQR(Ddb.z)); Ddb.x/=rbd; Ddb.y/=rbd; Ddb.z/=rbd; ThetaA=ReturnBendAngle(posC,posB,posD); CosThetaA=cos(ReturnBendAngle(posC,posB,posD)); SinThetaA=sin(ReturnBendAngle(posC,posB,posD)); ThetaC=ReturnBendAngle(posA,posB,posD); CosThetaC=cos(ReturnBendAngle(posA,posB,posD)); SinThetaC=sin(ReturnBendAngle(posA,posB,posD)); ThetaD=ReturnBendAngle(posA,posB,posC); CosThetaD=cos(ReturnBendAngle(posA,posB,posC)); SinThetaD=sin(ReturnBendAngle(posA,posB,posC)); cross_product_dc.x=Ddb.y*Dcb.z-Ddb.z*Dcb.y; cross_product_dc.y=Ddb.z*Dcb.x-Ddb.x*Dcb.z; cross_product_dc.z=Ddb.x*Dcb.y-Ddb.y*Dcb.x; dot_product=cross_product_dc.x*Dab.x+cross_product_dc.y*Dab.y+cross_product_dc.z*Dab.z; ChiA=asin(dot_product/SinThetaA); CosChiA=cos(ChiA); TanChiA=tan(ChiA); cross_product_ad.x=Dab.y*Ddb.z-Dab.z*Ddb.y; cross_product_ad.y=Dab.z*Ddb.x-Dab.x*Ddb.z; cross_product_ad.z=Dab.x*Ddb.y-Dab.y*Ddb.x; dot_product=cross_product_ad.x*Dcb.x+cross_product_ad.y*Dcb.y+cross_product_ad.z*Dcb.z; ChiC=asin(dot_product/sin(ReturnBendAngle(posA,posB,posD))); CosChiC=cos(ChiC); TanChiC=tan(ChiC); cross_product_ca.x=Dcb.y*Dab.z-Dcb.z*Dab.y; cross_product_ca.y=Dcb.z*Dab.x-Dcb.x*Dab.z; cross_product_ca.z=Dcb.x*Dab.y-Dcb.y*Dab.x; dot_product=cross_product_ca.x*Ddb.x+cross_product_ca.y*Ddb.y+cross_product_ca.z*Ddb.z; ChiD=asin(dot_product/sin(ReturnBendAngle(posA,posB,posC))); CosChiD=cos(ChiD); TanChiD=tan(ChiD); wa->x=(cross_product_dc.x/(CosChiA*SinThetaA)-Dab.x*TanChiA)/(3.0*rab); wa->y=(cross_product_dc.y/(CosChiA*SinThetaA)-Dab.y*TanChiA)/(3.0*rab); wa->z=(cross_product_dc.z/(CosChiA*SinThetaA)-Dab.z*TanChiA)/(3.0*rab); wc->x=(cross_product_ad.x/(CosChiA*SinThetaA)-(TanChiA/(SQR(SinThetaA)))*(Dcb.x-Ddb.x*CosThetaA))/(3.0*rbc); wc->y=(cross_product_ad.y/(CosChiA*SinThetaA)-(TanChiA/(SQR(SinThetaA)))*(Dcb.y-Ddb.y*CosThetaA))/(3.0*rbc); wc->z=(cross_product_ad.z/(CosChiA*SinThetaA)-(TanChiA/(SQR(SinThetaA)))*(Dcb.z-Ddb.z*CosThetaA))/(3.0*rbc); wd->x=(cross_product_ca.x/(CosChiA*SinThetaA)-(TanChiA/(SQR(SinThetaA)))*(Ddb.x-Dcb.x*CosThetaA))/(3.0*rbd); wd->y=(cross_product_ca.y/(CosChiA*SinThetaA)-(TanChiA/(SQR(SinThetaA)))*(Ddb.y-Dcb.y*CosThetaA))/(3.0*rbd); wd->z=(cross_product_ca.z/(CosChiA*SinThetaA)-(TanChiA/(SQR(SinThetaA)))*(Ddb.z-Dcb.z*CosThetaA))/(3.0*rbd); wc->x+=(cross_product_ad.x/(CosChiC*SinThetaC)-Dcb.x*TanChiC)/(3.0*rbc); wc->y+=(cross_product_ad.y/(CosChiC*SinThetaC)-Dcb.y*TanChiC)/(3.0*rbc); wc->z+=(cross_product_ad.z/(CosChiC*SinThetaC)-Dcb.z*TanChiC)/(3.0*rbc); wd->x+=(cross_product_ca.x/(CosChiC*SinThetaC)-(TanChiC/(SQR(SinThetaC)))*(Ddb.x-Dab.x*CosThetaC))/(3.0*rbd); wd->y+=(cross_product_ca.y/(CosChiC*SinThetaC)-(TanChiC/(SQR(SinThetaC)))*(Ddb.y-Dab.y*CosThetaC))/(3.0*rbd); wd->z+=(cross_product_ca.z/(CosChiC*SinThetaC)-(TanChiC/(SQR(SinThetaC)))*(Ddb.z-Dab.z*CosThetaC))/(3.0*rbd); wa->x+=(cross_product_dc.x/(CosChiC*SinThetaC)-(TanChiC/(SQR(SinThetaC)))*(Dab.x-Ddb.x*CosThetaC))/(3.0*rab); wa->y+=(cross_product_dc.y/(CosChiC*SinThetaC)-(TanChiC/(SQR(SinThetaC)))*(Dab.y-Ddb.y*CosThetaC))/(3.0*rab); wa->z+=(cross_product_dc.z/(CosChiC*SinThetaC)-(TanChiC/(SQR(SinThetaC)))*(Dab.z-Ddb.z*CosThetaC))/(3.0*rab); wd->x+=(cross_product_ca.x/(CosChiD*SinThetaD)-Ddb.x*TanChiD)/(3.0*rbd); wd->y+=(cross_product_ca.y/(CosChiD*SinThetaD)-Ddb.y*TanChiD)/(3.0*rbd); wd->z+=(cross_product_ca.z/(CosChiD*SinThetaD)-Ddb.z*TanChiD)/(3.0*rbd); wa->x+=(cross_product_dc.x/(CosChiD*SinThetaD)-(TanChiD/(SQR(SinThetaD)))*(Dab.x-Dcb.x*CosThetaD))/(3.0*rab); wa->y+=(cross_product_dc.y/(CosChiD*SinThetaD)-(TanChiD/(SQR(SinThetaD)))*(Dab.y-Dcb.y*CosThetaD))/(3.0*rab); wa->z+=(cross_product_dc.z/(CosChiD*SinThetaD)-(TanChiD/(SQR(SinThetaD)))*(Dab.z-Dcb.z*CosThetaD))/(3.0*rab); wc->x+=(cross_product_ad.x/(CosChiD*SinThetaD)-(TanChiD/(SQR(SinThetaD)))*(Dcb.x-Dab.x*CosThetaD))/(3.0*rbc); wc->y+=(cross_product_ad.y/(CosChiD*SinThetaD)-(TanChiD/(SQR(SinThetaD)))*(Dcb.y-Dab.y*CosThetaD))/(3.0*rbc); wc->z+=(cross_product_ad.z/(CosChiD*SinThetaD)-(TanChiD/(SQR(SinThetaD)))*(Dcb.z-Dab.z*CosThetaD))/(3.0*rbc); wb->x=-(wa->x+wc->x+wd->x); wb->y=-(wa->y+wc->y+wd->y); wb->z=-(wa->z+wc->z+wd->z); } // Calculate Bondforce void CalculateAdsorbateBondForce(int m) { int i,Type,NumberOfBonds,A,B; REAL U,DF,r,rr,temp,temp2,exp_term,r1; REAL *parms; POINT posA,posB; VECTOR dr,f; Type=Adsorbates[CurrentSystem][m].Type; NumberOfBonds=Components[Type].NumberOfBonds; for(i=0;ip_2 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2 [A] r1=r-parms[1]; U=0.5*parms[0]*SQR(MIN2(fabs(r1),parms[2])) +parms[0]*parms[2]*MAX2(fabs(r1)-parms[2],(REAL)0.0); DF=-parms[0]*(SIGN(MIN2(fabs(r1),parms[2]),r1))/r; break; case QUARTIC_BOND: // (1/2)*p_0*(r-p_1)^2+(1/3)*p_2*(r-p_1)^3+(1/4)*p_3*(r-p_1)^4 // =========================================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=0.5*parms[0]*temp2+(1.0/3.0)*parms[2]*temp*temp2+0.25*parms[3]*SQR(temp2); DF=temp*(parms[0]+parms[2]*temp+parms[3]*temp2)/r; break; case CFF_QUARTIC_BOND: // p_0*(r-p_1)^2+p_2*(r-p_1)^3+p_3*(r-p_1)^4 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=parms[0]*temp2+parms[2]*temp*temp2+parms[3]*SQR(temp2); DF=temp*(2.0*parms[0]+3.0*parms[2]*temp+4.0*parms[3]*temp2)/r; break; case MM3_BOND: // p_0*(r-p_1)^2*(1.0-2.55*(r-p_1)+(7.0/12.0)*2.55^2*(r-p_1)^2) // ================================================================= // p_0 [mdyne/A molecule] // p_1 [A] temp=r-parms[1]; temp2=SQR(temp); U=parms[0]*temp2*(1.0-2.55*temp+(7.0/12.0)*SQR(2.55)*temp2); DF=parms[0]*(2.0+2.55*(4.0*2.55*(7.0/12.0)*temp-3.0)*temp)*temp/r; break; case RIGID_BOND: U=DF=0.0; break; case FIXED_BOND: U=DF=0.0; break; default: fprintf(stderr, "Undefined Bond potential in routine 'CalculateAdsorbateBondForce' ('internal_force.c')\n"); exit(0); break; } // add contribution to the Adsorbate stretch energy UAdsorbateBond[CurrentSystem]+=U; // forces are oppositely directed to the gradient f.x=-DF*dr.x; f.y=-DF*dr.y; f.z=-DF*dr.z; // add contribution to the forces Adsorbates[CurrentSystem][m].Atoms[A].Force.x+=f.x; Adsorbates[CurrentSystem][m].Atoms[A].Force.y+=f.y; Adsorbates[CurrentSystem][m].Atoms[A].Force.z+=f.z; Adsorbates[CurrentSystem][m].Atoms[B].Force.x-=f.x; Adsorbates[CurrentSystem][m].Atoms[B].Force.y-=f.y; Adsorbates[CurrentSystem][m].Atoms[B].Force.z-=f.z; // add contribution to the stress tensor StrainDerivativeTensor[CurrentSystem].ax-=dr.x*f.x; StrainDerivativeTensor[CurrentSystem].bx-=dr.y*f.x; StrainDerivativeTensor[CurrentSystem].cx-=dr.z*f.x; StrainDerivativeTensor[CurrentSystem].ay-=dr.x*f.y; StrainDerivativeTensor[CurrentSystem].by-=dr.y*f.y; StrainDerivativeTensor[CurrentSystem].cy-=dr.z*f.y; StrainDerivativeTensor[CurrentSystem].az-=dr.x*f.z; StrainDerivativeTensor[CurrentSystem].bz-=dr.y*f.z; StrainDerivativeTensor[CurrentSystem].cz-=dr.z*f.z; } } // Calculate Bondforce void CalculateCationBondForce(int m) { int i,Type,NumberOfBonds,A,B; REAL U,DF,r,rr,temp,temp2,exp_term,r1; REAL *parms; POINT posA,posB; VECTOR dr,f; Type=Cations[CurrentSystem][m].Type; NumberOfBonds=Components[Type].NumberOfBonds; for(i=0;ip_2 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2 [A] r1=r-parms[1]; U=0.5*parms[0]*SQR(MIN2(fabs(r1),parms[2])) +parms[0]*parms[2]*MAX2(fabs(r1)-parms[2],(REAL)0.0); DF=-parms[0]*(SIGN(MIN2(fabs(r1),parms[2]),r1))/r; break; case QUARTIC_BOND: // (1/2)*p_0*(r-p_1)^2+(1/3)*p_2*(r-p_1)^3+(1/4)*p_3*(r-p_1)^4 // =========================================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=0.5*parms[0]*temp2+(1.0/3.0)*parms[2]*temp*temp2+0.25*parms[3]*SQR(temp2); DF=temp*(parms[0]+parms[2]*temp+parms[3]*temp2)/r; break; case CFF_QUARTIC_BOND: // p_0*(r-p_1)^2+p_2*(r-p_1)^3+p_3*(r-p_1)^4 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=parms[0]*temp2+parms[2]*temp*temp2+parms[3]*SQR(temp2); DF=temp*(2.0*parms[0]+3.0*parms[2]*temp+4.0*parms[3]*temp2)/r; break; case MM3_BOND: // p_0*(r-p_1)^2*(1.0-2.55*(r-p_1)+(7.0/12.0)*2.55^2*(r-p_1)^2) // ================================================================= // p_0 [mdyne/A molecule] // p_1 [A] temp=r-parms[1]; temp2=SQR(temp); U=parms[0]*temp2*(1.0-2.55*temp+(7.0/12.0)*SQR(2.55)*temp2); DF=parms[0]*(2.0+2.55*(4.0*2.55*(7.0/12.0)*temp-3.0)*temp)*temp/r; break; case RIGID_BOND: U=DF=0.0; break; case FIXED_BOND: U=DF=0.0; break; default: fprintf(stderr, "Undefined Bond potential in routine 'CalculateCationBondForce' ('internal_force.c')\n"); exit(0); break; } // add contribution to the Cation stretch energy UCationBond[CurrentSystem]+=U; // forces are oppositely directed to the gradient f.x=-DF*dr.x; f.y=-DF*dr.y; f.z=-DF*dr.z; // add contribution to the forces Cations[CurrentSystem][m].Atoms[A].Force.x+=f.x; Cations[CurrentSystem][m].Atoms[A].Force.y+=f.y; Cations[CurrentSystem][m].Atoms[A].Force.z+=f.z; Cations[CurrentSystem][m].Atoms[B].Force.x-=f.x; Cations[CurrentSystem][m].Atoms[B].Force.y-=f.y; Cations[CurrentSystem][m].Atoms[B].Force.z-=f.z; // add contribution to the stress tensor StrainDerivativeTensor[CurrentSystem].ax-=dr.x*f.x; StrainDerivativeTensor[CurrentSystem].bx-=dr.y*f.x; StrainDerivativeTensor[CurrentSystem].cx-=dr.z*f.x; StrainDerivativeTensor[CurrentSystem].ay-=dr.x*f.y; StrainDerivativeTensor[CurrentSystem].by-=dr.y*f.y; StrainDerivativeTensor[CurrentSystem].cy-=dr.z*f.y; StrainDerivativeTensor[CurrentSystem].az-=dr.x*f.z; StrainDerivativeTensor[CurrentSystem].bz-=dr.y*f.z; StrainDerivativeTensor[CurrentSystem].cz-=dr.z*f.z; } } // Calculate Urey-Bradley force void CalculateAdsorbateUreyBradleyForce(int m) { int i,Type,NumberOfUreyBradleys,A,C; REAL U,DF,r,rr,temp,temp2,exp_term,r1; REAL *parms; POINT posA,posC; VECTOR dr,f; Type=Adsorbates[CurrentSystem][m].Type; NumberOfUreyBradleys=Components[Type].NumberOfUreyBradleys; for(i=0;ip_2 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2 [A] r1=r-parms[1]; U=0.5*parms[0]*SQR(MIN2(fabs(r1),parms[2])) +parms[0]*parms[2]*MAX2(fabs(r1)-parms[2],(REAL)0.0); DF=-parms[0]*(SIGN(MIN2(fabs(r1),parms[2]),r1))/r; break; case QUARTIC_UREYBRADLEY: // (1/2)*p_0*(r-p_1)^2+(1/3)*p_2*(r-p_1)^3+(1/4)*p_3*(r-p_1)^4 // =========================================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=0.5*parms[0]*temp2+(1.0/3.0)*parms[2]*temp*temp2+0.25*parms[3]*SQR(temp2); DF=temp*(parms[0]+parms[2]*temp+parms[3]*temp2)/r; break; case CFF_QUARTIC_UREYBRADLEY: // p_0*(r-p_1)^2+p_2*(r-p_1)^3+p_3*(r-p_1)^4 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=parms[0]*temp2+parms[2]*temp*temp2+parms[3]*SQR(temp2); DF=temp*(2.0*parms[0]+3.0*parms[2]*temp+4.0*parms[3]*temp2)/r; break; case MM3_UREYBRADLEY: // p_0*(r-p_1)^2*(1.0-2.55*(r-p_1)+(7.0/12.0)*2.55^2*(r-p_1)^2) // ================================================================= // p_0 [mdyne/A molecule] // p_1 [A] temp=r-parms[1]; temp2=SQR(temp); U=parms[0]*temp2*(1.0-2.55*temp+(7.0/12.0)*SQR(2.55)*temp2); DF=parms[0]*(2.0+2.55*(4.0*2.55*(7.0/12.0)*temp-3.0)*temp)*temp/r; break; case RIGID_UREYBRADLEY: U=DF=0.0; break; case FIXED_UREYBRADLEY: U=DF=0.0; break; default: fprintf(stderr, "Undefined Urey-Bradley potential in routine 'CalculateAdsorbateUreyBradleyForce' ('internal_force.c')\n"); exit(0); break; } // add contribution to the Adsorbate Urey-Bradley energy UAdsorbateUreyBradley[CurrentSystem]+=U; // forces are oppositely directed to the gradient f.x=-DF*dr.x; f.y=-DF*dr.y; f.z=-DF*dr.z; // add contribution to the forces Adsorbates[CurrentSystem][m].Atoms[A].Force.x+=f.x; Adsorbates[CurrentSystem][m].Atoms[A].Force.y+=f.y; Adsorbates[CurrentSystem][m].Atoms[A].Force.z+=f.z; Adsorbates[CurrentSystem][m].Atoms[C].Force.x-=f.x; Adsorbates[CurrentSystem][m].Atoms[C].Force.y-=f.y; Adsorbates[CurrentSystem][m].Atoms[C].Force.z-=f.z; // add contribution to the stress tensor StrainDerivativeTensor[CurrentSystem].ax-=dr.x*f.x; StrainDerivativeTensor[CurrentSystem].bx-=dr.y*f.x; StrainDerivativeTensor[CurrentSystem].cx-=dr.z*f.x; StrainDerivativeTensor[CurrentSystem].ay-=dr.x*f.y; StrainDerivativeTensor[CurrentSystem].by-=dr.y*f.y; StrainDerivativeTensor[CurrentSystem].cy-=dr.z*f.y; StrainDerivativeTensor[CurrentSystem].az-=dr.x*f.z; StrainDerivativeTensor[CurrentSystem].bz-=dr.y*f.z; StrainDerivativeTensor[CurrentSystem].cz-=dr.z*f.z; } } // Calculate Urey-Bradley force void CalculateCationUreyBradleyForce(int m) { int i,Type,NumberOfUreyBradleys,A,C; REAL U,DF,r,rr,temp,temp2,exp_term,r1; REAL *parms; POINT posA,posC; VECTOR dr,f; Type=Cations[CurrentSystem][m].Type; NumberOfUreyBradleys=Components[Type].NumberOfUreyBradleys; for(i=0;ip_2 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2 [A] r1=r-parms[1]; U=0.5*parms[0]*SQR(MIN2(fabs(r1),parms[2])) +parms[0]*parms[2]*MAX2(fabs(r1)-parms[2],(REAL)0.0); DF=-parms[0]*(SIGN(MIN2(fabs(r1),parms[2]),r1))/r; break; case QUARTIC_UREYBRADLEY: // (1/2)*p_0*(r-p_1)^2+(1/3)*p_2*(r-p_1)^3+(1/4)*p_3*(r-p_1)^4 // =========================================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=0.5*parms[0]*temp2+(1.0/3.0)*parms[2]*temp*temp2+0.25*parms[3]*SQR(temp2); DF=temp*(parms[0]+parms[2]*temp+parms[3]*temp2)/r; break; case CFF_QUARTIC_UREYBRADLEY: // p_0*(r-p_1)^2+p_2*(r-p_1)^3+p_3*(r-p_1)^4 // =============================================== // p_0/k_B [K/A^2] // p_1 [A] // p_2/k_B [K/A^3] // p_3/k_B [K/A^4] temp=r-parms[1]; temp2=SQR(r-parms[1]); U=parms[0]*temp2+parms[2]*temp*temp2+parms[3]*SQR(temp2); DF=temp*(2.0*parms[0]+3.0*parms[2]*temp+4.0*parms[3]*temp2)/r; break; case MM3_UREYBRADLEY: // p_0*(r-p_1)^2*(1.0-2.55*(r-p_1)+(7.0/12.0)*2.55^2*(r-p_1)^2) // ================================================================= // p_0 [mdyne/A molecule] // p_1 [A] temp=r-parms[1]; temp2=SQR(temp); U=parms[0]*temp2*(1.0-2.55*temp+(7.0/12.0)*SQR(2.55)*temp2); DF=parms[0]*(2.0+2.55*(4.0*2.55*(7.0/12.0)*temp-3.0)*temp)*temp/r; break; case RIGID_UREYBRADLEY: U=DF=0.0; break; case FIXED_UREYBRADLEY: U=DF=0.0; break; default: fprintf(stderr, "Undefined Urey-Bradley potential in routine 'CalculateCationUreyBradleyForce' ('internal_force.c')\n"); exit(0); break; } // add contribution to the Cation Urey-Bradley energy UCationUreyBradley[CurrentSystem]+=U; // forces are oppositely directed to the gradient f.x=-DF*dr.x; f.y=-DF*dr.y; f.z=-DF*dr.z; // add contribution to the forces Cations[CurrentSystem][m].Atoms[A].Force.x+=f.x; Cations[CurrentSystem][m].Atoms[A].Force.y+=f.y; Cations[CurrentSystem][m].Atoms[A].Force.z+=f.z; Cations[CurrentSystem][m].Atoms[C].Force.x-=f.x; Cations[CurrentSystem][m].Atoms[C].Force.y-=f.y; Cations[CurrentSystem][m].Atoms[C].Force.z-=f.z; // add contribution to the stress tensor StrainDerivativeTensor[CurrentSystem].ax-=dr.x*f.x; StrainDerivativeTensor[CurrentSystem].bx-=dr.y*f.x; StrainDerivativeTensor[CurrentSystem].cx-=dr.z*f.x; StrainDerivativeTensor[CurrentSystem].ay-=dr.x*f.y; StrainDerivativeTensor[CurrentSystem].by-=dr.y*f.y; StrainDerivativeTensor[CurrentSystem].cy-=dr.z*f.y; StrainDerivativeTensor[CurrentSystem].az-=dr.x*f.z; StrainDerivativeTensor[CurrentSystem].bz-=dr.y*f.z; StrainDerivativeTensor[CurrentSystem].cz-=dr.z*f.z; } } void CalculateAdsorbateBendForce(int m) { int Type,NumberOfBends; int i,A,B,C,D; REAL *parms,DF,U,temp,temp2; REAL CosTheta,Theta,SinTheta; REAL rab,rbc,rac,DTDX; VECTOR posA,posB,posC,posD; VECTOR Rab,Rbc,Rac,fa,fb,fc,dtA,dtB,dtC;; VECTOR Rad,Rbd,Rcd,t,ip,ap,cp; REAL rt2,rap2,rcp2; REAL terma,termc,delta,delta2,rm,ptrt2,term; VECTOR dpdia,dpdic,dedip,fd,n; Type=Adsorbates[CurrentSystem][m].Type; NumberOfBends=Components[Type].NumberOfBends; for(i=0;iPosition; posB=HarmonicDistanceConstraints[CurrentSystem][m][1]->Position; parms0=HarmonicDistanceConstraintParameters[CurrentSystem][m][0]; parms1=HarmonicDistanceConstraintParameters[CurrentSystem][m][1]; dr.x=posA.x-posB.x; dr.y=posA.y-posB.y; dr.z=posA.z-posB.z; rr=SQR(dr.x)+SQR(dr.y)+SQR(dr.z); r=sqrt(rr); U=0.5*parms0*SQR(r-parms1); DF=parms0*(r-parms1)/r; // add contribution to the energy UDistanceConstraints[CurrentSystem]+=U; // forces are oppositely directed to the gradient f.x=-DF*dr.x; f.y=-DF*dr.y; f.z=-DF*dr.z; // add contribution to the forces HarmonicDistanceConstraints[CurrentSystem][m][0]->Force.x+=f.x; HarmonicDistanceConstraints[CurrentSystem][m][0]->Force.y+=f.y; HarmonicDistanceConstraints[CurrentSystem][m][0]->Force.z+=f.z; HarmonicDistanceConstraints[CurrentSystem][m][1]->Force.x-=f.x; HarmonicDistanceConstraints[CurrentSystem][m][1]->Force.y-=f.y; HarmonicDistanceConstraints[CurrentSystem][m][1]->Force.z-=f.z; // add contribution to the stress tensor StrainDerivativeTensor[CurrentSystem].ax-=dr.x*f.x; StrainDerivativeTensor[CurrentSystem].bx-=dr.y*f.x; StrainDerivativeTensor[CurrentSystem].cx-=dr.z*f.x; StrainDerivativeTensor[CurrentSystem].ay-=dr.x*f.y; StrainDerivativeTensor[CurrentSystem].by-=dr.y*f.y; StrainDerivativeTensor[CurrentSystem].cy-=dr.z*f.y; StrainDerivativeTensor[CurrentSystem].az-=dr.x*f.z; StrainDerivativeTensor[CurrentSystem].bz-=dr.y*f.z; StrainDerivativeTensor[CurrentSystem].cz-=dr.z*f.z; } } void CalculateHarmonicAngleConstraintForce(void) { int m; REAL DF,U; REAL CosTheta,Theta,SinTheta; REAL rab,rac,rbc,DTDX; POINT posA,posB,posC; VECTOR Rab,Rac,Rbc,fa,fb,fc,dtA,dtB,dtC; REAL parms0,parms1; UAngleConstraints[CurrentSystem]=0.0; for(m=0;mPosition; posB=HarmonicAngleConstraints[CurrentSystem][m][1]->Position; posC=HarmonicAngleConstraints[CurrentSystem][m][2]->Position; parms0=HarmonicAngleConstraintParameters[CurrentSystem][m][0]; parms1=HarmonicAngleConstraintParameters[CurrentSystem][m][1]; Rab.x=posA.x-posB.x; Rab.y=posA.y-posB.y; Rab.z=posA.z-posB.z; rab=sqrt(SQR(Rab.x)+SQR(Rab.y)+SQR(Rab.z)); Rab.x/=rab; Rab.y/=rab; Rab.z/=rab; Rbc.x=posC.x-posB.x; Rbc.y=posC.y-posB.y; Rbc.z=posC.z-posB.z; rbc=sqrt(SQR(Rbc.x)+SQR(Rbc.y)+SQR(Rbc.z)); Rbc.x/=rbc; Rbc.y/=rbc; Rbc.z/=rbc; Rac.x=posC.x-posA.x; Rac.y=posC.y-posA.y; Rac.z=posC.z-posA.z; rac=sqrt(SQR(Rac.x)+SQR(Rac.y)+SQR(Rac.z)); Rac.x/=rac; Rac.y/=rac; Rac.z/=rac; CosTheta=(Rab.x*Rbc.x+Rab.y*Rbc.y+Rab.z*Rbc.z); Theta=acos(CosTheta); SinTheta=MAX2((REAL)1.0e-8,sqrt(1.0-SQR(CosTheta))); DTDX=-1.0/sqrt(1.0-SQR(CosTheta)); U=0.5*parms0*SQR(Theta-parms1); DF=parms0*(Theta-parms1)*DTDX; // add contribution to the energy UAngleConstraints[CurrentSystem]+=U; // Calculate the components of the derivatives. dtA.x=(Rbc.x-CosTheta*Rab.x)/rab; dtA.y=(Rbc.y-CosTheta*Rab.y)/rab; dtA.z=(Rbc.z-CosTheta*Rab.z)/rab; dtC.x=(Rab.x-CosTheta*Rbc.x)/rbc; dtC.y=(Rab.y-CosTheta*Rbc.y)/rbc; dtC.z=(Rab.z-CosTheta*Rbc.z)/rbc; dtB.x=-(dtA.x+dtC.x); dtB.y=-(dtA.y+dtC.y); dtB.z=-(dtA.z+dtC.z); // forces are oppositely directed to the gradient fa.x=-DF*dtA.x; fa.y=-DF*dtA.y; fa.z=-DF*dtA.z; fb.x=-DF*dtB.x; fb.y=-DF*dtB.y; fb.z=-DF*dtB.z; fc.x=-DF*dtC.x; fc.y=-DF*dtC.y; fc.z=-DF*dtC.z; // add contribution to the forces HarmonicAngleConstraints[CurrentSystem][m][0]->Force.x+=fa.x; HarmonicAngleConstraints[CurrentSystem][m][0]->Force.y+=fa.y; HarmonicAngleConstraints[CurrentSystem][m][0]->Force.z+=fa.z; HarmonicAngleConstraints[CurrentSystem][m][1]->Force.x-=(fa.x+fc.x); HarmonicAngleConstraints[CurrentSystem][m][1]->Force.y-=(fa.y+fc.y); HarmonicAngleConstraints[CurrentSystem][m][1]->Force.z-=(fa.z+fc.z); HarmonicAngleConstraints[CurrentSystem][m][2]->Force.x+=fc.x; HarmonicAngleConstraints[CurrentSystem][m][2]->Force.y+=fc.y; HarmonicAngleConstraints[CurrentSystem][m][2]->Force.z+=fc.z; // add contribution to the stress tensor // Note: rab and rbc are here because the vectors were normalized before StrainDerivativeTensor[CurrentSystem].ax-=rab*Rab.x*fa.x+rbc*Rbc.x*fc.x; StrainDerivativeTensor[CurrentSystem].bx-=rab*Rab.y*fa.x+rbc*Rbc.y*fc.x; StrainDerivativeTensor[CurrentSystem].cx-=rab*Rab.z*fa.x+rbc*Rbc.z*fc.x; StrainDerivativeTensor[CurrentSystem].ay-=rab*Rab.x*fa.y+rbc*Rbc.x*fc.y; StrainDerivativeTensor[CurrentSystem].by-=rab*Rab.y*fa.y+rbc*Rbc.y*fc.y; StrainDerivativeTensor[CurrentSystem].cy-=rab*Rab.z*fa.y+rbc*Rbc.z*fc.y; StrainDerivativeTensor[CurrentSystem].az-=rab*Rab.x*fa.z+rbc*Rbc.x*fc.z; StrainDerivativeTensor[CurrentSystem].bz-=rab*Rab.y*fa.z+rbc*Rbc.y*fc.z; StrainDerivativeTensor[CurrentSystem].cz-=rab*Rab.z*fa.z+rbc*Rbc.z*fc.z; } } void CalculateHarmonicDihedralConstraintForce(void) { int m; POINT posA,posB,posC,posD; REAL d,e,rbc; VECTOR Dab,Dcb,Ddc,dr,ds; REAL dot_ab,dot_cd,r,s,sign; REAL CosPhi,Phi,CosPhi2,SinPhi,U,DF; VECTOR dtA,dtB,dtC,dtD,Pb,Pc; VECTOR fa,fb,fc,fd; REAL parms0,parms1; UDihedralConstraints[CurrentSystem]=0.0; for(m=0;mPosition; posB=HarmonicDihedralConstraints[CurrentSystem][m][1]->Position; posC=HarmonicDihedralConstraints[CurrentSystem][m][2]->Position; posD=HarmonicDihedralConstraints[CurrentSystem][m][3]->Position; parms0=HarmonicDihedralConstraintParameters[CurrentSystem][m][0]; parms1=HarmonicDihedralConstraintParameters[CurrentSystem][m][1]; Dab.x=posA.x-posB.x; Dab.y=posA.y-posB.y; Dab.z=posA.z-posB.z; Dcb.x=posC.x-posB.x; Dcb.y=posC.y-posB.y; Dcb.z=posC.z-posB.z; rbc=sqrt(SQR(Dcb.x)+SQR(Dcb.y)+SQR(Dcb.z)); Dcb.x/=rbc; Dcb.y/=rbc; Dcb.z/=rbc; Ddc.x=posD.x-posC.x; Ddc.y=posD.y-posC.y; Ddc.z=posD.z-posC.z; dot_ab=Dab.x*Dcb.x+Dab.y*Dcb.y+Dab.z*Dcb.z; dot_cd=Ddc.x*Dcb.x+Ddc.y*Dcb.y+Ddc.z*Dcb.z; dr.x=Dab.x-dot_ab*Dcb.x; dr.y=Dab.y-dot_ab*Dcb.y; dr.z=Dab.z-dot_ab*Dcb.z; r=sqrt(SQR(dr.x)+SQR(dr.y)+SQR(dr.z)); dr.x/=r; dr.y/=r; dr.z/=r; ds.x=Ddc.x-dot_cd*Dcb.x; ds.y=Ddc.y-dot_cd*Dcb.y; ds.z=Ddc.z-dot_cd*Dcb.z; s=sqrt(SQR(ds.x)+SQR(ds.y)+SQR(ds.z)); ds.x/=s; ds.y/=s; ds.z/=s; // compute Cos(Phi) // Phi is defined in protein convention Phi(trans)=Pi CosPhi=dr.x*ds.x+dr.y*ds.y+dr.z*ds.z; // Ensure CosPhi is between -1 and 1. CosPhi=SIGN(MIN2(fabs(CosPhi),(REAL)1.0),CosPhi); CosPhi2=SQR(CosPhi); // potential defined in terms of 'phi' and therefore contains a singularity // the sign of the angle-phi is positive if (Rab x Rbc) x (Rbc x Rcd) is in the // same direction as Rbc, and negative otherwise Pb.x=Dab.z*Dcb.y-Dab.y*Dcb.z; Pb.y=Dab.x*Dcb.z-Dab.z*Dcb.x; Pb.z=Dab.y*Dcb.x-Dab.x*Dcb.y; Pc.x=Dcb.y*Ddc.z-Dcb.z*Ddc.y; Pc.y=Dcb.z*Ddc.x-Dcb.x*Ddc.z; Pc.z=Dcb.x*Ddc.y-Dcb.y*Ddc.x; sign=(Dcb.x*(Pc.z*Pb.y-Pc.y*Pb.z)+Dcb.y*(Pb.z*Pc.x-Pb.x*Pc.z) +Dcb.z*(Pc.y*Pb.x-Pc.x*Pb.y)); Phi=SIGN(acos(CosPhi),sign); SinPhi=sin(Phi); Phi-=parms1; Phi-=NINT(Phi/(2.0*M_PI))*2.0*M_PI; SinPhi=SIGN(MAX2((REAL)1.0e-8,fabs(SinPhi)),SinPhi); // remove singularity U=0.5*parms0*SQR(Phi); DF=-parms0*(Phi)/SinPhi; UDihedralConstraints[CurrentSystem]+=U; // Calculate the first derivative vectors. d=dot_ab/rbc; e=dot_cd/rbc; dtA.x=(ds.x-CosPhi*dr.x)/r; dtA.y=(ds.y-CosPhi*dr.y)/r; dtA.z=(ds.z-CosPhi*dr.z)/r; dtD.x=(dr.x-CosPhi*ds.x)/s; dtD.y=(dr.y-CosPhi*ds.y)/s; dtD.z=(dr.z-CosPhi*ds.z)/s; dtB.x=dtA.x*(d-1.0)+e*dtD.x; dtB.y=dtA.y*(d-1.0)+e*dtD.y; dtB.z=dtA.z*(d-1.0)+e*dtD.z; dtC.x=-dtD.x*(e+1.0)-d*dtA.x; dtC.y=-dtD.y*(e+1.0)-d*dtA.y; dtC.z=-dtD.z*(e+1.0)-d*dtA.z; // forces are oppositely directed to the gradient fa.x=-DF*dtA.x; fa.y=-DF*dtA.y; fa.z=-DF*dtA.z; fb.x=-DF*dtB.x; fb.y=-DF*dtB.y; fb.z=-DF*dtB.z; fc.x=-DF*dtC.x; fc.y=-DF*dtC.y; fc.z=-DF*dtC.z; fd.x=-DF*dtD.x; fd.y=-DF*dtD.y; fd.z=-DF*dtD.z; // add contribution to the forces HarmonicDihedralConstraints[CurrentSystem][m][0]->Force.x+=fa.x; HarmonicDihedralConstraints[CurrentSystem][m][0]->Force.y+=fa.y; HarmonicDihedralConstraints[CurrentSystem][m][0]->Force.z+=fa.z; HarmonicDihedralConstraints[CurrentSystem][m][1]->Force.x+=fb.x; HarmonicDihedralConstraints[CurrentSystem][m][1]->Force.y+=fb.y; HarmonicDihedralConstraints[CurrentSystem][m][1]->Force.z+=fb.z; HarmonicDihedralConstraints[CurrentSystem][m][2]->Force.x+=fc.x; HarmonicDihedralConstraints[CurrentSystem][m][2]->Force.y+=fc.y; HarmonicDihedralConstraints[CurrentSystem][m][2]->Force.z+=fc.z; HarmonicDihedralConstraints[CurrentSystem][m][3]->Force.x+=fd.x; HarmonicDihedralConstraints[CurrentSystem][m][3]->Force.y+=fd.y; HarmonicDihedralConstraints[CurrentSystem][m][3]->Force.z+=fd.z; // add contribution to the stress tensor // Note: rbc is here because the vector was normalized before StrainDerivativeTensor[CurrentSystem].ax-=Dab.x*fa.x+Dcb.x*rbc*(fc.x+fd.x)+Ddc.x*fd.x; StrainDerivativeTensor[CurrentSystem].bx-=Dab.y*fa.x+Dcb.y*rbc*(fc.x+fd.x)+Ddc.y*fd.x; StrainDerivativeTensor[CurrentSystem].cx-=Dab.z*fa.x+Dcb.z*rbc*(fc.x+fd.x)+Ddc.z*fd.x; StrainDerivativeTensor[CurrentSystem].ay-=Dab.x*fa.y+Dcb.x*rbc*(fc.y+fd.y)+Ddc.x*fd.y; StrainDerivativeTensor[CurrentSystem].by-=Dab.y*fa.y+Dcb.y*rbc*(fc.y+fd.y)+Ddc.y*fd.y; StrainDerivativeTensor[CurrentSystem].cy-=Dab.z*fa.y+Dcb.z*rbc*(fc.y+fd.y)+Ddc.z*fd.y; StrainDerivativeTensor[CurrentSystem].az-=Dab.x*fa.z+Dcb.x*rbc*(fc.z+fd.z)+Ddc.x*fd.z; StrainDerivativeTensor[CurrentSystem].bz-=Dab.y*fa.z+Dcb.y*rbc*(fc.z+fd.z)+Ddc.y*fd.z; StrainDerivativeTensor[CurrentSystem].cz-=Dab.z*fa.z+Dcb.z*rbc*(fc.z+fd.z)+Ddc.z*fd.z; } }