# Description:

# This example shows how to put a protein (inclusion) in a 
# lipid bilayer mixture composed of two different lipids (DPPC and DLPC).
# The DPPC lipid model is described here:
#      G. Brannigan, P.F. Philips, and F.L.H. Brown,
#      Physical Review E, Vol 72, 011915 (2005)
# The protein model is described here:
#      G. Bellesia, AI Jewett, and J-E Shea, 
#      Protein Science, Vol19 141-154 (2010)
# The new DLPC model is a truncated version of DPPC, 
# (Its behaviour has not been rigorously tested.)
# Note that 50%/50% mixtures of DPPC & DLPC are commonly used to 
# build liposomes http://www.ncbi.nlm.nih.gov/pubmed/10620293

# Note:
#   This example may require additional features to be added to LAMMPS.
# If LAMMPS complains about an "Invalid pair_style", then copy the code
# in the "additional_lammps_code" directory into your LAMMPS "src" directory
# and recompile LAMMPS.



import "CGLipidBr2005.lt"

using namespace CGLipidBr2005

# The "= new random" syntax chooses one of several molecules at random

lipids = new random([DPPC, DLPC], [0.5,0.5], 1234)    #"1234"=random_seed
                    [13].move(7.5,    0,     0)
                    [15].move(3.75, 6.49519, 0)  # <-- hexagonal lattice
                     [2].rot(180, 1, 0, 0)       # <-- 2 monolayers

# Move all the lipds up to the center of the box

lipids[*][*][*].move(0,0,75.0)




# Although this patch of lipids is not square or rectangular, (it looks 
# like a parallelogram), this is no longer the case after rectangular
# periodic boundary conditions are applied. (Check by visualising in VMD.)


write_once("Data Boundary") {                                        
  0        97.5         xlo xhi
  0        97.42785792  ylo yhi
  0        150.0        zlo zhi                                     
}


# A note on geometry:
# We want to create a bilayer arranged in a hexagonal lattice consisting of
#    15 rows     (each row is aligned with the x-axis)
#    13 columns  (aligned at a 60 degree angle from the x axis)
# The lattice spacing is 7.5 Angstroms.
# When wrapped onto a rectangular box, the dimensions of the system are:
#    13 * 7.5 Angstroms           in the X direction
#    15 * 7.5*sqrt(3)/2 Angstroms in the Y direction







# ------------------- protein inclusion ---------------------

import "1beadProtSci2010.lt"

using namespace 1beadProtSci2010

protein = new 4HelixInsideOut

protein.move(45.0, 25.98076211, 75.0)


# Delete a hole in the membrane to create space for the protein.

delete lipids[4][2][*]
delete lipids[6][2][*]
delete lipids[3-6][3][*]
delete lipids[3-5][4][*]
delete lipids[2-5][5][*]
delete lipids[2][6][*]
delete lipids[4][6][*]

# Note: All atom types must include the full path (the name of
# the namespace which defined them as well as the atom type name).
# (This is because we are no longer inside that namespace.)


