units real
atom_style full
boundary p p p  # Periodic boundaries in all directions
newton on  # Faster calculations with Newton’s third law

# Define force field parameters before reading data
pair_style lj/cut/coul/long 15.0  # Cutoff for Lennard-Jones and Coulombic
kspace_style pppm 1.0e-4  # Long-range electrostatics
bond_style harmonic
angle_style harmonic
dihedral_style opls
improper_style cvff

# Read data file
read_data loop1.lmp
log log.loop2.lammps

# Replicate the simulation box
# replicate 10 1 10 # Uncomment if needed

pair_modify mix arithmetic  # Lorentz-Berthelot mixing rules

# Neighbor list
neighbor 4.0 bin
neigh_modify delay 0 every 1 check yes
neigh_modify page 50000 one 5000

# Output trajectory
dump 1 all atom 5000 loop2.lammpstrj
dump_modify 1 scale yes

# Output thermodynamics
thermo_style custom step temp etotal ke pe vol density press epair ebond eangle edihed
thermo 1000

# Energy minimization
min_style cg
minimize 1.0e-4 1.0e-6 1000 10000

# Time step
timestep 0.5

# The mom and rot keywords are used by create. If mom = yes, the linear momentum of the newly created ensemble of velocities is zeroed; if rot = yes, the angular momentum is zeroed.
# dist value = uniform or gaussian
velocity all create 800 11111 mom yes rot yes dist gaussian
# run_style respa 3 2 1 bond 1 angle 1 dihedral 1 pair 2 kspace 3
variable dt equal dt

variable infile index in.loop2.sh
variable Tstep equal 5.0
variable Tstart equal 800
variable Pstep equal 9.99
variable Pstart equal 1000
dump dump.loop2 all xyz 25000 dump.loop2.xyz
variable k loop 100
label loop2
    variable Tstop equal 800-$k*${Tstep}
    variable Pstop equal 1000-$k*${Pstep}
    fix npt2 all npt temp ${Tstart} ${Tstop} 100.0 iso ${Pstart} ${Pstop} 1000
    run 5000 # 125000 1000000 Femtosecond equal 1 Nanosecond
    unfix npt2
    write_data loop2.${k}.lmp
    variable kPrevious equal $k-1
    shell rm -f loop2.${kPrevious}.lmp
    variable Tstart equal ${Tstop}
    variable Pstart equal ${Pstop}
    next k
jump ${infile} loop2


# Write final state
write_data loop2.lmp
