[ase-users] Getting magnetic moments from vasp

Protik Das protik77 at gmail.com
Wed May 24 00:23:20 CEST 2017


Very interesting. Yes I could reproduce it. Initially I tried your script:

from ase.calculators.vasp import Vasp
from ase.build.surface import fcc111
from ase.io import read, write

slab = fcc111('Ni', size=(1, 1, 3), vacuum=10.0)

calc = Vasp(prec='Normal',
            xc='PBE',
            lreal=False,
            kpts=(3,3,1),
            algo='Fast',
            nelm=120,
            ibrion=-1,
            nsw=0,
            lorbit=11)

slab.set_initial_magnetic_moments([1.]*len(slab))
slab.set_calculator(calc)
slab.get_potential_energy()

write('Ni_test.traj', slab)

print(slab.get_magnetic_moment())
print(slab.get_magnetic_moments())

As you said the ispin and magmom terms were included automatically and
there was no error. I could access the magnetic moments on the fly and from
the trajectory file without any error. Then I tried this:

from ase.calculators.vasp import Vasp
from ase.build.surface import fcc111
from ase.io import read, write
import numpy as np

slab = fcc111('Ni', size=(1, 1, 3), vacuum=10.0)

calc = Vasp(prec='Normal',
            xc='PBE',
            lreal=False,
            ispin=2,
            magmom = np.ones(len(slab)),
            kpts=(3,3,1),
            algo='Fast',
            nelm=120,
            ibrion=-1,
            nsw=0,
            lorbit=11)

slab.set_calculator(calc)
slab.get_potential_energy()

write('Ni_test2.traj', slab)

print(slab.get_magnetic_moment())
print(slab.get_magnetic_moments())

Now I get the following error in the print line:

Traceback (most recent call last):
  File "test.py", line 26, in <module>
    print(slab.get_magnetic_moment())
  File
"/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/atoms.py",
line 617, in get_magnetic_moment
    return self._calc.get_magnetic_moment(self)
  File
"/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/calculators/vasp.py",
line 1005, in get_magnetic_moment
    return self.magnetic_moment
AttributeError: 'Vasp' object has no attribute 'magnetic_moment'

Also I went to my python prompt and tried reading the magnetic moments from
the trajectory file by doing this:

>>> from ase.io import read
>>> a = read('Ni_test2.traj')
>>> a.get_magnetic_moments()

And got the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/atoms.py",
line 611, in get_magnetic_moments
    return self._calc.get_magnetic_moments(self)
  File
"/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/calculators/calculator.py",
line 445, in get_magnetic_moments
    return self.get_property('magmoms', atoms)
  File
"/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/calculators/singlepoint.py",
line 34, in get_property
    'The property "{0}" is not available.'.format(name))
ase.calculators.calculator.PropertyNotImplementedError: The property
"magmoms" is not available.

I believe setting magnetic moments through the initial_magnetic_moments or
through magmom of the calculator should have the same effect. But that is
not happening. Hope this helps.




On Tue, May 23, 2017 at 12:45 AM Kondov, Ivan (SCC) <ivan.kondov at kit.edu>
wrote:

> Dear Protik,
>
> Yes, the vasp calculator sets ispin=2 and the MAGMOM string automatically
> if
> we have defined the initial magnetic moments with
> atoms.set_initial_magnetic_moments(). As this is the case in the example
> below this is not the reason for the 'None' output.  The total magnetic
> moment is always available, the magnetic moments of individual atoms are
> available only if we specify lorbit>=10. I modified the script like this
>
> from ase.calculators.vasp import Vasp
> from ase.build.surface import fcc111
> calc = Vasp(prec='Normal', xc='PBE', lreal=False, kpts=(3,3,1),
> algo='Fast',
>             nelm=120, ibrion=-1, nsw=0, lorbit=10)
> slab = fcc111('Ni', size=(1, 1, 1), vacuum=10.0)
> slab.set_initial_magnetic_moments([1.]*len(slab))
> slab.set_calculator(calc)
> slab.get_potential_energy()
> print(slab.get_magnetic_moment())
> print(slab.get_magnetic_moments())
>
> and got this output:
>
> 3.3235328
> [ 1.12   1.047  1.122]
>
> I hope this helps.
>
> However I still cannot explain the PropertyNotImplementedError in your
> original post. How did this come about? Do you have a script to show that
> reproduces it?
>
> Best regards,
> Ivan
>
>
>
> > From: Eric Hermes [mailto:ehermes at chem.wisc.edu]
> > Sent: Tuesday, May 23, 2017 1:04 AM
> > To: Protik Das; Kondov, Ivan (SCC)
> > Subject: RE: [ase-users] Getting magnetic moments from vasp
> >
> > You need to run VASP with ispin=2 to enable spin polarization, otherwise
> the spin is fixed to 0. VASP also does not assign atomic magnetic moments,
> so get_magnetic_moments() will not work. If you want atomic magnetic
> moments, you can do something like Bader analysis on the spin density, but
> that will be a postprocessing step.
> >
> > I am uncertain if the VASP calculator parses the magnetic moments from
> initial_magnetic_moments. You can explicitly set initial magnetic moments
> with the Vasp keyword magmom. The default is 1. for each atom when spin
> polarization is enabled (with ispin=2).
> >
> > Eric
> >
> > From: ase-users-bounces at listserv.fysik.dtu.dk
> [mailto:ase-users-bounces at listserv.fysik.dtu.dk] On Behalf Of Protik Das
> via
> ase-users
> > Sent: Monday, May 22, 2017 4:44 PM
> > To: Kondov, Ivan (SCC) <ivan.kondov at kit.edu>;
> ase-users at listserv.fysik.dtu.dk
> > Subject: Re: [ase-users] Getting magnetic moments from vasp
> >
> > No really. I am constructing the calculaor object on the fly.
> > Your script works for me too. It prints out the final total magnetic
> moment. But I need the final magnetic moment of the individual atoms. I
> tried to do that by using the following script,
> >
> > from ase.calculators.vasp import Vasp
> > from ase.build.surface import fcc111
> > calc = Vasp(prec='Normal', xc='PBE', lreal=False, kpts=(3,3,1),
> algo='Fast',
> >             nelm=120, ibrion=-1, nsw=0, lorbit=0)
> > slab = fcc111('Ni', size=(1, 1, 1), vacuum=10.0)
> > slab.set_initial_magnetic_moments([1.]*len(slab))
> > slab.set_calculator(calc)
> > slab.get_potential_energy()
> > print(slab.get_magnetic_moment())
> > print(slab.get_magnetic_moments())
> > It only printed out 'None'. It seems the atoms object does not update the
> initial magnetic moments. Any idea about how I can get the final magnetic
> moments?
> > Thanks.
> >
> > On Mon, May 22, 2017 at 6:55 AM Kondov, Ivan (SCC) via ase-users
> <ase-users at listserv.fysik.dtu.dk> wrote:
> > Hello,
> >
> > I just tried to reproduce with this short script:
> >
> > from ase.calculators.vasp import Vasp
> > from ase.build.surface import fcc111
> > calc = Vasp(prec='Normal', xc='PBE', lreal=False, kpts=(3,3,1),
> algo='Fast',
> > nelm=120)
> > slab = fcc111('Ni', size=(1, 1, 3), vacuum=10.0)
> > slab.set_initial_magnetic_moments([1.]*len(slab))
> > slab.set_calculator(calc)
> > print(slab.get_magnetic_moment())
> >
> > It does not complain and prints the magmom on the screen. The method
> > calc.get_property('magmom', slab) also instantly updates and returns the
> > magmom. Quite notable from your error output below is that you do not use
> an
> > instance of the Vasp calculator but one derived
> > from ->SinglePointCalculator->Calculator classes (in singlepoint and
> > calculator modules). They are actually not used by the Vasp calculator.
> > Probably your calc object was (incompletely) constructed or read from a
> > database?
> >
> > Best regards,
> > Ivan
> >
> >
> > From: ase-users-bounces at listserv.fysik.dtu.dk
> > [mailto:ase-users-bounces at listserv.fysik.dtu.dk] On Behalf Of Protik Das
> via
> > ase-users
> > Sent: Monday, May 22, 2017 9:10 AM
> > To: ase-users at listserv.fysik.dtu.dk
> > Subject: [ase-users] Getting magnetic moments from vasp
> >
> > Hi,
> > I am running a spin polarized calculation using vasp as a calculator. But
> it
> > seems the atoms object is not updated with the magnetic moments from the
> > calculator when the calculation is done. I am getting the following error
> when
> > I try to get the magnetic moments from the atoms or the calculator
> object.
> >
> >   File
> >
>
> "/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/calculators
> /calculator.py",
> > line 441, in get_magnetic_moment
> >     return self.get_property('magmom', atoms)
> >   File
> >
>
> "/home/protik/anaconda3/envs/ase/lib/python3.6/site-packages/ase/calculators
> /singlepoint.py",
> > line 34, in get_property
> >     'The property "{0}" is not available.'.format(name))
> > ase.calculators.calculator.PropertyNotImplementedError: The property
> "magmom"
> > is not available.
> >
> > Is there a way to update the magnetic moments of the elements from the
> > calculation? I am using ase 3.13.0.
> > Thanks.
> > --
> > Protik Das,
> > ECE Graduate Student,
> > LATTE (http://latte.ece.ucr.edu),
> > University of California, Riverside.
> > _______________________________________________
> > ase-users mailing list
> > ase-users at listserv.fysik.dtu.dk
> > https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
> > --
> > Protik Das,
> > ECE Graduate Student,
> > LATTE (http://latte.ece.ucr.edu),
> > University of California, Riverside.
> >
>
-- 
Protik Das,
ECE Graduate Student,
LATTE (http://latte.ece.ucr.edu),
University of California, Riverside.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20170523/c064265a/attachment-0001.html>


More information about the ase-users mailing list