[ase-users] ASE LAMMPS: update Atoms object coordinates and use constraints
Spencer Hills
spencer.hills at my.wheaton.edu
Fri Mar 17 18:20:13 CET 2017
Hello,
Thanks for changes! These work well!
-Spencer
On Wed, Mar 15, 2017 at 4:40 AM, - <mazay0 at gmail.com> wrote:
> This code should work for you (changed to Pt, because I do not have
> Au.tersoff). Read comments in code for details.
> I have added set_atoms parameter to the run() method. So you need to
> checkout the last commit (a9a0e38dcd9ee10eb0bb94099e089d65474285d2) from
> https://gitlab.com/Mazay0/ase/tree/lammps-multistep
>
>
> #!/usr/bin/python3 -u
>
> import sys,os
> sys.path = ['/home/mazay/prg/ase/'] + sys.path
> import ase
> from ase.data import atomic_numbers, chemical_symbols, atomic_masses
>
>
> from ase import Atoms, Atom
>
> from ase.io import read,write
>
> from ase.calculators.lammpsrun import LAMMPS
>
> masses = ['1 ' + str(atomic_masses[atomic_numbers['Pt']]/(
> ase.units.kg/(1000.*ase.units.mol)) )]
>
> from ase.cluster.icosahedron import Icosahedron
> os.environ['LAMMPS_COMMAND']='/usr/bin/lammps'
>
> atoms = Icosahedron('Pt', noshells=7)
> print ('atoms.positions[10]', atoms.positions[10]) # initial coordinates
>
> parameters = {'pair_style':'tersoff','pair_coeff':["* * Au.tersoff
> Pt"],'boundaries':'p p p','mass':masses} #define lammps input file
> parameters
> # NO minimize! NO run!
>
> files=["Au.tersoff"] #call potential file
> calc = LAMMPS(files=files,parameters=parameters, keep_tmp_files=True)
> #input to calculator
> atoms.set_calculator(calc) #set calculator
> print ('atoms.get_potential_energy()',atoms.get_potential_energy()) # get
> energy BEFORE minimization
>
> parameters['minimize'] = '1.0e-3 1.0e-2 200 4000' # add minimize
> calc.params = parameters
> calc.run(set_atoms=True) # set_atoms=True to read final coordinates
> after minimization
>
> print ('atoms.positions[10]',atoms.positions[10]) # still initial
> coordinates here
> print ('calc.atoms.positions[10]',calc.atoms.positions[10]) #
> minimized configuration is stored in calc.atoms !!!
>
> print ('atoms.get_potential_energy()',atoms.get_potential_energy()) # in
> fact calculates energy of calc.atoms, not atoms. It is strange, but I do
> not dare to change this behavior because it is deeply rooted in general
> Atoms-Calulator design.
>
> On 15 March 2017 at 00:31, Spencer Hills <spencer.hills at my.wheaton.edu>
> wrote:
>
>> Hello,
>>
>> Here are the relevant portions of the code:
>>
>> from ase import Atoms, Atom
>>
>> from ase.io import read,write
>>
>> from ase.calculators.lammpsrun import LAMMPS
>>
>>
>> parameters = {'pair_style':'tersoff','pair_coeff':["* * Au.tersoff
>> Au"],'boundaries':'p p p','mass':masses,'minimize':'1.0e-3 1.0e-2 200
>> 4000','run':'0'} #define lammps input file parameters
>> files=["~/Downloads/Au.tersoff"] #call potential file
>> calc = LAMMPS(files=files,parameters=parameters) #input to calculator
>> atoms.set_calculator(calc) #set calculator
>> atoms.get_potential_energy() # get energy -> lammps minimize function is
>> called in in_lammps made by calculator, and minimizes structure based on
>> lammps force fields (tmp traj files show this)
>>
>> I am using the multistep minimization that lammpsrun.py uses (params['minimize']
>> = 'etol ftol maxiter maxeval', in your example), and was hoping that it
>> there was a way to get the new coordinates from the lammps trajectory. I am
>> able to save the trajectory files produced by lammps with ASE (temporary
>> trajectory files), but have not been able to extract the coordinates from those
>> files.
>>
>> I think that with this command that you mentioned, I should be able to
>> get those new positions (calc.trajectory_out = Trajectory('/tmp/sio2.run.
>> traj','w')). Do you have example code of how that works?
>>
>> Thanks,
>> Spencer
>>
>> On Tue, Mar 14, 2017 at 12:34 AM, - <mazay0 at gmail.com> wrote:
>>
>>> Please, show your code.
>>> Minimization should be done with LBFGS,MDMin,FIRE classes from
>>> ase.optimize. Where do you call minimize() function ?
>>>
>>>
>>> Concerning constraints in LAMMPS input file.
>>> Right now I work on this functionality here:
>>> https://gitlab.com/Mazay0/ase/tree/lammps-multistep
>>> Currently you can fix atoms with the following parameters of the
>>> calculator:
>>>
>>> params['group'] = ['lower_atoms id ' + ' '.join([str(atom.index+1) for
>>> atom in sio2 if atom.position[2] < 6 ])] # named group of all atoms if z
>>> coordinate less than 6.0
>>> params['fix'] = ['freeze_lower_atoms lower_atoms setforce 0.0 0.0 0.0']
>>> # fix their position, in fact you can used any fix from here:
>>> http://lammps.sandia.gov/doc/fix.html
>>>
>>> For a while my code do not consider ASE constraints, but in future I am
>>> going to implement automatic generation of fix commands from Atoms's
>>> constraints.
>>>
>>> Also you can control trajectory generation with two parameters of the
>>> calculator:
>>>
>>> calc.trajectory_out = Trajectory('/tmp/sio2.run.traj','w') # convert
>>> LAMMPS trajectory from 'trj_xxx' to ASE trajectory '/tmp/sio2.run.traj'
>>> calc.dump_period = 20 # write trajectory frame each 20 steps
>>>
>>> To run multistep simulation just pass the desired number of steps:
>>>
>>> params['run'] = 100000
>>> calc.parameters = params
>>>
>>> and call run() method of the calculator:
>>>
>>> calc.run()
>>>
>>>
>>> For multistep minimization there is a code in lammpsrun.py that should
>>> accept something like this:
>>>
>>> params['minimize'] = 'etol ftol maxiter maxeval' # see
>>> http://lammps.sandia.gov/doc/minimize.html for details
>>>
>>> But I have not tested it yet.
>>>
>>>
>>>
>>>
>>> On 14 March 2017 at 00:28, Spencer Hills via ase-users <
>>> ase-users at listserv.fysik.dtu.dk> wrote:
>>>
>>>> Hello,
>>>>
>>>> I am new to ASE and am trying to use it to look at different data types
>>>> by calling other functions (ex: LAMMPS). With the ASE atoms object it is
>>>> very easy to keep everything stored in one place. I am using lammpsrun.py
>>>> from the standard ASE package to write input files from a code, so that I
>>>> can make a modular code and not require the user to write lammps input file
>>>> everytime they want to run the code.
>>>>
>>>> However, when I use LAMMPS and call the minimize function, I run into
>>>> some difficulties. It will minimize the energy correctly (compared to
>>>> running lammps with the python library version of it and the same inputs),
>>>> but it does not update the positions of the atoms in the atoms object, so I
>>>> can't compare the minimized energy to anything else because its a different
>>>> arrangement.
>>>>
>>>> Is there a way to update the atoms object with the LAMMPS minimized
>>>> structure? I think that I could make it read the trajectory file and
>>>> convert that to positions, but I would rather not save the temporary files
>>>> in order to do this. Is there a more elegant way to do this? Or is there a
>>>> current implementation in ASE?
>>>>
>>>> Additionally, when I call the minimize function, it does not use the
>>>> constraints that I assign to it. Right now I am starting simple with one
>>>> atom at a fixed position, but this atom does not stay in the same position.
>>>>
>>>> Is there a way to pass the constraints to the LAMMPS input file?
>>>>
>>>> I've looking through some of the mailing list, and have been unable to
>>>> find answers to the questions. Any direction, either to previous threads or
>>>> general help on this issue would be appreciated!
>>>>
>>>> Thanks,
>>>> Spencer Hills
>>>> Research Aide
>>>> Argonne National Lab
>>>>
>>>> _______________________________________________
>>>> ase-users mailing list
>>>> ase-users at listserv.fysik.dtu.dk
>>>> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20170317/d00215b0/attachment-0001.html>
More information about the ase-users
mailing list