write_once("In Settings") {

  # -----------------------------------------------------------
  # -------- interactions between protein and lipids ----------
  # -----------------------------------------------------------

  # Interactions between the protein and lipid atoms are usually
  # determined by mixing rules.  (However this is not possible some 
  # for atoms, such as the "int" atoms in the lipid model which 
  # interact using -1/r^2 attraction.)  Mixing rules do not make
  # sense for these atoms so we must explicitly define their 
  # interaction with all other atoms.

  # We want the hydrophobic interactions between hydrophobic residues in 
  # the protein and beads the interior of the lipid to be energetically 
  # similar to the attractive interactions between the lipid tails.
  #
  # Note: I made the width of the outward-facing protein beads slightly larger
  # ("12.5") whenever they interact with the "tail" beads in each lipid
  # (in order to make the protein wider there).
  # This hopefully relieves some of the internal negative pressure in the center
  # of the bilayer which can otherwise rip apart the protein or suck it into 
  # the bilaer.  (This is a hack, and I'm not sure if it is necessary.
  # For different protein or lipid models, you probably don't need this.)
  #
  #                  i                      j                   pairstylename                     eps   sig  K  L

  pair_coeff @atom:CGLipidBr2005/tail      @atom:1beadProtSci2010/sH lj/charmm/coul/charmm/inter 0.1643 12.5 0.4 -1
  pair_coeff @atom:CGLipidBr2005/int       @atom:1beadProtSci2010/sH lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 -1

  # To help keep the protein from tilting 90 degrees and burying itself 
  # within the lipid bilayer, we make the turn regions at either 
  # end of the protein (strongly)  attracted to the head groups 
  # of the lipid.  (In reality, they  would probably be attracted 
  # to the water as well.)

  pair_coeff @atom:CGLipidBr2005/DPPC/head @atom:1beadProtSci2010/tN lj/charmm/coul/charmm/inter 1.8065518 5.5 1 -1
  pair_coeff @atom:CGLipidBr2005/DPPC/head @atom:1beadProtSci2010/tN lj/charmm/coul/charmm/inter 1.8065518 5.5 1 -1

  # All other interactions between proteins and lipids are steric.

  pair_coeff @atom:CGLipidBr2005/tail      @atom:1beadProtSci2010/sL lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0
  pair_coeff @atom:CGLipidBr2005/tail      @atom:1beadProtSci2010/tN lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0

  pair_coeff @atom:CGLipidBr2005/int       @atom:1beadProtSci2010/sL lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0
  pair_coeff @atom:CGLipidBr2005/int       @atom:1beadProtSci2010/tN lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0

  pair_coeff @atom:CGLipidBr2005/DPPC/head @atom:1beadProtSci2010/sH lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0
  pair_coeff @atom:CGLipidBr2005/DPPC/head @atom:1beadProtSci2010/sL lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0

  pair_coeff @atom:CGLipidBr2005/DLPC/head @atom:1beadProtSci2010/sH lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0
  pair_coeff @atom:CGLipidBr2005/DLPC/head @atom:1beadProtSci2010/sL lj/charmm/coul/charmm/inter 0.1643 7.5 0.4 0


  # -----------------------------------------------------------
  # -------- Modifications to the protein model: --------------
  # -----------------------------------------------------------
  #
  # Turn off attraction between the hydrophobic "@atom:sH" beads:
  # (These beads are located in the outside of a trans-membrane protein.)

  pair_coeff @atom:1beadProtSci2010/sH @atom:1beadProtSci2010/sH lj/charmm/coul/charmm/inter  1.8065518 5.5 1 0

  # (Why: These beads are only attracted to 
  #       each other in an aqueous environment)

  # ... and
  # Turn ON attraction between the hydrophilic "@atom:sL" beads.
  # (These beads are located in the interior of a trans-membrane protein.)

  pair_coeff @atom:1beadProtSci2010/sL @atom:1beadProtSci2010/sL lj/charmm/coul/charmm/inter  1.8065518 5.5 1 -1

  # Why?
  #   In reality, polar groups in the interior of trans-membrane 
  # proteins do form hydrogen bonds with each other.  This was 
  # absent from the original protein model because, in an aqueous 
  # environment, these groups preferentially interact with the water.
  #
  # Why is this necessary?
  #   Shouldn't attraction between lipid tails and the protein create
  # an effective force which brings the hydrophilic beads together?
  # (similar to the hydrophobic effect, but in reverse?).
  # Answer:
  #   Unlike an aqueous environment (~zero pressure, or +1atm), there is 
  # a large negative pressure in the interior of some bilayer membrane 
  # models (such as this one).  Without some kind of direct attraction 
  # between interior residues, the protein will get pulled apart.
  # (Perhaps the attractive force I am using is too strong?)

}




# Finally, we must combine the two force-field styles which were used for
# the coarse-grained lipid and protein.  To do that, we write one last time 
# to the "In Init" section.  When reading the "Init" section LAMMPS will 
# read these commands last and this will override any earlier settings.

write_once("In Init") {
  # -- These styles override earlier settings --
  units           real
  atom_style      full
  # (Hybrid force field styles were used for portability.)
  bond_style      hybrid harmonic
  angle_style     hybrid cosine/delta harmonic
  dihedral_style  hybrid fourier
  improper_style  none
  pair_style  hybrid table linear 1130 lj/charmm/coul/charmm/inter es4k4l 14.5 15
  pair_modify     mix arithmetic
  special_bonds   lj 0.0 0.0 1.0   # turn off pairs if "less than 3 bonds"
}

