This example shows how to use the Effective Screening Medium Method (ESM) 
and constant bias potential (constant-mu) method to calculate the total energy, 
charge density, force, and potential of a polarized or charged slab (which
can be also be molecules and clusters)

ESM screens the electronic charge of a polarized/charged medium along one 
perpendicular direction by introducing a classical charge model and a local 
relative permittivity into the first-principles calculation framework. This 
permits calculations using open boundary conditions (OBC). The method is 
described in detail in M. Otani and O. Sugino, "First-principles calculations 
of charged surfaces and interfaces: A plane-wave nonrepeated slab approach," 
PRB 73, 115407 (2006).

Using the constant-mu method one can control the Fermi energy, i.e.
applied bias, during a simulation. The method is described in detail in
N. Bonnet, T. Morishita, O. Sugino, and M. Otani, "First-Principles Molecular 
Dynamics at a Constant Electrode Potential", PRL 109, 266101 (2012).

In addition to 'pbc' (ordinary periodic boundary conditions with ESM 
disabled), the code allows three different sets of boundary conditions 
perpendicular to the polarized slab:

1) 'bc1' : Immerse the slab between two semi-infinite vacuum regions; 
2) 'bc2' : Immerse the slab between two semi-infinite metallic electrodes, 
           with optional fixed field applied between them.
           Constant-mu method is available for controlling the Fermi energy. 
3) 'bc3' : Immerse the slab between one semi-infinite vacuum region (left-hand
           side) and one semi-infinite metallic electrode (right-hand side).
           Constant-mu method is available for controlling the Fermi energy. 

Two dimensional (xy-plane) average charge density and electrostatic potentials
are printed out into 'esm1' file.

The example calculation proceeds as follows:

esm_bc = 'pbc':

1) make a self-consistent calculation for H2O with esm_bc = 'pbc' (ESM off)
   (input=H2O_pbc.in, output=H2O_pbc.out). Using 'pbc' causes the
   code to print out the density and potential (hartree + local) along z, even
   though ESM is disabled. Note that the molecule has a z-oriented dipole.

2) make a self-consistent calculation for Al(001) with esm_bc = 'pbc'
   (input=Al001_pbc.in, output=Al001_pbc.out). 

3) make a self-consistent calculation for graphene with esm_bc = 'pbc'
   Stress calculation is enabled.

esm_bc = 'bc1':

4) make a self-consistent calculation for H2O with esm_bc = 'bc1'
   (input=H2O_bc1.in, output=H2O_bc1.out). This simulates the water molecule 
   in an infinite vacuum along the z-direction, preventing dipole-dipole 
   interaction between periodic images. 

5) make a self-consistent calculation for Al(001) with esm_bc = 'bc1' 
   (input=Al001_bc1.in, output=Al001_bc1.out). 

6) make a self-consistent calculation for graphene with esm_bc = 'bc1'
   (input=graphene_bc1.in, output=graphene_bc1.out).
   Stress calculation is enabled.

7) make a variable cell (vc-relax) calculation for graphene with esm_bc = 'bc1'
   (input=graphene_bc1_vc-relax.in, output=graphene_bc1_vc-relax.out). 
   This simulation starts from slightly distorted cell (angle of lattice vector 
   is 117 degree) and ends with hexagonal cell (angle of lattice vector is 120 
   degree).

esm_bc = 'bc2':

8) make a self-consistent calculation for Al(001) with esm_bc = 'bc2',
   without an applied field (input=Al001_bc2.in, output=Al001_bc2.out). 
   This simulates the slab sandwiched between two uncharged semi-infinite 
   metal electrodes. 

9) make a self-consistent calculation for Al(001) with esm_bc = 'bc2',
   this time with an applied field (input=Al001_bc2_efield.in, 
   output=Al001_bc2_efield.out). The slab polarizes in response.

10) make a self-consistent calculation for graphene with esm_bc = 'bc2',
   input=graphene_bc2.in, output=graphene_bc2.out).
   Stress calculation is enabled.

esm_bc = 'bc3':

11) make a self-consistent calculation for Al(001) with esm_bc = 'bc3' to 
   simulate a slab in contact with semi-infinite  metal electrode (right-
   hand side).
   (input=Al001_bc3.in, output=Al001_bc3.out).

12) make a self-consistent calculation for Al(001) with esm_bc = 'bc3' to 
   simulate a slab in contact with semi-infinite metal electrode with 
   a weakly negative (-0.02e) overall charge (input=Al001_bc3_m002.in, 
   output=Al001_bc3_m002.out). Note that the charge migrates to the right
   surface of the slab.

13) Repeat #6 but with a weakly positive (+0.02e) overall charge 
   (input=Al001_bc3_p002.in, output=Al001_bc3_p002.out).

14) make a 'relax' calculation on both geometory and Fermi energy for Al(001)
   with esm_bc = 'bc3' (input=Al001_bc3_v00.in, output=Al001_bc3_v00.out).
   The target Fermi energy is set to that of the neutral surface (#11, Vpzc).
   (input=Al001_bc3_v00.in, output=Al001_bc3_v00.out).
   
15) Repeat #8 but with a higher target Fermi energy (+0.5V vs Vpzc).
   (input=Al001_bc3_vp05.in, output=Al001_bc3_vp05.out).

16) Repeat #8 but with a lower target Fermi energy (-0.5V vs Vpzc).
    (input=Al001_bc3_vm05.in, output=Al001_bc3_vm05.out).

17) make a self-consistent calculation for graphene with esm_bc = 'bc3'
    (input=graphene_bc3.in, output=graphene_bc3.out).

18) make a variable cell (vc-relax) calculation for graphene with esm_bc = 'bc3'
    (input=graphene_bc3_vc-relax.in, output=graphene_bc3_vc-relax.out).
    The graphene is weakly positive (+0.02e) overall charge. The angle of the
    unit cell is converged to 120 degree.
