Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 194 lines (155 sloc) 6.585 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
/*
Copyright (C) 2010,2012 The ESPResSo project
Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
Max-Planck-Institute for Polymer Research, Theory Group
This file is part of ESPResSo.
ESPResSo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ESPResSo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GB_H
#define GB_H

/** \file gb.h
* Routines to calculate the Gay-Berne energy and force
* for a pair of particles.
* \ref forces.c
*/

#include "utils.h"
#include "interaction_data.h"
#include "particle_data.h"
#include "mol_cut.h"

#ifdef GAY_BERNE

///
int gay_berne_set_params(int part_type_a, int part_type_b,
double eps, double sig, double cut,
double k1, double k2,
double mu, double nu);

MDINLINE void add_gb_pair_force(Particle *p1, Particle *p2, IA_parameters *ia_params,
double d[3], double dist, double force[3], double torque1[3], double torque2[3])

{
  if (!CUTOFF_CHECK(dist < ia_params->GB_cut))
    return;
  
  double a,b,c, X, Xcut,
    Brack,BrackCut,
    Bra12,Bra12Cut,
    u1x, u1y, u1z,
    u2x, u2y, u2z,
    E,E1,E2, Sigma,
    Brhi1,Brhi2,
    Plus1,Minus1,
    Plus2,Minus2,
    Koef1,Koef2, /* mu/E2 and Sigma^3/2 */
    dU_dr, dU_da, dU_db, dU_dc, /* all derivatives */
    FikX,FikY,FikZ, /* help for forces */
    Gx,Gy,Gz; /* help for torques */

    u1x = p1->r.quatu[0]; u1y = p1->r.quatu[1]; u1z = p1->r.quatu[2];
    u2x = p2->r.quatu[0]; u2y = p2->r.quatu[1]; u2z = p2->r.quatu[2];
    
    a = d[0]*u1x + d[1]*u1y + d[2]*u1z;
    b = d[0]*u2x + d[1]*u2y + d[2]*u2z;
    c = u1x*u2x + u1y*u2y + u1z*u2z;
    E1 = 1/sqrt(1-ia_params->GB_chi1*ia_params->GB_chi1*c*c);
    Plus1 = (a+b)/(1+ia_params->GB_chi1*c);
    Plus2 = (a+b)/(1+ia_params->GB_chi2*c);
    Minus1 = (a-b)/(1-ia_params->GB_chi1*c);
    Minus2 = (a-b)/(1-ia_params->GB_chi2*c);
    Brhi2 = (ia_params->GB_chi2/dist/dist)*(Plus2*(a+b) + Minus2*(a-b));
    E2 = 1-0.5*Brhi2;
    E = 4*ia_params->GB_eps*pow(E1,ia_params->GB_nu)*pow(E2,ia_params->GB_mu);
    Brhi1 = (ia_params->GB_chi1/dist/dist)*(Plus1*(a+b) + Minus1*(a-b));
    Sigma = ia_params->GB_sig/sqrt(1-0.5*Brhi1);
    Koef1 = ia_params->GB_mu/E2;
    Koef2 = Sigma*Sigma*Sigma*0.5;
    
    X = 1/(dist - Sigma + ia_params->GB_sig);
    Xcut = 1/(ia_params->GB_cut - Sigma + ia_params->GB_sig);
     
    if (X < 1.25) { /* 1.25 corresponds to the interparticle penetration of 0.2 units of length.
If they are not that close, the GB forces and torques are calculated */
      
      Brack = X*X*X;
      BrackCut = Xcut*Xcut*Xcut;
      Brack = Brack*Brack;
      BrackCut = BrackCut*BrackCut;
 
      Bra12 = 6*Brack*X*(2*Brack-1);
      Bra12Cut = 6*BrackCut*Xcut*(2*BrackCut-1);
      Brack = Brack*(Brack-1);
      BrackCut = BrackCut*(BrackCut-1);
      
      /*-------- Here we calculate derivatives -----------------------------*/

      dU_dr = E*(Koef1*Brhi2*(Brack-BrackCut)-Koef2*Brhi1*(Bra12-Bra12Cut)-Bra12*dist)/dist/dist;
      Koef1 = Koef1*ia_params->GB_chi2/dist/dist;
      Koef2 = Koef2*ia_params->GB_chi1/dist/dist;
      dU_da = E*(Koef1*(Minus2+Plus2)*(BrackCut-Brack)+Koef2*(Plus1+Minus1)*(Bra12-Bra12Cut));
      dU_db = E*(Koef1*(Minus2-Plus2)*(Brack-BrackCut)+Koef2*(Plus1-Minus1)*(Bra12-Bra12Cut));
      dU_dc = E*((Brack-BrackCut)*(ia_params->GB_nu*E1*E1*ia_params->GB_chi1*ia_params->GB_chi1*c+
0.5*Koef1*ia_params->GB_chi2*(Plus2*Plus2-Minus2*Minus2))-
(Bra12-Bra12Cut)*0.5*Koef2*ia_params->GB_chi1*(Plus1*Plus1-Minus1*Minus1));
      
      /*--------------------------------------------------------------------*/
 
      FikX = -dU_dr*d[0] - dU_da*u1x - dU_db*u2x;
      FikY = -dU_dr*d[1] - dU_da*u1y - dU_db*u2y;
      FikZ = -dU_dr*d[2] - dU_da*u1z - dU_db*u2z;
      
      force[0] += FikX;
      force[1] += FikY;
      force[2] += FikZ;
      
      /* calculate torque: torque = u_1 x G */

      Gx = -dU_da*d[0] - dU_dc*u2x;
      Gy = -dU_da*d[1] - dU_dc*u2y;
      Gz = -dU_da*d[2] - dU_dc*u2z;
      
      torque1[0]+= u1y*Gz - u1z*Gy;
      torque1[1]+= u1z*Gx - u1x*Gz;
      torque1[2]+= u1x*Gy - u1y*Gx;

      /* calculate torque: torque = u_2 x G */

      Gx = -dU_db*d[0] - dU_dc*u1x;
      Gy = -dU_db*d[1] - dU_dc*u1y;
      Gz = -dU_db*d[2] - dU_dc*u1z;

      torque2[0]+= u2y*Gz - u2z*Gy;
      torque2[1]+= u2z*Gx - u2x*Gz;
      torque2[2]+= u2x*Gy - u2y*Gx;
    }
    else { /* the particles are too close to each other */
      Koef1 = 100;
       
      force[0] += Koef1 * d[0];
      force[1] += Koef1 * d[1];
      force[2] += Koef1 * d[2];
    }
}

