Running PBS script with LAMMPS

From EVOCD
(Difference between revisions)
Jump to: navigation, search
(Created page with '== Abstract == This example shows how to run LAMMPS (or any other UNIX executable) on a UNIX cluster that uses the batch scripting language, PBS. This will use the LAMMPS input …')
 
Line 6: Line 6:
 
== LAMMPS Input File ==
 
== LAMMPS Input File ==
  
In order to have LAMMPS output data useful for plotting, the simulation cell length must be stored; and the stress and strain data must be written to an external file.The following script shows how the final cell length is stored in the aluminum examples. The cell length is lx, while the initial length of the cell is stored as L0. These values are needed for strain calculation. Note that these commands are written before deformation commands in the input scripts.
+
== Download an input file ==
{|border  ="0"
+
 
|<pre>
+
This input script was run using the Jan 2010 version of LAMMPS.  Changes in some commands may require revision of the input script.  Copy the text below and paste it into a text file, 'calc_fcc.in'.  Use the 'Paste Special' command with 'Unformatted Text'. Notice that the replicate command is used in the following script so that it is a 20 x 20 x 20 simulation cell (32,000 atoms) that is going to be run on 16 processors. Notice that we get the same cohesive energy as that run with 4 atoms in Tutuorial 1.
# Store final cell length for strain calculations
+
variable tmp equal "lx"
+
variable L0 equal ${tmp}
+
variable L0 equal 40.64912642
+
print "Initial Length, L0: ${L0}"
+
Initial Length, L0: 40.64912642
+
</pre>
+
|}
+
  
The following script shows how the aluminum examples write stress and strain data to a file. Strain is calculated from variables defined above and is stored as p1. The principal stresses are first converted to GPa and then stored as p1, p2, and p3. The fix command is used to print these four variables to a new file, in this case, named "Al_comp.def1.txt." When LAMMPS is run, this file appears in the directory with other LAMMPS output files. Note that these commands are written after the deformation procedure in the input scripts.
 
 
{|border  ="0"
 
{|border  ="0"
 
|<pre>
 
|<pre>
# Output strain and stress information to file.
 
# For metal units, pressure is [bars] = 100 [kPa] = 1/10000 [GPa]
 
# p2, p3, and p4 are in GPa
 
  
variable strain equal "(lx - v_L0) / v_L0"
+
# Find minimum energy fcc configuration
variable p1 equal "v_strain"
+
# Mark Tschopp, 2010
variable p2 equal "-pxx/10000"
+
variable p3 equal "-pyy/10000"
+
variable p4 equal "-pzz/10000"
+
fix def1 all print 100 "${p1} ${p2} ${p3} ${p4}" file Al_comp.def1.txt screen no
+
</pre>
+
|}
+
  
== LAMMPS Datafiles ==
+
# ---------- Initialize Simulation ---------------------
The following datafiles were created for the tension and compression aluminum examples.
+
clear
 +
units metal
 +
dimension 3
 +
boundary p p p
 +
atom_style atomic
 +
atom_modify map array
  
Al_SC_100.def1.txt:
+
# ---------- Create Atoms ---------------------
{|border  ="0"
+
lattice fcc 4
|<pre>
+
region box block 0 1 0 1 0 1 units lattice
# Fix print output for fix def1
+
create_box 1 box
0.0009999999119 0.08667300618 0.03175758225 0.03801213452
+
 
0.001999999912 0.09131420312 -0.05499624531 -0.03396621651
+
lattice fcc 4 orient x 1 0 0 orient y 0 1 0 orient z 0 0
0.002999999912 0.2254889267 0.04825004506 0.04680554658
+
create_atoms 1 box
0.003999999912 0.2199842183 -0.04156649661 -0.02074145126
+
replicate 20 20 20
0.004999999912 0.3127067321 0.01435171918 0.01093418588
+
 
...
+
# ---------- Define Interatomic Potential ---------------------  
</pre>
+
pair_style eam/alloy
|}
+
pair_coeff * * Al99.eam.alloy Al
 +
neighbor 2.0 bin
 +
neigh_modify delay 10 check yes
 +
 +
# ---------- Define Settings ---------------------
 +
compute eng all pe/atom
 +
compute eatoms all reduce sum c_eng
 +
 
 +
# ---------- Run Minimization ---------------------
 +
reset_timestep 0  
 +
fix 1 all box/relax iso 0.0 vmax 0.001
 +
thermo 10
 +
thermo_style custom step pe lx ly lz press pxx pyy pzz c_eatoms
 +
min_style cg
 +
minimize 1e-25 1e-25 5000 10000
 +
 
 +
variable natoms equal "count(all)"
 +
variable teng equal "c_eatoms"
 +
variable length equal "lx"
 +
variable ecoh equal "v_teng/v_natoms"
 +
 
 +
print "Total energy (eV) = ${teng};"
 +
print "Number of atoms = ${natoms};"
 +
print "Lattice constant (Angstoms) = ${length};"
 +
print "Cohesive energy (eV) = ${ecoh};"
 +
 
 +
print "All done!"
  
Al_comp.def1.txt:
 
{|border  ="0"
 
|<pre>
 
# Fix print output for fix def1
 
-0.001000000088 -0.06084024339 0.005103309452 0.011634529
 
-0.002000000088 -0.1414344573 -0.02482512452 -0.00442782696
 
-0.003000000088 -0.1893439523 0.009944994037 0.01031293284
 
-0.004000000088 -0.2745471681 -0.01431999273 0.006837682636
 
-0.005000000088 -0.3417247015 -0.005247107989 -0.01437892764
 
...
 
 
</pre>
 
</pre>
 
|}
 
|}
  
