LAMMPS is not missing a term. We just haven't shown where the term is in the source code to Harold's satisfaction. I'll give it a shot.
First, we need to be clear about what term we're talking about. We're talking about the term that Harold refers to in this paragraph:
> all charge-charge interactions are
> calculated in kspace, and the spurious intramolecular interactions
> are removed in real space with a term like the following
>
> -qi * qj * erf(g_ewald * |rij|) / (|rij|)
>
> for each excluded intramolecular i,j particle pair. Note this is
> the error function, erf, and NOT the complementary erfc which is
> used in the non-bonded real space term. This term is not as
> well-known as the self term, and is not explained in Frenkel and
> Smit or Allen and Tildesley for simplicity. DL_POLY has it in
> their manual:
> http://wanglab.bu.edu/DLPOLY2/node65.html , eq. 2.131, last term.
Let's call it the "intramolecular self term," which is not to be confused with the regular "self term": qi*qj*alpha/sqrt(pi). LAMMPS correctly includes both of these.
Next, note that we've so far been talking only about energies. These terms take a different form when converted to forces. The regular "self term" is independent of particle positions, so it does not contribute to the force. Ahmed and Harold have already identified the "self term" energy contribution:
> Regarding Ahmed's reply, I have indeed found the self terms in
> ewald.cpp, about line 285: ( energy -= g_ewald*qsqsum/1.772453851
> +). This is the well known correction due to the spurious
> interaction of a point charge with the Gaussian cloud centered
> about the same particle, and is different from the excluded
> intramolecular terms.
But the "intramolecular self term" contributes to both the energy and the force. We've already agreed upon the correct expression for the energy (-qi * qj * erf(g_ewald * |rij|) / (|rij|)), but no one in this thread has given the correct expression for the force yet. So, we just need to come up with the correct expression for the force (left as an exercise for the reader), point to the code that includes the energy and force versions of the term, and convince everyone that the energy and force versions of the term in LAMMPS are the same as what we've identified the energy and force versions of the term should be (left as exercises for the reader). Let's start with the LAMMMPS code for the contribution to the force. Steve has already pointed us to the code that does this:
>> The simplest bit of code that does this is in
>> pair_lj_cut_coul_long.cpp, Similar code is in any pair style with
>> a "long". Here it is:
>>
>> prefactor = qqrd2e * qtmp*q[j]/r;
>> forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
>> if (factor_coul< 1.0) forcecoul -=
>> (1.0-factor_coul)*prefactor;
>>
>> Factor_coul is a value from 0 to 1 (inclusive), which is setup by
>> the special_bonds command and is peculiar to this pair of atoms.
>> So it is being applied only to the closest pair of all the images
>> of these 2 atoms.
The LAMMPS contribution to the energy can be found in the same function about 40 lines further down (line 186 in pari_lj_cut_coul_long.cpp in the version I'm looking at):
if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
But this doesn't look the same as "intramolecular self term" contribution to the energy that we've agreed upon above. Let's assume that factor_coul is zero, meaning that we want to turn off the interaction. Stepping through some algebra, we get:
prefactor = qqrd2e * qtmp*q[j]/r;
ecoul -= (1.0-factor_coul)*prefactor;
ecoul -= qqrd2e * qtmp*q[j]/r;
which tells us we've subtracted off the entire interaction, including the kspace and real space contributions. But this is OK since LAMMPS has already added both the real and kspace contributions to this term. Both the real space and kspace contributions were added in the same way as all of the other non-cancelled terms. So the form of the equation that we identified for the "intramolecular self term" energy never shows up, but in the end, the math is done correctly in LAMMPS.
In the interest of time, I'll leave the corresponding analysis for the force term as an exercise for the reader.
Paul