[ase-users] ase.db and magnetic moments

Jens Jørgen Mortensen jensj at fysik.dtu.dk
Thu May 22 11:43:57 CEST 2014


On 05/22/2014 11:01 AM, Steen Lysgaard wrote:
> Hi,
>
> I am having some difficulty extracting the magnetic moment assigned to 
> each atom in an atoms object from a .db file. I think the reason is 
> that magmoms and initial_magmoms are mixed up during the whole 
> atoms->dict->row->dict->atoms transformation. Consider the following:
>
> >>> from ase.db import connect
> >>> from ase.lattice.surface import fcc111
> >>> db = connect('magmom.db')
> >>> atoms = fcc111('Ni',(2,2,3))
> >>> atoms.set_initial_magnetic_moments([0.6 for _ in range(len(atoms))])
> >>> print atoms[0].magmom
> 0.6
> >>> db.write(atoms,keywords=['magmom'])
> 1
> >>> new_atoms = db.get_atoms(1)
> >>> print new_atoms[0].magmom
> 0.0
> >>> print new_atoms.get_initial_magnetic_moments()
> [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
>
> Doing this:
>
> Index: ase/db/core.py
> ===================================================================
> --- ase/db/core.py    (revision 3638)
> +++ ase/db/core.py    (working copy)
> @@ -497,7 +497,7 @@
>                    dct['positions'],
>                    cell=dct['cell'],
>                    pbc=dct['pbc'],
> -                  magmoms=dct.get('initial_magmoms'),
> +                  magmoms=dct.get('magmoms'),
>                    charges=dct.get('initial_charges'),
>                    tags=dct.get('tags'),
>                    masses=dct.get('masses'),
>
> fixes the exampleabove. But I am not sure that this will not mix up 
> the differentiation between magmoms and initial_magmoms further.

Thanks for finding this.  It was a bug in the SQLite backend - should be 
fixed now.

Jens Jørgen

>
> Best regards,
> Steen
>




More information about the ase-users mailing list