# Setting up a user for SqliteZipBackend (?)

**URL:** <https://aiida.discourse.group/t/setting-up-a-user-for-sqlitezipbackend/139>\
**Category:** New to AiiDA\
**Tags:** question\
**Created:** [October 27, 2023, 8:28am UTC](https://aiida.discourse.group/t/setting-up-a-user-for-sqlitezipbackend/139 "2023-10-27T08:28:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SiLiKhon](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@SiLiKhon](https://aiida.discourse.group/u/SiLiKhon)\
**Post date:** [October 27, 2023, 8:28am UTC](https://aiida.discourse.group/t/setting-up-a-user-for-sqlitezipbackend/139/1 "2023-10-27T08:28:14Z")

</div>

Hi!  
I haven’t used AiiDA before. I’m now trying to read some data shared as an AiiDA archive ([Materials Cloud Archive](https://archive.materialscloud.org/record/2019.0077/v1)). I figured that I can use `SqliteZipBackend.create_profile("path/to/archive.aiida")` to create a profile for accessing it. This does work to some extent, but some of the nodes within the archive won’t let me read them, failing with `ValueError: the user cannot be None` exception.

The particular steps I made are:

1. downloaded the above mentioned aiida archive
2. installed aiida localy with `pip instal aiida`
3. updated the downloaded archive with `verdi archive migrate screening.aiida migrated.aiida`
4. in python I’m doing the following:

```python
from aiida.storage.sqlite_zip.backend import SqliteZipBackend
from aiida import orm, load_profile

load_profile(SqliteZipBackend.create_profile("migrated.aiida"))

traj_group = orm.Group.objects.get(label="concatenated_trajectories")
stru_group = orm.Group.objects.get(label="starting_structures")

# this works nicely and gives me an ASE structure:
initial_structure = stru_group.nodes[0].get_ase()
print(initial_structure)

# this also works and returns me a 1D numpy array with MD time values:
times = traj_group.nodes[0].get_times()
print(times[:10])

# however, this fails with the above mentioned exception:
step0_struct = traj_group.nodes[0].get_step_structure(0)

```

From the traceback, I see that just before this error the user value is accessed via `backend.default_user`, which apparently is None. Hence, my question is whether there is a way to set up a user for this backend?

Or does this mean I need to import the archive into some profile with a non-read-only backend?..

Thanks!

---

<div class="post-metadata">

**Author:** ![eimrek](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/eimrek/32/8_2.png) [@eimrek](https://aiida.discourse.group/u/eimrek)\
**Post date:** [October 27, 2023, 1:42pm UTC](https://aiida.discourse.group/t/setting-up-a-user-for-sqlitezipbackend/139/2 "2023-10-27T13:42:35Z")

</div>

Hi!

I would suggest to use the verdi CLI to

1. set up an AiiDA profile with `verdi quicksetup` or `verdi setup`;  
and then
2. import the archive with `verdi archive import` (see [here](https://aiida.readthedocs.io/projects/aiida-core/en/latest/howto/data.html#importing-data) and [here](https://aiida.readthedocs.io/projects/aiida-core/en/latest/howto/share_data.html#importing-an-archive) for info. Latter case imports directly from archive url but you can also import from a file.)

And then, you can access the data directly in a python script by loading the corresponding profile (here named `'qs'`). Something like

```python
from aiida import orm, load_profile

load_profile("qs")

group = orm.load_group(label='test_group')

group_nodes = list(group.nodes)

```

I am not fully sure if you can create profiles or import archive files directly in python in a straightforward way.

---

<div class="post-metadata">

**Author:** ![sphuber](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/sphuber/32/6_2.png) [@sphuber](https://aiida.discourse.group/u/sphuber)\
**Post date:** [October 27, 2023, 1:45pm UTC](https://aiida.discourse.group/t/setting-up-a-user-for-sqlitezipbackend/139/3 "2023-10-27T13:45:48Z")

</div>

Hi SiLiKhon, great to hear that you are straigt away diving into an existing AiiDA archive and using the `SqliteZipBackend`. The problem you encounter is that calling `Trajectory.get_step_structure` is creating a new `StructureData` instance. Even if you are not storing this, this requires a `User` instance to be set as the `user` for that node. But apparently, no default user has been defined, so the code excepts.

Now necessarily, the archive _must_ contain at least one `User`, because all the nodes are required to have one. I opened the archive as well and confirmed that indeed there is a one user

```python
In [1]: from aiida import orm

In [2]: orm.QueryBuilder().append(orm.User).all(flat=True)
Out[2]: [<aiida.orm.users.User at 0x7f1abbe310d0>]

```

Now all that we have to do is define the `default_user_email` on the profile and things now work:

```python
In [1]: from aiida.manage import get_profile

In [2]: profile = get_profile()

In [3]: user = orm.QueryBuilder().append(orm.User).first(flat=True)

In [4]: profile.default_user_email = user.email

In [5]: traj_group = orm.Group.objects.get(label="concatenated_trajectories")

In [6]: step0_struct = traj_group.nodes[0].get_step_structure(0)

In [7]: step0_struct
Out[7]: <StructureData: uuid: a85da7ec-489b-497a-af5f-b0a35af1795f (unstored)>

```

I think the `SqliteZipBackend.create_profile` should automatically set a default user given that the archive is required to already have a user and no new users can be created, since it is a read-only backend. I have opened an [issue for this on `aiida-core`](https://github.com/aiidateam/aiida-core/issues/6165). For the time being, you can use the workaround I described above.

**Edit** : the solution above is ideal if you simply want to explore the data. If you want to start working with the data and create new data, or launch new calculations, then you will need a profile with a real storage backend that is not read-only, and the answer by @eimrek is the one to follow

---

<div class="post-metadata">

**Author:** ![SiLiKhon](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@SiLiKhon](https://aiida.discourse.group/u/SiLiKhon)\
**Post date:** [October 31, 2023, 7:19am UTC](https://aiida.discourse.group/t/setting-up-a-user-for-sqlitezipbackend/139/4 "2023-10-31T07:19:34Z")

</div>

Thank you @eimrek, @sphuber for the prompt and helpful replies!

@eimrek I was hoping to avoid setting up a full profile. It seems to require to set up a database server backend, which is somewhat cumbersome if I only want to have a look at the data.

@sphuber your suggestion works like a charm, thanks again 🙂
