the Question of LAMMPS with fortran program in Bash shell script

Dear all,

I have a question about LAMMPS with fortran program in Bash shell script, my model is about atom deposition, but lammps itself do not have so much function about it(controlling flux or velocity Gaussian distribution), So I built a shell script and use fortran to change input file, but I find Lammps can not be input the force from last run(just coordinate and velocity). so I want to know if I just input coordinate and velocity form last run, does the system will be affected?
actually, it is not a good method, I heard that lammps can be built as a library, can this library be connect with fortran, just like a function in lammps itself ? (for example I use lammps to calculate force form the deposit atom and use lammps to calculate the substrate)

Thanks so much!
Best wish!
Lu Xie

Dear all,

I have a question about LAMMPS with fortran program in Bash shell
script, my model is about atom deposition, but lammps itself do not have
so much function about it(controlling flux or velocity Gaussian
distribution), So I built a shell script and use fortran to change input
file, but I find Lammps can not be input the force from last run(just
coordinate and velocity). so I want to know if I just input coordinate
and velocity form last run, does the system will be affected?
actually, it is not a good method, I heard that lammps can be built as a
library, can this library be connect with fortran, just like a function
in lammps itself ? (for example I use lammps to calculate force form the
deposit atom and use lammps to calculate the substrate)

sure. lammps interfaces to fortran code for the meam and reax
pair styles and you can also interface the library interface with
fortran. however, if all you want to do is to manipulate forces,
it would probably be easier to find a colleague with a little bit
of c/++ experience and write a “fix” class that will add your
modification to the integration loop. even if you want to insert
a fortran subroutine you would need some “glue code”.
the complications of interfacing c/c++ to fortran are probably
larger than just writing a bit of c/c++. for the most part it is
just like free format fortran, only that each line is terminated
with a semi-colon, that array indices are bracketed in square
brackets instead of parenthesis and that arrays (and loops)
typically start at 0 instead of 1.

cheers,
axel.

In addition, if you restart a LAMMPS run (from your script)
using postitions and velocities from a previous run, there
is no need to also re-specify the forces. The forces are
a function of the positions of the atoms. LAMMPS will
re-compute the forces for the new simulation and they
willl be the same as in the old simulation.

Steve

Thanks so much for your suggestions, I try with this today, I find it works well, I use Fortran to creat new "in file" and "data file" every 2ps for changing thermostat and adding atoms. but I also find a problem that, I can not run lammps with parallel that does not for the problem of Fortran serial and lammps parallel, It was about the range in z direction.
In order to prevent that the rejected atom do not exceed the boundary, I set the box in z direction very large, when Lammps run with this range and the error arise "lost atom", So is there a method to solve this problem?:slight_smile:
Thanks a lot again!
Lu.

hmmm... can you try to reduce your description
to a few small sentences, each describing an
individual issue. as it is, i have difficulties to
follow what you are describing.

Thanks so much for your suggestions, I try with this today, I find it works
well, I use Fortran to creat new "in file" and "data file" every 2ps for
changing thermostat and adding atoms.

why? have you looked at "fix deposit" which
can be used to add atoms to a simulation.
thermostats can have ramps or you can
program looped switches. it you need to
add atoms in special positions, you may
be helped more by creating a modified
version of fix deposit.

but I also find a problem that, I can
not run lammps with parallel that does not for the problem of Fortran serial
and lammps parallel, It was about the range in z direction.

i don't understand what this sentence
is supposed to say. please reformulate.

In order to prevent that the rejected atom do not exceed the boundary, I set
the box in z direction very large, when Lammps run with this range and the
error arise "lost atom", So is there a method to solve this problem?:slight_smile:

lost atoms can happen for a lot of reasons.
most of the time, this is a result of bad
contacts or bad physics.

since you don't provide any example,
i would have to guess. do you by any
chance use "shrinkwrap" boundary
conditions in z direction?

axel.

Sorry for my poor describing (I use red color for my problem)

hmmm... can you try to reduce your description
to a few small sentences, each describing an
individual issue. as it is, i have difficulties to
follow what you are describing.


Thanks so much for your suggestions, I try with this today, I find it works
well, I use Fortran to creat new "in file" and "data file" every 2ps for
changing thermostat and adding atoms.

why? have you looked at "fix deposit" which
can be used to add atoms to a simulation.
thermostats can have ramps or you can
program looped switches. it you need to
add atoms in special positions, you may
be helped more by creating a modified
version of fix deposit.

