# THIS EXAMPLE HAS NOT BEEN RIGOROUSLY TESTED.
# (This simulation may fail.
#  However the "run.in.nvt" example in this directory should work.)
#
#        Requirements:
# To run this system at constant pressure, it might help to compile LAMMPS with
# the optional RIGID package, and use "fix rigid" on the carbon.  (Optional.)
# The use of fix rigid is controversial.  This method is demonstrated below.

# ------------------------------- Initialization Section --------------------

include system.in.init

# ------------------------------- Atom Definition Section -------------------

read_data system.data

# ------------------------------- Settings Section --------------------------

include system.in.settings

# ------------------------------- Run Section -------------------------------


# Only the Cgraphene atoms are immobile.
group mobile subtract all Cgraphene


# Unfortunately you can not use the LAMMPS "minimize" command on this system
# because there is no way to immobilize the carbon graphene & nanotube atoms
# during minimization.  Instead, we can use langevin dynamics with a large 
# damping parameter and a small timestep.

print "--------- beginning minimization (using fix langevin) ---------"

timestep        0.1
fix fxlan mobile langevin 1.0 1.0 100.0 48279
fix fxnve mobile nve   # <-- needed by fix langevin (see lammps documentation)
thermo          100
run 2500

unfix fxlan
unfix fxnve

# -- simulation protocol --

print "--------- beginning simulation (using fix nvt) ---------"

timestep        0.25
dump            1 all custom 1000 traj_npt.lammpstrj id mol type x y z ix iy iz

thermo_style    custom step temp pe etotal press vol epair ebond eangle edihed
thermo          1000  # time interval for printing out "thermo" data





# ------------------------- NPT ---------------------------

# Set temp=300K, pressure=100bar, and equilibrate volume only in the z direction

fix fxMoveStuff mobile npt temp 300 300 100 z 100 100 1000.0 dilate mobile

#  ------ QUESTIONABLE (see below): ------

fix Ffreezestuff Cgraphene rigid/npt single temp 300 300 100 z 100 100 1000.0 force * off off off torque * off off off dilate mobile

#     -- Alternate npt rigid method --
# I'm not sure which way is more correct, however 
# this also seems to behave in a reasonable-looking way:
#fix Ffreezestuff Cgraphene rigid single force * off off off torque * off off off
#
# The use of either "fix rigid" or "fix rigid/npt" to immobilize
# an object is somewhat controversial.  Feel free to omit it.
#(Neither Trung or Steve Plimpton use rigid or rigid/npt for immobilizing 
#molecules, but I noticed that at NPT, it does a better job of maintaining 
# the correct volume. However "fix rigid" has changed since then (2011), 
# so this may no longer be true.  Please use this example with caution.)
#  ----------------------------------------

# IMPORTANT for NPT: You must use "neigh_modify" to turn off calculation of the
#                    forces between immobilized atoms.
neigh_modify exclude group Cgraphene Cgraphene

# The next two lines recalculate the temperature 
# using only the mobile degrees of freedom:

compute tempMobile mobile temp
compute pressMobile all pressure tempMobile

thermo_style custom step c_tempMobile c_pressMobile temp press vol

fix_modify fxMoveStuff temp tempMobile

run             100000

write_restart  system_after_npt.rst
