LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] Questions about loop in lammps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lammps-users] Questions about loop in lammps


From: Axel Kohlmeyer <akohlmey@...24...>
Date: Wed, 13 Dec 2017 11:37:31 -0500



On Wed, Dec 13, 2017 at 3:43 AM, Xuechen Zheng <xuechen_zheng@...730...> wrote:

DearDrAxel

Thanks for your advice!

Actually, the force is calculated through a potential energy state which gived in python.

​that is not helping.​

I just want to calculated the force of every atom directlly from python and add it to lammps. So you mean it is intolerable for lammps to do it? 

​i have already written down what i mean in my previous e-mail. i don't see the point of repeating it.
the short message is, the way you are trying to implement your feature *cannot* work because you don't understand the flow of control and the data structures in LAMMPS.
...and unless you provide more specific information, nobody can give you more specific advice.

axel.

 

 
 Thanks!


Xuechen Zheng


-----原始邮件-----
发件人:"Axel Kohlmeyer" <akohlmey@...24...>
发送时间:2017-12-13 12:01:38 (星期三)

收件人: "Xuechen Zheng" <xuechen_zheng@...7279.....>
抄送: "LAMMPS Users Mailing List" <lammps-users@...396...sourceforge.net>
主题: Re: [lammps-users] Questions about loop in lammps



On Tue, Dec 12, 2017 at 8:17 PM, Xuechen Zheng <xuechen_zheng@...36.....730...> wrote:

Dear Dr Axel,

    I have another question. The python scripts need to input a atom coordinate to get the force. It cannot input all atoms' coordinate. The previous way is to set the first atom's coordinate as the input for python. I do not know how to use compute reduce to input the coordinate to python one by one and then get the sum of the force. Could you tell me more about it?

you are not making much sense here.

specifically, you don't seem to be understanding the data model of LAMMPS and how it is parallelized.

doing a loop over all atoms at the LAMMPS script level and calling a python function for every atom is a procedure that is very slow even for a single atom, but intolerable for all of them. it particularly will defeat all parallelization, since you turn the processing across processors and distributed data structures into slow global operations.

it also, is not clear from your description whether you want to compute a different, position dependent force for each atom, or put the sum over position depended forces into fix addforce.
finally, how is your force defined in the python function? unless you are doing complex operations, perhaps it will be easier (and faster) to do the same computation with an atom style variable.
or you'd have to avoid passing arguments at all and access all LAMMPS data structures directly inside the python function via the lammps python module and then do the computation across all atoms.
there is still a good chance, that with a python function things will be slowed down significantly. so for a complex operation, implementing in python would at best serve for prototyping and then require a C++ implementation for good performance.

at any rate, you need to spend more time studying various examples about how to compute properties, how to access data, and how to avoid serializing parallel operations.

axel.

 



Thanks!   




Xuechen Zheng



-----原始邮件-----
发件人:"Axel Kohlmeyer" <akohlmey@...24...>
发送时间:2017-12-13 00:05:48 (星期三)
收件人: "Xuechen Zheng" <xuechen_zheng@...7279.....>
抄送: "LAMMPS Users Mailing List" <lammps-users@...42...e.net>
主题: Re: [lammps-users] Questions about loop in lammps

Don't do a loop, use compute reduce instead. 
Axel 



--
Dr. Axel Kohlmeyer  akohlmey@...24...  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.

On Dec 12, 2017 10:54, "Xuechen Zheng" <xuechen_zheng@...730...> wrote:

Dear all,

   I would like to addforce to lammps and the force is calculated by python scripts. However, it seems that it just evaluates the forces per atom. I want to sum the force of all atoms and add it to all atoms. The present input file is 

variable         tz2 equal z[1]
 variable         tx2 equal x[1]

 variable         tz2 equal z[1]

 variable         force_z python force_CH4_z
 python           force_CH4_z input 3 v_tx2 v_ty2 v_tz2 return v_force_z format ffff file  interp.py

 fix               3 all addforce 0 0 v_force_z

It just calculate the first atom's force and it works. Could you tell me how to do a loop that can sum the force of all atoms and do the remaining calculation. I tried the flowing commend

label            loop 

variable         a loop 100

variable         tz2 equal z[a]

variable         tx2 equal x[a]

variable         ty2 equal y[a]


variable         force_z python force_CH4_z

python           force_CH4_z input 3 v_tx2 v_ty2 v_tz2 return v_force_z format ffff file interp.py

fix               3 all addforce 0 0 v_force_z

clear

next              a

jump             z_move.force

"

But the result is that "Segmentation fault". Could you tell me how to set a corect loop? 

Thanks!



Xuechen Zheng



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
lammps-users mailing list
lammps-users@...655....net
https://lists.sourceforge.net/lists/listinfo/lammps-users





------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
lammps-users mailing list
lammps-users@...655....net
https://lists.sourceforge.net/lists/listinfo/lammps-users




--
Dr. Axel Kohlmeyer  akohlmey@...24...  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
lammps-users mailing list
lammps-users@...6297....sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lammps-users




--
Dr. Axel Kohlmeyer  akohlmey@...12...24...  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.