Query structures based on both with_outgoing and with_incoming

16 views
Skip to first unread message

Sylvian Cadars

unread,
Aug 26, 2021, 4:44:22 AM8/26/21
to aiidausers
Dear aiida developpers or users,

I have a problem which I assume is related to my yet-too-poor understanding of the database query concepts.
I am trying to search for structures that have been created with a certain calcfunction called  'create_structure_and_info_from_cif' AND have then been used as an input to a certain relaxation workchain called 'MyRelaxWorkChain'.

I understand how to find matches to the first condition :

qb1 = QueryBuilder()

qb1.append(cls=CalcFunctionNode,
           filters={
               'attributes.function_name' : 'create_structure_and_info_from_cif',
               'attributes.exit_status' : 0,
           },
           tag='Structure_creation_nodes'
        )

qb1.append(cls=StructureData,
           with_incoming='Structure_creation_nodes',
           tag='Structures_created_from_cif'
          )

But so far the best way to match the second condition I have found is to proceed along the graph and then back to the structures as follows :

# Get ' MyRelaxWorkChain's processes run from the above structures
qb1.append(cls=WorkChainNode,
           filters={
               'attributes.process_label' : MyRelaxWorkChain',
               'attributes.process_state' : 'finished',
           },
           with_incoming='Structures_created_from_cif',
           tag='my_relax_workchain_nodes',
          )
# Go back to the input structures
qb1.append(cls=StructureData,
           with_outgoing=' my_relax_workchain _nodes',
           tag='Structures_created_from_cif_and_relaxed',
           project=['*','id','uuid'],
          )

This works but seems unnecessarily complicated to me. What I am looking for is simplyn an inner_join of two queries :
- structures with an incoming 'create_structure_and_info_from_cif' calcfunction
- structures with an outgoing 'MyRelaxWorkChain'

I tried to set both 'with_incoming' and 'with_outgoing' in my StructureData query but it does not seem to be possible.

Can someone help me figure out how to do this in a more clever manner ?

Thank you very much.
Sylvian.

Marnik Bercx

unread,
Aug 27, 2021, 6:18:11 AM8/27/21
to aiida...@googlegroups.com
Hi Sylvian! 👋

Note that you can project at any of the append steps, even if you append more to your query afterwards. Would the following query not do the trick? (not tested)

qb1 = QueryBuilder()

qb1.append(cls=CalcFunctionNode,
           filters={
               'attributes.function_name' : 'create_structure_and_info_from_cif',
               'attributes.exit_status' : 0,
           },
           tag='Structure_creation_nodes'
        )

qb1.append(cls=StructureData,
           with_incoming='Structure_creation_nodes',
           project=['*','id','uuid']
           tag='Structures_created_from_cif',
          )

qb1.append(cls=WorkChainNode,
           filters={
               'attributes.process_label' : MyRelaxWorkChain',
               'attributes.process_state' : 'finished',
           },
           with_incoming='Structures_created_from_cif',
          )

Best,
Marnik


--
AiiDA is supported by the NCCR MARVEL (http://nccr-marvel.ch/), funded by the Swiss National Science Foundation, and by the European H2020 MaX Centre of Excellence (http://www.max-centre.eu/).
 
Before posting your first question, please see the posting guidelines at http://www.aiida.net/?page_id=356 .
---
You received this message because you are subscribed to the Google Groups "aiidausers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aiidausers+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aiidausers/0011f7a8-520d-4afe-8cf8-4e40356c0d9en%40googlegroups.com.

Sylvian Cadars

unread,
Aug 30, 2021, 4:48:05 AM8/30/21
to aiidausers
Dear Marnik,

Many thanks for your suggestion, which seems to work prefectly fine. I had to struggle, however, to understand why the behaviour differed from the first three 'append' steps in my example. It took me a while to realize that the 'project' key was indeed THE key. Indeed, the only difference between your suggestion and mine is that you explicitely project the result at the second 'append(cls=StructureData,...)' step whereas I only did that at the very end.

Let me be sure I understand well. The 'append' stage at which the projection is performed becomes the central step, one might say the focus point, of the query, and further 'append's then simply act as additional filters. Is this the correct way to understand what is happening here ? If this is correct, then this means that if no projection is explicitely perfomed in any of the 'append's step, then the default 'project' = ['*"] applies to the last step, which then automatically becomes the point of focus. Am I right ?

Thank you very much for your help.
Best regards.

Sylvian.

Marnik Bercx

unread,
Sep 2, 2021, 8:09:59 AM9/2/21
to aiida...@googlegroups.com
Hi Sylvian,

It's true that in case no projections are performed, the "default projection" so to speak would be the nodes corresponding to the final append step (indeed `project = ['*']` as you mentioned). However, you can project at every append step of the query if desired. For example, you could also project the UUID  of the `create_structure_and_info_from_cif` calculation functions in your example:

qb1 = QueryBuilder()

qb1.append(cls=CalcFunctionNode,
           filters={
               'attributes.function_name' : 'create_structure_and_info_from_cif',
               'attributes.exit_status' : 0,
           },
           tag='Structure_creation_nodes'
   project=['uuid'],

        )

qb1.append(cls=StructureData,
           with_incoming='Structure_creation_nodes',
           project=['*','id','uuid'],

           tag='Structures_created_from_cif',
          )

qb1.append(cls=WorkChainNode,
           filters={
               'attributes.process_label' : MyRelaxWorkChain',
               'attributes.process_state' : 'finished',
           },
           with_incoming='Structures_created_from_cif',
          )

Each query result would then consist of a list with 4 items: the UUID of the calculation function, and then the `StructureData` node, PK and UUID. So there isn't really a "central" append step, you can add projections at any append call. :)

Hope that makes things a bit clearer!

Best,
Marnik


Sylvian Cadars

unread,
Sep 2, 2021, 8:48:49 AM9/2/21
to aiidausers
Hi Marnik,
Yes it does clarify the logic, thank you very much.
All the best.
Sylvian.
Reply all
Reply to author
Forward
0 new messages