MDINLINE double gb_pair_energy(Particle *p1, Particle *p2, IA_parameters *ia_params,
double d[3], double dist)
{
  if (!CUTOFF_CHECK(dist < ia_params->GB_cut))
    return 0.0;
  
  double a,b,c, X, Xcut,
    Brack,BrackCut,
    u1x, u1y, u1z,
    u2x, u2y, u2z,
    E,E1,E2, Sigma,
    Plus1, Minus1,
    Plus2, Minus2;

    
    u1x = p1->r.quatu[0]; u1y = p1->r.quatu[1]; u1z = p1->r.quatu[2];
    u2x = p2->r.quatu[0]; u2y = p2->r.quatu[1]; u2z = p2->r.quatu[2];

    a = d[0]*u1x + d[1]*u1y + d[2]*u1z;
    b = d[0]*u2x + d[1]*u2y + d[2]*u2z;
    c = u1x*u2x + u1y*u2y + u1z*u2z;

    Plus1 = (a+b)/(1+ia_params->GB_chi1*c);
    Plus2 = (a+b)/(1+ia_params->GB_chi2*c);
    Minus1 = (a-b)/(1-ia_params->GB_chi1*c);
    Minus2 = (a-b)/(1-ia_params->GB_chi2*c);
    E1 = 1/sqrt(1-ia_params->GB_chi1*ia_params->GB_chi1*c*c);
    E2 = 1-0.5*(ia_params->GB_chi2/dist/dist)*(Plus2*(a+b) + Minus2*(a-b));
    E = 4*ia_params->GB_eps*pow(E1,ia_params->GB_nu)*pow(E2,ia_params->GB_mu);
    Sigma = ia_params->GB_sig/sqrt(1-0.5*(ia_params->GB_chi1/dist/dist)*(Plus1*(a+b) + Minus1*(a-b)));
        
    X = 1/(dist - Sigma + ia_params->GB_sig);
    Xcut = 1/(ia_params->GB_cut - Sigma + ia_params->GB_sig);

    Brack = X*X*X;
    BrackCut = Xcut*Xcut*Xcut;
    Brack = Brack*Brack;
    BrackCut = BrackCut*BrackCut;
    Brack = Brack*(Brack-1);
    BrackCut = BrackCut*(BrackCut-1);

    return E*(Brack-BrackCut);
}

#endif
#endif
Something went wrong with that request. Please try again.