<< Graphics`Arrow3D`

(Subscript[ϵ, 0]) =  8.85419*^-12

e  =  1.60219*^-19

rbond =  2.5*^-10

rlat = 2.815*^-10

color[chloride] = RGBColor[0, 0.8, 0];

color[sodium] = RGBColor[0.8, 0, 0];

radius[chloride] = 0.05;

radius[sodium] = 0.04;

particlePoint[{particle_, coords_}] := {color[particle],
        PointSize[radius[particle]], Point[coords]}

sampleLattice = {{sodium, {-rlat, -rlat, 0}}, {
          sodium, {-rlat, rlat, 0}}, {sodium, {0, 0, 0}}, {
          sodium, {rlat, -rlat, 0}}, {sodium, {rlat, rlat, 0}}, {
          chloride, {-rlat, 0, 0}}, {chloride, {0, -rlat, 0}}, {
          chloride, {0, rlat, 0}}, {chloride, {rlat, 0, 0}}}

Map[particlePoint,  sampleLattice]

Show[Graphics3D[%], ViewPoint -> {0, 0, 5}]

sodiumLattice[size_] :=
      Flatten[Table[{sodium, {i rlat, j rlat, 0}}, {i, -size, size}, {
            j, Mod[i + size, 2] - size, size - Mod[i + size, 2], 2}], 1]

chlorideLattice[size_] :=
      Flatten[Table[{chloride, {i rlat, j rlat, 0}}, {i, -size, size}, {
            j, Mod[i + 1 + size, 2] - size, size - Mod[i + 1 + size, 2], 2}],
        1]

lattice[size_] := Join[sodiumLattice[size], chlorideLattice[size]]

lattice[2]

Map[particlePoint, lattice[2]]

Show[Graphics3D[%], ViewPoint -> {0, 0, 5}]

mag[vector_] := Sqrt[vector . vector]

(Subscript[F, like])[r_List]  :=
      -(((e^2) r)/(4 π (Subscript[ϵ, 0 ])
              mag[r]^3))

(Subscript[F, opp])[r_List]  :=
      (((e^2) r)/(4 π (Subscript[ϵ, 0])))
        ((1/mag)[r]^3 - ((((rbond))^8)/mag)[r]^11)

forceBetween[{particle1_, coords1_}, {particle2_, coords2_}] :=
      forceFunction[particle1, particle2][coords2 - coords1]

forceFunction[chloride, chloride] = (Subscript[F, like]);

forceFunction[sodium, sodium] = (Subscript[F, like]);

forceFunction[chloride, sodium] = (Subscript[F, opp]);

forceFunction[sodium, chloride] = (Subscript[F, opp]);

forceBetween[{sodium, {1.87*^-10, 9.37*^-11, -1.87*^-10}}, {
        sodium, {0, 0, 0}}]

ions = {{chloride, {0, 0, 3.0*^-10}}, {sodium, {0, 0, 0}}};

Map[particlePoint, ions]

Show[Graphics3D[%],
      PlotRange -> {{-4.0*^-10, 4.0*^-10}, {-4.0*^-10, 4.0*^-10}, {
            -4.0*^-10, 4.0*^-10}}]

\(scaling\  = \ 0.05; 
z = 3.0*^-10; 
force = {0, 0, \(-1.97*^-9\)};
    
{Arrow3D[{0, 0, z}, {0, 0, z} + force*scaling],
      Map[particlePoint, ions]}; \)

Show[Graphics3D[%],
      PlotRange -> {{-4.0*^-10, 4.0*^-10}, {-4.0*^-10, 4.0*^-10}, {
            -4.0*^-10, 4.0*^-10}}]

Clear[scaling, z, force]

forceFrom[ion_] := forceBetween[{chloride, {0, 0, 3.0*^-10}}, ion]

forces = Map[forceFrom, sampleLattice]

Apply[Plus, forces]

allIons = Prepend[sampleLattice, {chloride, {0, 0, 3.0*^-10}}]

Map[particlePoint, allIons]

Show[Graphics3D[%]]

Clear[z]

forceFrom[ion_] := forceBetween[{chloride, {0, 0, z}}, ion]

forces = Map[forceFrom, sampleLattice]

zforce = Apply[Plus, forces][[3]]

FindRoot[zforce == 0, {z, rbond}, AccuracyGoal -> 15]