# Description:
# 
# This example shows how to build a multicomponent spherical vesicle.
# The lipid bilayer is composed of two different lipids (DPPC and DLPC), 
# The vesicle contains 120 trans-membrane protein inclusions.
#
# 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: THE COORDINATES FOR THESE MOLECULES ARE GENERATED BY PACKMOL (see below)
# 
# 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.

# First, load the definitions of the molecules we will need:

import "CGLipidBr2005.lt"
using namespace CGLipidBr2005

import "1beadProtSci2010.lt"
using namespace 1beadProtSci2010

# PREREQUISITES:
# Coordinates for the molecules in this example are loaded from an .XYZ file
# created by PACKMOL.  This must be done in advance.  (See ../packmol_files/)
#
# The XYZ file was created by PACKMOL in 3 steps:
# (Add the proteins, then pack lipids in the inner & outer layers around them.)
#
# step1) Creae 120 proteins.  Distribute them on the surface of the sphere.
#
# step2) Keeping the coordinates from step1 fixed, 
#     a) first we add 9500 DPPC lipids to the inner monolayer
#     b)  then we add 9500 DLPC lipids to the inner monolayer
#
# step3) Keeping the coordinates from steps 1 and 2 fixed, 
#     a) first we add 12500 DPPC lipids to the outer monolayer
#     b)  then we add 12500 DLPC lipids to the outer monolayer
#
# The order that molecules are created in moltemplate should match the order
# they appear in the final XYZ file created by PACKMOL.  (See above.)
# Consequently I instantiate the molecules in the same order here:


# Step 1)                   ---- protein inclusions ----

proteins = new 4HelixInsideOut [120]

# Step 2a)                  ---- inner monolayer ----
dppc_in = new DPPC [9500]
# Step 2b)
dlpc_in = new DLPC [9500]

# Step 3a)                  ---- outer monolayer ----
dppc_out = new DPPC [12500]
# Step 3b)
dlpc_out = new DLPC [12500]



# ------------------ boundary conditions --------------------

write_once("Data Boundary") {                                        
  -500.0      500.0       xlo xhi
  -500.0      500.0       ylo yhi
  -500.0      500.0       zlo zhi                                     
}


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"
  communicate multi
}

