/************************************************************************************************************* 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. **************************************************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "constants.h" #include "molecule.h" #include "framework.h" #include "framework_energy.h" #include "simulation.h" #include "ewald.h" #include "potentials.h" #include "utils.h" #include "output.h" #include "cbmc.h" #include "mc_moves.h" #include "grids.h" #include "spacegroup.h" // the routines for VDW and charge-charge interaction are splitted. The VDW interactions can potentially shift the // actual interaction site across a bond (see e.g. MM3). // Calculate the Energy of a bead of type "typeA" at a position "posA". // posA is defined in xyz (also for triclinic). REAL CalculateFrameworkVDWEnergyAtPosition(POINT posA,int typeA,REAL scaling) { int i,j,typeB,f1; REAL rr; REAL UVDW; VECTOR posB,dr,s; int icell,icell0; int ncell; UVDW=0.0; if(Framework[CurrentSystem].FrameworkModel!=NONE) { if((Framework[CurrentSystem].FrameworkModel==GRID)&&(VDWGrid[typeA])) // grid-interpolating for rigid frameworks { UVDW=InterpolateVDWGrid(typeA,posA); return UVDW; } else if(UseCellLists[CurrentSystem]) // energy using cell-lists { // convert from xyz to abc s.x=InverseBox[CurrentSystem].ax*posA.x+InverseBox[CurrentSystem].bx*posA.y+InverseBox[CurrentSystem].cx*posA.z; s.y=InverseBox[CurrentSystem].ay*posA.x+InverseBox[CurrentSystem].by*posA.y+InverseBox[CurrentSystem].cy*posA.z; s.z=InverseBox[CurrentSystem].az*posA.x+InverseBox[CurrentSystem].bz*posA.y+InverseBox[CurrentSystem].cz*posA.z; // apply boundary condition s.x-=(REAL)NINT(s.x); s.y-=(REAL)NINT(s.y); s.z-=(REAL)NINT(s.z); // s between 0 and 1 s.x+=0.5; s.y+=0.5; s.z+=0.5; // compute the corresponding cell-id icell0=(int)(s.x*NumberOfCellListCells[CurrentSystem].x)+ ((int)(s.y*NumberOfCellListCells[CurrentSystem].y))*NumberOfCellListCells[CurrentSystem].x+ ((int)(s.z*NumberOfCellListCells[CurrentSystem].z))*NumberOfCellListCells[CurrentSystem].x*NumberOfCellListCells[CurrentSystem].y; for(f1=0;f1=0) { typeB=Framework[CurrentSystem].Atoms[f1][j].Type; posB=Framework[CurrentSystem].Atoms[f1][j].AnisotropicPosition; 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); if(rrp_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); 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); 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); 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); break; case MEASURE_BOND: U=0.0; break; case RIGID_BOND: U=0.0; break; case FIXED_BOND: U=0.0; break; default: fprintf(stderr, "Undefined Bond potential in routine 'CalculateFrameworkBondEnergy' ('framework_energy.c')\n"); exit(0); break; } // add contribution to the Adsorbate stretch energy UHostBond+=U; } } } } return UHostBond; } REAL CalculateFrameworkUreyBradleyEnergy(int flag,int f2,int atom_id) { int i,f1; REAL r,rr,r1,U; REAL temp,temp2,exp_term; VECTOR dr,posA,posC; REAL *parms,UHostUreyBradley; int A,C; UHostUreyBradley=0.0; for(f1=0;f1p_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); 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); 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); 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); break; case RIGID_UREYBRADLEY: U=0.0; break; case FIXED_UREYBRADLEY: U=0.0; break; default: fprintf(stderr, "Undefined Urey-Bradley potential in routine 'CalculateFrameworkUreyBradleyEnergy' ('framework_energy.c')\n"); exit(0); break; } // add contribution to the Adsorbate Urey-Bradley energy UHostUreyBradley+=U; } } } } return UHostUreyBradley; } REAL CalculateFrameworkBendEnergy(int flag,int f2,int atom_id) { int i,A,B,C,D,f1; REAL *parms,U,temp,temp2; REAL CosTheta,Theta,SinTheta; REAL rab,rbc,rac,DTDX,UHostBend; VECTOR posA,posB,posC,posD; VECTOR Rab,Rbc,Rac; VECTOR Rad,Rbd,Rcd,t,ip,ap,cp; REAL delta,rt2,rap2,rcp2; UHostBend=0.0; for(f1=0;f11e-8) { A=Framework[CurrentSystem].Torsions[f1][i].A; typeA=Framework[CurrentSystem].Atoms[f1][A].Type; posA=Framework[CurrentSystem].Atoms[f1][A].Position; B=Framework[CurrentSystem].Torsions[f1][i].D; typeB=Framework[CurrentSystem].Atoms[f1][B].Type; posB=Framework[CurrentSystem].Atoms[f1][B].Position; if(!BITVAL(Framework[CurrentSystem].ExclusionMatrix[f1][A][B],7)) { 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); UHostHostVDW[CurrentSystem]+=parms[6]*PotentialValue(typeA,typeB,rr,1.0); } } } } } return 0; } int CalculateFrameworkIntraChargeChargeEnergy(void) { int i,j,typeA,typeB; REAL chargeA,chargeB; REAL r,rr; VECTOR posA,posB,dr; int f1,f2,A,B; REAL *parms; REAL alpha; // Framework-Framework energy UHostHostChargeChargeReal[CurrentSystem]=0.0; if(ChargeMethod==NONE) return 0; for(f1=0;f11e-8) { A=Framework[CurrentSystem].Torsions[f1][i].A; chargeA=Framework[CurrentSystem].Atoms[f1][A].Charge; posA=Framework[CurrentSystem].Atoms[f1][A].AnisotropicPosition; B=Framework[CurrentSystem].Torsions[f1][i].D; chargeB=Framework[CurrentSystem].Atoms[f1][B].Charge; posB=Framework[CurrentSystem].Atoms[f1][B].AnisotropicPosition; if(!BITVAL(Framework[CurrentSystem].ExclusionMatrix[f1][A][B],7)) { dr.x=posA.x-posB.x; dr.y=posA.y-posB.y; dr.z=posA.z-posB.z; dr=ApplyBoundaryCondition(dr); r=sqrt(SQR(dr.x)+SQR(dr.y)+SQR(dr.z)); UHostHostChargeChargeReal[CurrentSystem]+=parms[7]*COULOMBIC_CONVERSION_FACTOR*chargeA*chargeB/r; } } } } } return 0; } int CalculateFrameworkIntraChargeBondDipoleEnergy(void) { int i,j,f1,f2; int A1,A2; int Type; VECTOR posA,posB,posA1,posA2,dr; REAL rr,ri2,temp,length,chargeB; VECTOR dipoleA; REAL Bt1; REAL DipoleMagnitudeA; REAL_MATRIX3x3 v; Bt1=0.0; v.ax=v.bx=v.cx=0.0; v.ay=v.by=v.cy=0.0; v.az=v.bz=v.cz=0.0; UHostHostChargeBondDipoleReal[CurrentSystem]=0.0; if(ChargeMethod==NONE) return 0; for(f1=0;f1=0) { posB=Framework[CurrentSystem].Atoms[f1][k].AnisotropicPosition; typeB=Framework[CurrentSystem].Atoms[f1][k].Type; 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); if(rr=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostAdsorbateVDW[CurrentSystem]+=energy; } } } } } } } return 0; } int CalculateFrameworkCationVDWEnergy(void) { int i,j,k,l,f1; int typeA,typeB,type; REAL rr,scalingA,energy; VECTOR posA,posB,dr; VECTOR s; int icell0,icell; UHostCationVDW[CurrentSystem]=0.0; for(i=0;i=0) { posB=Framework[CurrentSystem].Atoms[f1][k].AnisotropicPosition; typeB=Framework[CurrentSystem].Atoms[f1][k].Type; 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); if(rr=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostCationVDW[CurrentSystem]+=energy; } } } } } } } return 0; } int CalculateFrameworkAdsorbateChargeChargeEnergy(void) { int i,j,k; int typeA,typeB,type; REAL r,rr; REAL chargeA,chargeB; VECTOR posA,posB,dr; REAL scalingA; UHostAdsorbateChargeChargeReal[CurrentSystem]=0.0; if(ChargeMethod==NONE) return 0; for(i=0;i1e-8) { A=MIN2(Framework[CurrentSystem].Torsions[f1][i].A,Framework[CurrentSystem].Torsions[f1][i].D); B=MAX2(Framework[CurrentSystem].Torsions[f1][i].A,Framework[CurrentSystem].Torsions[f1][i].D); if(!BITVAL(Framework[CurrentSystem].ExclusionMatrix[f1][A][B],7)) { typeA=Framework[CurrentSystem].Atoms[f1][A].Type; posA=Framework[CurrentSystem].Atoms[f1][A].AnisotropicPosition; typeB=Framework[CurrentSystem].Atoms[f1][B].Type; posB=Framework[CurrentSystem].Atoms[f1][B].AnisotropicPosition; 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); if(rr1e-8) { A=MIN2(Framework[CurrentSystem].Torsions[f1][i].A,Framework[CurrentSystem].Torsions[f1][i].D); B=MAX2(Framework[CurrentSystem].Torsions[f1][i].A,Framework[CurrentSystem].Torsions[f1][i].D); if(!BITVAL(Framework[CurrentSystem].ExclusionMatrix[f1][A][B],7)) { chargeA=Framework[CurrentSystem].Atoms[f1][A].Charge; posA=Framework[CurrentSystem].Atoms[f1][A].AnisotropicPosition; chargeB=Framework[CurrentSystem].Atoms[f1][B].Charge; posB=Framework[CurrentSystem].Atoms[f1][B].AnisotropicPosition; 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); if(rr=0) { typeB=Framework[CurrentSystem].Atoms[f1][k].Type; posB=Framework[CurrentSystem].Atoms[f1][k].AnisotropicPosition; dr.x=posA_new.x-posB.x; dr.y=posA_new.y-posB.y; dr.z=posA_new.z-posB.z; dr=ApplyBoundaryCondition(dr); rr=SQR(dr.x)+SQR(dr.y)+SQR(dr.z); if(rr=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } k=Framework[CurrentSystem].CellList[f1][k]; } } } } else if(UseReplicas[CurrentSystem]) { for(f1=0;f1=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } } } } } else { for(f1=0;f1=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } } } } } } } if(Old) { if(Framework[CurrentSystem].FrameworkModel!=NONE) { // grid interpolation; transfer to the correct coordinates nr_atoms=Components[comp].NumberOfAtoms; for(j=0;j=0) { typeB=Framework[CurrentSystem].Atoms[f1][k].Type; posB=Framework[CurrentSystem].Atoms[f1][k].AnisotropicPosition; dr.x=posA_old.x-posB.x; dr.y=posA_old.y-posB.y; dr.z=posA_old.z-posB.z; dr=ApplyBoundaryCondition(dr); rr=SQR(dr.x)+SQR(dr.y)+SQR(dr.z); if(rr=0) { typeB=Framework[CurrentSystem].Atoms[f1][k].Type; posB=Framework[CurrentSystem].Atoms[f1][k].AnisotropicPosition; dr.x=posA_new.x-posB.x; dr.y=posA_new.y-posB.y; dr.z=posA_new.z-posB.z; dr=ApplyBoundaryCondition(dr); rr=SQR(dr.x)+SQR(dr.y)+SQR(dr.z); if(rr=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } k=Framework[CurrentSystem].CellList[f1][k]; } } } } else if(UseReplicas[CurrentSystem]) { for(f1=0;f1=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } } } } } else { for(f1=0;f1=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } } } } } } } if(Old) { if(Framework[CurrentSystem].FrameworkModel!=NONE) { // grid interpolation; transfer to the correct coordinates nr_atoms=Components[comp].NumberOfAtoms; for(j=0;j=0) { typeB=Framework[CurrentSystem].Atoms[f1][k].Type; posB=Framework[CurrentSystem].Atoms[f1][k].AnisotropicPosition; dr.x=posA_old.x-posB.x; dr.y=posA_old.y-posB.y; dr.z=posA_old.z-posB.z; dr=ApplyBoundaryCondition(dr); rr=SQR(dr.x)+SQR(dr.y)+SQR(dr.z); if(rr=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostChargeChargeRealDelta[CurrentSystem]+=energy; } } } } } else { for(f1=0;f1=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostChargeChargeRealDelta[CurrentSystem]+=energy; } } } } } } } if(Old) { if(Framework[CurrentSystem].FrameworkModel!=NONE) { // grid interpolation; transfer to the correct coordinates for(j=0;j=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; energy=PotentialValue(typeA,typeB,rr,scalingA_old); if(energy>=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]-=energy; } } } } } return FALSE; } int CalculateFrameworkAdsorbateVDWEnergyDifferenceNewRXCM(int reaction,REAL LambdaNew,int direction) { int i,j,k,l,f1; int typeA,typeB; int TypeMolA; REAL rr,energy; VECTOR posA,posB,dr; REAL scalingA_new; int NumberOfRXMCMolecules; int RXMCMoleculeNumbers[256]; int RXMCMoleculeType[256]; OVERLAP=FALSE; UHostVDWDelta[CurrentSystem]=0.0; NumberOfRXMCMolecules=0; switch(direction) { case FORWARD: for(j=0;j=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostVDWDelta[CurrentSystem]+=energy; } } } } } return FALSE; } int CalculateFrameworkAdsorbateChargeChargeEnergyDifferenceRXCM(int reaction,REAL Lambda1,REAL Lambda2,REAL LambdaNew,int **LambdaRetraceMolecules,int direction) { int i,j,k,l,m,f1; REAL rr,energy,scalingA_new,scalingA_old; VECTOR posA,posB,dr; int TypeMolA; int NumberOfRXMCMolecules; int RXMCMoleculeNumbers[256]; int RXMCMoleculeType[256]; REAL chargeA,chargeB,chargeA_new,chargeA_old; OVERLAP=FALSE; UHostChargeChargeRealDelta[CurrentSystem]=0.0; NumberOfRXMCMolecules=0; for(j=0;j=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostChargeChargeRealDelta[CurrentSystem]+=energy; energy=PotentialValueCoulombic(chargeA_old,chargeB,sqrt(rr)); if(energy>=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostChargeChargeRealDelta[CurrentSystem]-=energy; } } } } } return FALSE; } int CalculateFrameworkAdsorbateChargeChargeEnergyDifferenceNewRXCM(int reaction,REAL LambdaNew,int direction) { int i,j,k,l,f1; int TypeMolA; REAL rr,energy; VECTOR posA,posB,dr; REAL scalingA_new; int NumberOfRXMCMolecules; int RXMCMoleculeNumbers[256]; int RXMCMoleculeType[256]; REAL chargeA_new,chargeB; OVERLAP=FALSE; UHostChargeChargeRealDelta[CurrentSystem]=0.0; NumberOfRXMCMolecules=0; switch(direction) { case FORWARD: for(j=0;j=EnergyOverlapCriteria) return OVERLAP=TRUE; UHostChargeChargeRealDelta[CurrentSystem]+=energy; } } } } } return FALSE; } REAL CalculateFrameworkElectrostaticPotential(POINT posA) { int i,typeB,f; REAL r,rr,chargeB; VECTOR posB,dr; REAL ElectrostaticPotential; ElectrostaticPotential=0.0; if(Framework[CurrentSystem].FrameworkModel!=NONE) { if(ChargeMethod!=NONE) { for(f=0;f