I try with “fix deposit” before, but It can not create the velocity with Gaussian distribution or deposit freely as I want(for example deposit 10 atoms at one time), So I create a txt file which contained all the deposit atoms’ velocity and coordinate with Gaussian distribution. So if I want to check the the cluster growing on different substrate, this is a good method (the pre-deposit atoms’ velocity and coordinate is the same, this is better for compare with different substrate.)
and for the thermostat, it a little bit difficult for me to choose right atoms, for example if I define a region, I just want the specific element with thermostat, so I use Fortran to select specific element in the region, change their ID and use “group pt id <> 123 1123” to define specific thermostat group.
maybe, it more simple to creating a modified version of fix deposit. but I was not familiar with C/C++, but I will try to study it.

but I also find a problem that, I can
not run lammps with parallel that does not for the problem of Fortran serial
and lammps parallel, It was about the range in z direction.

i don't understand what this sentence
is supposed to say. please reformulate.

if I put ./lmp_linux and ./input(a executable file of Fortran) in the qsub for setting specific number of processors, for LAMMPS is parallel and FORTRAN program is serial, but I make a BASH Shell script and it OK with this method, for example

#!/bin/sh
number=0 
while (test $number -lt 1000) 
 do 
   ./input  # run with one processor
   /home/xie/lmp/mpich2/bin/mpirun -np 8 ./lmp_linux < in.graphene  # run with 8 processors

Sorry for my poor describing :frowning: (I use red color for my problem)

sorry, but using a red font is not such a good idea.
that makes the text really hard to read with html
formatting enabled, and it doesn't show up for
people using a text-mode mail program.

[...]

if I put ./lmp_linux and ./input(a executable file of Fortran) in the qsub
for setting specific number of processors, for LAMMPS is parallel and
FORTRAN program is serial, but I make a BASH Shell script and it OK with
this method, for example

#!/bin/sh

number=0

while (test $number -lt 1000)

do

./input # run with one processor

/home/xie/lmp/mpich2/bin/mpirun -np 8 ./lmp_linux < in.graphene # run
with 8 processors

number=`expr $number + 1`

echo "$number"

done

echo

ok. that sounds reasonable.

This shell repeatedly read data and run LAMMPS, if at some time one atom
exceed the boundary of the system, the LAMMPS can not read the data from
data file, So I have to enlarge the boundary to insure that all the atom in
the last run will be read in the next run.

correct.

In order to prevent that the rejected atom do not exceed the boundary, I set
the box in z direction very large, when Lammps run with this range and the
error arise "lost atom", So is there a method to solve this problem?:slight_smile:

lost atoms can happen for a lot of reasons.
most of the time, this is a result of bad
contacts or bad physics.

since you don't provide any example,
i would have to guess. do you by any
chance use "shrinkwrap" boundary
conditions in z direction?

Yes, I choose the "shrinkwarp" in z direction, but it can be work in one
lammps running, but for me when I deposit 10 atoms in 2000 steps, the work
of LAMMPS end. After using the Fortran porgram change the files for LAMMPS,
it restart again. but my "lost atom" arise at the place that if I use 8
processors to run a system while the boundary of this system is

shrinkwrap is the problem. just use "m" instead of "s".
i had this happen to me a while ago. what happens is
that atoms are first distributed according to domains
based on the original box size from you input, but
then at a later point, the box is adjusted to fit the
min/max of your atom positions. with shrinkwrap
that may be result in a _lot_ of shrinkage, which
will indirectly cause the "lost atoms" error. this
of course only happens in parallel runs. there are
two ways to deal with this. you can enforce using
only one processor in that direction through the
command: processors * * 1
or by choosing "m" boundary conditions, which
is like shrinkwrap, but with a minimum size,
that minimum size definition will avoid the
large shrink. you probably want to use both,
since using only 1 processor in z-direction
should give better parallel performance through
better load balancing (otherwise you may
have some processors with only few atoms
in their domain).

"-20.000000 20.000000 xlo xhi

-20.000000 20.000000 ylo yhi

-900000.0000 900000.0000 zlo zhi"

this error arise with lost 1/3 atoms in the system.

yup. exactly.

I am a little bit crazy to this work, :frowning: I should try to study C/C++ and
adding code in LAMMPS itself.

as a person that learned programming in
fortran long before c and c++, i can assure
you, that LAMMPS is written in a very
readable style. the biggest problem is
to get into the "lammps programming
mind", the difference in the programming
language is rather minor.

cheers and good luck,
    axel.