== MATLAB Script ==
+
== PBS batch script ==
The stress strain curve for the aluminum in tension and compression examples can be seen in Figures 1 and 2. The following MATLAB script will plot the stress-strain curve for either case, provided the LAMMPS datafile and this script are located in the same directory. Note that values are negative in the compressive case. In order to attain the image in Figure 2, simply make negative the strain and stress variables in the script.
+
 
 +
Here is an example batch script for Raptor.  Copy the text below and paste it into a text file, 'pbs_Raptor_calc_fcc.txt'. Use the 'Paste Special' command with 'Unformatted Text'.  
  
The plot can be saved as a MATLAB figure after it appears. Additionally, the exportfig command, which refers to a script that can be downloaded at the [http://www.mathworks.com/matlabcentral/fileexchange/727-exportfig MATLAB Central File website], exports the plot to a tiff file.
 
 
{|border  ="0"
 
{|border  ="0"
 
|<pre>
 
|<pre>
%% Analyze def1.txt files
 
% Plot the various responses
 
  
d = dir('*.def1.txt');
+
#!/bin/sh
for i = 1:length(d)
+
#PBS -N calc_fcc
    % Get data
+
#PBS -q q16p192h@Raptor
    fname = d(i).name;
+
#PBS -l nodes=4:ppn=4
    A = importdata(fname);
+
#PBS -l walltime=192:00:00
    % Define strain as first column of data in A (*.def1.txt)
+
#PBS -mea
    strain = A.data(:,1);
+
#PBS -r n
    % Define stress as second through fourth columns in A (*def1.txt)
+
#PBS -V
    stress = A.data(:,2:4);
+
cd $PBS_O_WORKDIR
 +
mpirun -np 16 < calc_fcc.in
  
    % Generate plot
 
    plot(strain,stress(:,1),'-or','LineWidth',2,'MarkerEdgeColor','r',...
 
                'MarkerFaceColor','r','MarkerSize',5),hold on
 
    plot(strain,stress(:,2),'-ob','LineWidth',2,'MarkerEdgeColor','b',...
 
                'MarkerFaceColor','b','MarkerSize',5),hold on
 
    plot(strain,stress(:,3),'-og','LineWidth',2,'MarkerEdgeColor','g',...
 
                'MarkerFaceColor','g','MarkerSize',5),hold on
 
    axis square
 
    ylim([0 10])
 
    set(gca,'LineWidth',2,'FontSize',24,'FontWeight','normal','FontName','Times')
 
    set(get(gca,'XLabel'),'String','Strain','FontSize',32,'FontWeight','bold','FontName','Times')
 
    set(get(gca,'YLabel'),'String','Stress (GPa)','FontSize',32,'FontWeight','bold','FontName','Times')
 
    set(gcf,'Position',[1 1 round(1000) round(1000)])
 
 
    % Export the figure to a tif file
 
    exportfig(gcf,strrep(fname,'.def1.txt','.tif'),'Format','tiff',...
 
        'Color','rgb','Resolution',300)
 
 
end
 
 
</pre>
 
</pre>
 
|}
 
|}
  
{|
+
Here is an example batch script for Talon. Copy the text below and paste it into a text file, 'pbs_Talon_calc_fcc.txt'. Use the 'Paste Special' command with 'Unformatted Text'.  
| [[image:Al_SC_100_stress-strain.jpg|thumb|350px|Figure 1. Stress-strain curve for uniaxial tensile loading of single crystal aluminum in the <100> loading direction. ]]
+
| [[image:Al comp sscurve.jpg|thumb|350px|Figure 2. Stress-strain curve for uniaxial compressive loading of single crystal aluminum in the <100> loading direction. ]]
+
|}
+
  
{|
 
| The following script will combine the tensile and compressive curves into a single plot, seen in Figure 3. Note that only the principal stresses in the x direction have been included.
 
 
{|border  ="0"
 
{|border  ="0"
 
|<pre>
 
|<pre>
% Compare responses for Uniaxial Tension and Compression in Single Crystal
 
% Aluminum
 
  
%Find files from which to pull data
+
#!/bin/sh
a = dir('Al_SC_100.def1.txt');
+
#PBS -N calc_fcc
b = dir('Al_comp.def1.txt');
+
#PBS -q q192p48h@Talon
for i = 1:length(a)
+
#PBS -l nodes=16:ppn=12
   
+
#PBS -l walltime=48:00:00
    %Pull data and define columns and stress and strain
+
#PBS -mbea
    fname_t = a(i).name;
+
#PBS -r n
    A = importdata(fname_t);
+
#PBS -V
    strain_t = A.data(:,1);
+
cd $PBS_O_WORKDIR
    stress_t = A.data(:,2);
+
mpirun -np 192 < calc_fcc.in
   
+
 
    fname_c = b(i).name;
+
    B = importdata(fname_c);
+
    strain_c = -B.data(:,1);
+
    stress_c = -B.data(:,2);
+
   
+
    %Plot columns of data on a common graph
+
    plot(strain_t,stress_t,'-or','LineWidth',2,'MarkerEdgeColor','r',...
+
        'MarkerFaceColor','r','MarkerSize',5),hold on
+
    plot(strain_c,stress_c,'-ob','LineWidth',2,'MarkerEdgeColor','b',...
+
        'MarkerFaceColor','b','MarkerSize',5),hold on
+
    axis square
+
    ylim([0,9])
+
   
+
    %Configure labels for the axes
+
    set(gca,'LineWidth',2,'FontSize',12,'FontWeight','normal','FontName','Times')
+
    set(get(gca,'xlabel'),'String','Strain','FontSize',20,'FontWeight','bold','FontName','Times')
+
    set(get(gca,'ylabel'),'String','Stress (GPa)','FontSize',20','FontWeight','bold','FontName','Times')
+
    set(gcf,'Position',[1 1 round(1000) round(1000)])
+
   
+
    %Display a legend to label the curves
+
    legend('show','Tension','Compression')
+
   
+
    % Export the figure to a tif file
+
    exportfig(gcf,strrep(fname_t,'Al_SC_100.def1.txt','jointfig.tif'),'Format','tiff',...
+
        'Color','rgb','Resolution',300)
+
end
+
 
</pre>
 
</pre>
|}
 
| [[image:Al ss tension comp.jpg|thumb|350px|Figure 3. Stress-strain curve for uniaxial tensile and compressive loading of single crystal aluminum in the <100> direction. ]]
 
 
|}
 
|}

Revision as of 09:44, 26 January 2011

Contents

Abstract

This example shows how to run LAMMPS (or any other UNIX executable) on a UNIX cluster that uses the batch scripting language, PBS. This will use the LAMMPS input script from tutorial 1.

Author(s): Mark A. Tschopp

LAMMPS Input File

Download an input file

This input script was run using the Jan 2010 version of LAMMPS. Changes in some commands may require revision of the input script. Copy the text below and paste it into a text file, 'calc_fcc.in'. Use the 'Paste Special' command with 'Unformatted Text'. Notice that the replicate command is used in the following script so that it is a 20 x 20 x 20 simulation cell (32,000 atoms) that is going to be run on 16 processors. Notice that we get the same cohesive energy as that run with 4 atoms in Tutuorial 1.


# Find minimum energy fcc configuration
# Mark Tschopp, 2010

# ---------- Initialize Simulation --------------------- 
clear 
units metal 
dimension 3 
boundary p p p 
atom_style atomic 
atom_modify map array

# ---------- Create Atoms --------------------- 
lattice 	fcc 4
region	box block 0 1 0 1 0 1 units lattice
create_box	1 box

lattice	fcc 4 orient x 1 0 0 orient y 0 1 0 orient z 0 0 1  
create_atoms 1 box
replicate 20 20 20

# ---------- Define Interatomic Potential --------------------- 
pair_style eam/alloy 
pair_coeff * * Al99.eam.alloy Al
neighbor 2.0 bin 
neigh_modify delay 10 check yes 
 
# ---------- Define Settings --------------------- 
compute eng all pe/atom 
compute eatoms all reduce sum c_eng 

# ---------- Run Minimization --------------------- 
reset_timestep 0 
fix 1 all box/relax iso 0.0 vmax 0.001
thermo 10 
thermo_style custom step pe lx ly lz press pxx pyy pzz c_eatoms 
min_style cg 
minimize 1e-25 1e-25 5000 10000 

variable natoms equal "count(all)" 
variable teng equal "c_eatoms"
variable length equal "lx"
variable ecoh equal "v_teng/v_natoms"

print "Total energy (eV) = ${teng};"
print "Number of atoms = ${natoms};"
print "Lattice constant (Angstoms) = ${length};"
print "Cohesive energy (eV) = ${ecoh};"

print "All done!" 

PBS batch script

Here is an example batch script for Raptor. Copy the text below and paste it into a text file, 'pbs_Raptor_calc_fcc.txt'. Use the 'Paste Special' command with 'Unformatted Text'.


#!/bin/sh 
#PBS -N calc_fcc 
#PBS -q q16p192h@Raptor 
#PBS -l nodes=4:ppn=4 
#PBS -l walltime=192:00:00 
#PBS -mea 
#PBS -r n 
#PBS -V 
cd $PBS_O_WORKDIR 
mpirun -np 16 < calc_fcc.in

Here is an example batch script for Talon. Copy the text below and paste it into a text file, 'pbs_Talon_calc_fcc.txt'. Use the 'Paste Special' command with 'Unformatted Text'.


#!/bin/sh 
#PBS -N calc_fcc
#PBS -q q192p48h@Talon 
#PBS -l nodes=16:ppn=12 
#PBS -l walltime=48:00:00 
#PBS -mbea 
#PBS -r n 
#PBS -V 
cd $PBS_O_WORKDIR 
mpirun -np 192 < calc_fcc.in

Personal tools
Namespaces

Variants
Actions
home
Materials
Material Models
Design
Resources
Projects
Education
Toolbox