# Querying from attributes

**URL:** <https://aiida.discourse.group/t/querying-from-attributes/433>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 17, 2024, 12:46pm UTC](https://aiida.discourse.group/t/querying-from-attributes/433 "2024-07-17T12:46:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPchico](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/jpchico/32/29_2.png) [@JPchico](https://aiida.discourse.group/u/JPchico)\
**Post date:** [July 17, 2024, 12:46pm UTC](https://aiida.discourse.group/t/querying-from-attributes/433/1 "2024-07-17T12:46:51Z")

</div>

Hello!

I have a small question. I’m trying to query for the structures which contains a given element. I’m able to write a query that is something like this

```auto
qb = orm.QueryBuilder()
qb.append(
     orm.StructureData,
     filters={
         'attributes.kinds.0.symbols': {'contains': ['Si']}
     }
)

```

This means that I can check if the first kind has `Si`, but is there a way to generalize it for it to check in any symbol?

---

<div class="post-metadata">

**Author:** ![JPchico](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/jpchico/32/29_2.png) [@JPchico](https://aiida.discourse.group/u/JPchico)\
**Post date:** [July 17, 2024, 1:34pm UTC](https://aiida.discourse.group/t/querying-from-attributes/433/2 "2024-07-17T13:34:57Z")

</div>

I have seen the answer about [alloys-by-elements](https://aiida.discourse.group/t/find-calculations-with-alloys-by-elements/328). And that might work, I do wonder however, if there is a way of just checking by the symbols, as not having to worry about the kind object itself.

---

<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:** [July 23, 2024, 8:50am UTC](https://aiida.discourse.group/t/querying-from-attributes/433/3 "2024-07-23T08:50:12Z")

</div>

Hi @JPchico! Unfortunately, I think the (rather cumbersome) kind solution is the best I can think of at the moment. We’ve been working on a new `StructureData` type though (mostly to be able to add properties), and there I would simply add the formula (or chemical system) to the attributes directly in some fashion.

A workaround I’ve been using to keep my life simple is writing a loop that checks if the `formula` is in the extras for all `StructureData`, and adding it in case it isn’t. This is not a very satisfying solution however, since newly created `StructureData` won’t have these extras.

---

<div class="post-metadata">

**Author:** ![JPchico](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/jpchico/32/29_2.png) [@JPchico](https://aiida.discourse.group/u/JPchico)\
**Post date:** [August 22, 2024, 11:01am UTC](https://aiida.discourse.group/t/querying-from-attributes/433/4 "2024-08-22T11:01:42Z")

</div>

Hi @mbercx ! Sorry for the late reply I must have missed this notification.

No worries I understand, I was just wondering if there was a better way. I normally do store the formula in the extras, but I have to relabel nodes for exactly the reason that you are mentioning, new nodes do not have those extras.

But that is no problem 🙂 will keep doing it that way

---

<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:** [August 28, 2024, 7:02am UTC](https://aiida.discourse.group/t/querying-from-attributes/433/5 "2024-08-28T07:02:02Z")

</div>

Closed on August 28, 2024, 7:02am UTC

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