# Fix atoms in StructureData

**URL:** <https://aiida.discourse.group/t/fix-atoms-in-structuredata/149>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 8, 2023, 6:32pm UTC](https://aiida.discourse.group/t/fix-atoms-in-structuredata/149 "2023-11-08T18:32:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoriniTT](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DoriniTT](https://aiida.discourse.group/u/DoriniTT)\
**Post date:** [November 8, 2023, 6:32pm UTC](https://aiida.discourse.group/t/fix-atoms-in-structuredata/149/1 "2023-11-08T18:32:49Z")

</div>

Hello everyone,

I’m creating several surface structures to be calculated with AiiDA-VASP. First, I create all structures with ASE and use the FixAtoms class to fix the bottom layers of my slab. Then I transform these ASE Atoms structures into a list of StructureData as input for my WorkChain. However, when I look at the generated POSCAR in the remote computer I noticed that it did not fix the atoms. What is the proper way to do this?

Thanks in advance!  
Thiago

---

<div class="post-metadata">

**Author:** ![mbercx](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/mbercx/32/345_2.png) [@mbercx](https://aiida.discourse.group/u/mbercx)\
**Post date:** [November 8, 2023, 8:26pm UTC](https://aiida.discourse.group/t/fix-atoms-in-structuredata/149/2 "2023-11-08T20:26:01Z")

</div>

Hi Thiago!

Currently the `StructureData` doesn’t store such calculation settings, so the ASE constraints aren’t transferred initializing them from the ASE `Atoms`.

I’ve never run any calculations with `aiida-vasp`, but it seems there is an input for setting selective dynamics on the `VaspCalculation`:

> <https://github.com/aiida-vasp/aiida-vasp/blob/ace503fa5b04047aadb7d9231d6c696f4ba2bb6c/aiida_vasp/calcs/vasp.py#L79-L84>

This is subsequently passed to the `PoscarParser` class:

> <https://github.com/aiida-vasp/aiida-vasp/blob/ace503fa5b04047aadb7d9231d6c696f4ba2bb6c/aiida_vasp/calcs/vasp.py#L495-L504>

I played around with the `PoscarParser` a bit, and you can indeed pass selective dynamics to the parser via the `options` argument as a list of lists. See the following minimal example:

```python
from ase import Atoms
from ase.constraints import FixAtoms

from aiida import orm, load_profile
from aiida_vasp.parsers.content_parsers.poscar import PoscarParser

load_profile()

d = 2.9
L = 10.0

atoms = Atoms(
    symbols=['Au', 'Cu'],
    positions=[[0, L / 2, L / 2], [d, L / 2, L / 2]],
    cell=[2 * d, L, L],
    pbc=[1, 0, 0]
)

poscar_parser = PoscarParser(
    data=orm.StructureData(ase=atoms),
    options={'positions_dof': [[True, True, True], [False, False, False]]}
)
poscar_parser.write('POSCAR')

```

Now the POSCAR will indeed contain:

```auto
Selective dynamics
Direct
  0.000000000000 0.500000000000 0.500000000000 T T T
  0.500000000000 0.500000000000 0.500000000000 F F F

```

So I’m assuming you can fix atom positions by specifying the `dynamics` input as follows:

```auto
builder = VaspCalculation.get_builder()

builder.dynamics = orm.Dict(
    {'positions_dof': [[True, True, True], [False, False, False]]}
)

```

Along with the other inputs of course. 🙂

Hope it works!

---

<div class="post-metadata">

**Author:** ![DoriniTT](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DoriniTT](https://aiida.discourse.group/u/DoriniTT)\
**Post date:** [November 9, 2023, 12:38pm UTC](https://aiida.discourse.group/t/fix-atoms-in-structuredata/149/3 "2023-11-09T12:38:16Z")

</div>

Hi Marnik!

I see! I managed to use your example as guide for my own system and it worked perfectly.

Thanks a lot for the fast and detailed response, I really appreciate it!  
Kind regards,  
Thiago

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/aiida/original/1X/c417197d3750949351575d03ed03f5e2ad32e649.png) [@system](https://aiida.discourse.group/u/system)\
**Post date:** [November 15, 2023, 8:38am UTC](https://aiida.discourse.group/t/fix-atoms-in-structuredata/149/4 "2023-11-15T08:38:42Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
