diff --git a/aiida/backends/djsite/db/subtests/nodes.py b/aiida/backends/djsite/db/subtests/nodes.py index 2312acfc3a..83b9373f3e 100644 --- a/aiida/backends/djsite/db/subtests/nodes.py +++ b/aiida/backends/djsite/db/subtests/nodes.py @@ -145,7 +145,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 0 ) @@ -155,7 +155,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 2 ) @@ -165,7 +165,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 2 ) @@ -175,7 +175,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 4 ) @@ -187,7 +187,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 2 ) @@ -196,7 +196,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 1 ) #~ self.assertEquals( @@ -207,7 +207,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 0 ) #~ self.assertEquals( @@ -218,13 +218,13 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n4.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 1 ) self.assertEquals( QueryBuilder().append( Node, filters={'id':n5.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n7.pk} + ).append(Node, with_ancestors='anc', filters={'id':n7.pk} ).count(), 1 ) #~ self.assertEquals( @@ -239,7 +239,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id':n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id':n8.pk} + ).append(Node, with_ancestors='anc', filters={'id':n8.pk} ).count(), 1 ) #~ self.assertEquals( diff --git a/aiida/backends/general/abstractqueries.py b/aiida/backends/general/abstractqueries.py index ebadbcbd3c..120f86127f 100644 --- a/aiida/backends/general/abstractqueries.py +++ b/aiida/backends/general/abstractqueries.py @@ -171,7 +171,7 @@ def get_bands_and_parents_structure(self, args): qb.append(orm.Group, tag="group", filters=group_filters, group_of="bdata") - qb.append(StructureData, tag="sdata", ancestor_of="bdata", + qb.append(StructureData, tag="sdata", with_descendants="bdata", # We don't care about the creator of StructureData project=["id", "attributes.kinds", "attributes.sites"]) @@ -245,5 +245,5 @@ def get_all_parents(self, node_pks, return_values=('id',)): qb = QueryBuilder() qb.append(Node, tag='low_node', filters={'id': {'in': node_pks}}) - qb.append(Node, ancestor_of='low_node', project=return_values) + qb.append(Node, with_descendants='low_node', project=return_values) return qb.all() diff --git a/aiida/backends/sqlalchemy/tests/nodes.py b/aiida/backends/sqlalchemy/tests/nodes.py index 3816e373bc..852853e823 100644 --- a/aiida/backends/sqlalchemy/tests/nodes.py +++ b/aiida/backends/sqlalchemy/tests/nodes.py @@ -56,7 +56,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 0 ) @@ -66,7 +66,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 2 ) @@ -81,7 +81,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 2 ) # ~ self.assertEquals( @@ -94,7 +94,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 4 ) @@ -111,7 +111,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 2 ) @@ -127,7 +127,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 1 ) @@ -143,7 +143,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 0 ) @@ -158,7 +158,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n4.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 1 ) # ~ self.assertEquals( @@ -169,7 +169,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n5.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n7.pk} + ).append(Node, with_ancestors='anc', filters={'id': n7.pk} ).count(), 1 ) # ~ self.assertEquals( @@ -184,7 +184,7 @@ def test_creation_and_deletion(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 1 ) # ~ self.assertEquals( diff --git a/aiida/backends/tests/query.py b/aiida/backends/tests/query.py index de76b71b7f..022aaf7a85 100644 --- a/aiida/backends/tests/query.py +++ b/aiida/backends/tests/query.py @@ -878,13 +878,13 @@ def test_query_path(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 0) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk} + ).append(Node, with_descendants='desc', filters={'id': n1.pk} ).count(), 0) n6.add_incoming(n5, link_type=LinkType.INPUT_CALC, link_label='link1') @@ -892,36 +892,36 @@ def test_query_path(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 2 ) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk} + ).append(Node, with_descendants='desc', filters={'id': n1.pk} ).count(), 2) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk}, edge_filters={'depth': {'<': 6}}, + ).append(Node, with_descendants='desc', filters={'id': n1.pk}, edge_filters={'depth': {'<': 6}}, ).count(), 2) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk}, edge_filters={'depth': 5}, + ).append(Node, with_descendants='desc', filters={'id': n1.pk}, edge_filters={'depth': 5}, ).count(), 2) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk}, edge_filters={'depth': {'<': 5}}, + ).append(Node, with_descendants='desc', filters={'id': n1.pk}, edge_filters={'depth': {'<': 5}}, ).count(), 0) # TODO write a query that can filter certain paths by traversed ID qb = QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc', - ).append(Node, ancestor_of='desc', edge_project='path', filters={'id': n1.pk}) + ).append(Node, with_descendants='desc', edge_project='path', filters={'id': n1.pk}) queried_path_set = set([frozenset(p) for p, in qb.all()]) paths_there_should_be = set([ @@ -934,7 +934,7 @@ def test_query_path(self): qb = QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' ).append( - Node, descendant_of='anc', filters={'id': n8.pk}, edge_project='path' + Node, with_ancestors='anc', filters={'id': n8.pk}, edge_project='path' ) self.assertTrue(set( @@ -950,14 +950,14 @@ def test_query_path(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 2 ) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk} + ).append(Node, with_descendants='desc', filters={'id': n1.pk} ).count(), 2) n9.add_incoming(n6, link_type=LinkType.INPUT_CALC, link_label='link6') # And now there should be 4 nodes @@ -965,19 +965,19 @@ def test_query_path(self): self.assertEquals( QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' - ).append(Node, descendant_of='anc', filters={'id': n8.pk} + ).append(Node, with_ancestors='anc', filters={'id': n8.pk} ).count(), 4) self.assertEquals( QueryBuilder().append( Node, filters={'id': n8.pk}, tag='desc' - ).append(Node, ancestor_of='desc', filters={'id': n1.pk} + ).append(Node, with_descendants='desc', filters={'id': n1.pk} ).count(), 4) qb = QueryBuilder().append( Node, filters={'id': n1.pk}, tag='anc' ).append( - Node, descendant_of='anc', filters={'id': n8.pk}, edge_tag='edge' + Node, with_ancestors='anc', filters={'id': n8.pk}, edge_tag='edge' ) qb.add_projection('edge', 'depth') self.assertTrue(set(next(zip(*qb.all()))), set([5, 6])) diff --git a/aiida/orm/implementation/django/node.py b/aiida/orm/implementation/django/node.py index 732815f42e..edd75fef92 100644 --- a/aiida/orm/implementation/django/node.py +++ b/aiida/orm/implementation/django/node.py @@ -240,7 +240,7 @@ def _add_dblink_from(self, src, link_type, label): # in the TC table from self to src if QueryBuilder().append( Node, filters={'id': self.pk}, tag='parent').append( - Node, filters={'id': src.pk}, tag='child', descendant_of='parent').count() > 0: + Node, filters={'id': src.pk}, tag='child', with_ancestors='parent').count() > 0: raise ValueError( "The link you are attempting to create would generate a loop") diff --git a/aiida/orm/implementation/general/node.py b/aiida/orm/implementation/general/node.py index 396bf4bccb..0122ac7712 100644 --- a/aiida/orm/implementation/general/node.py +++ b/aiida/orm/implementation/general/node.py @@ -2038,7 +2038,7 @@ def has_children(self): from aiida.orm import Node first_desc = QueryBuilder().append( Node, filters={'id': self.pk}, tag='self').append( - Node, descendant_of='self', project='id').first() + Node, with_ancestors='self', project='id').first() return bool(first_desc) @property @@ -2051,7 +2051,7 @@ def has_parents(self): from aiida.orm import Node first_ancestor = QueryBuilder().append( Node, filters={'id': self.pk}, tag='self').append( - Node, ancestor_of='self', project='id').first() + Node, with_descendants='self', project='id').first() return bool(first_ancestor) # pylint: disable=no-self-argument diff --git a/aiida/orm/implementation/sqlalchemy/node.py b/aiida/orm/implementation/sqlalchemy/node.py index 6a3dc5a536..b9d5628ee1 100644 --- a/aiida/orm/implementation/sqlalchemy/node.py +++ b/aiida/orm/implementation/sqlalchemy/node.py @@ -287,7 +287,7 @@ def _add_dblink_from(self, src, link_type, label): }, tag='parent').append( Node, filters={ 'id': src.pk - }, tag='child', descendant_of='parent').count() > 0: + }, tag='child', with_ancestors='parent').count() > 0: raise ValueError("The link you are attempting to create would generate a loop") self._do_create_link(src, label, link_type) diff --git a/aiida/orm/querybuilder.py b/aiida/orm/querybuilder.py index 9416ebea4e..4bc633bd1a 100644 --- a/aiida/orm/querybuilder.py +++ b/aiida/orm/querybuilder.py @@ -1262,7 +1262,7 @@ def _join_descendants_recursive(self, joined_entity, entity_to_join, isouterjoin """ self._check_dbentities((joined_entity, self._impl.Node), (entity_to_join, self._impl.Node), - 'descendant_of_beta') + 'with_ancestors') link1 = aliased(self._impl.Link) link2 = aliased(self._impl.Link) @@ -1316,7 +1316,7 @@ def _join_ancestors_recursive(self, joined_entity, entity_to_join, isouterjoin, """ self._check_dbentities((joined_entity, self._impl.Node), (entity_to_join, self._impl.Node), - 'descendant_of_beta') + 'with_ancestors') link1 = aliased(self._impl.Link) link2 = aliased(self._impl.Link) @@ -1478,12 +1478,14 @@ def _get_function_map(self): 'with_comment': self._join_comment_node, 'with_incoming': self._join_outputs, 'with_outgoing': self._join_inputs, - 'ancestor_of': self._join_ancestors_recursive, - 'descendant_of': self._join_descendants_recursive, + 'with_descendants': self._join_ancestors_recursive, + 'with_ancestors': self._join_descendants_recursive, 'with_computer': self._join_to_computer_used, 'with_user': self._join_created_by, 'with_group': self._join_group_members, 'direction': None, + 'ancestor_of': self._deprecate(self._join_ancestors_recursive, 'ancestor_of', 'with_descendants'), + 'descendant_of': self._deprecate(self._join_descendants_recursive, 'descendant_of', 'with_ancestors'), 'input_of': self._deprecate(self._join_inputs, 'input_of', 'with_outgoing'), 'output_of': self._deprecate(self._join_outputs, 'output_of', 'with_incoming'), 'has_computer': self._deprecate(self._join_to_computer_used, 'has_computer', 'with_computer'), @@ -1659,7 +1661,7 @@ def _build(self): isouterjoin = verticespec.get('outerjoin') edge_tag = verticespec['edge_tag'] - if verticespec['joining_keyword'] in ('descendant_of', 'ancestor_of'): + if verticespec['joining_keyword'] in ('with_ancestors', 'with_descendants', 'ancestor_of', 'descendant_of'): # I treat those two cases in a special way. # I give them a filter_dict, to help the recursive function find a good # starting point. TODO: document this! @@ -2076,7 +2078,7 @@ def dict(self, batch_size=None): ) qb.append( Node, - descendant_of='structure', + with_ancestors='structure', project=['type', 'id'], # returns type (string) and id (string) tag='descendant' ) @@ -2131,7 +2133,7 @@ def children(self, **kwargs): """ join_to = self._path[-1]['tag'] cls = kwargs.pop('cls', Node) - self.append(cls=cls, descendant_of=join_to, autotag=True, **kwargs) + self.append(cls=cls, with_ancestors=join_to, autotag=True, **kwargs) return self def parents(self, **kwargs): @@ -2142,7 +2144,7 @@ def parents(self, **kwargs): """ join_to = self._path[-1]['tag'] cls = kwargs.pop('cls', Node) - self.append(cls=cls, ancestor_of=join_to, autotag=True, **kwargs) + self.append(cls=cls, with_descendants=join_to, autotag=True, **kwargs) return self def _deprecate(self, function, deprecated_name, preferred_name, version='1.0.0a5'): diff --git a/docs/source/querying/querybuilder/usage.rst b/docs/source/querying/querybuilder/usage.rst index 0f24856c1a..1fabf23327 100644 --- a/docs/source/querying/querybuilder/usage.rst +++ b/docs/source/querying/querybuilder/usage.rst @@ -288,33 +288,33 @@ to a previous entity by using one of the keywords in the above table and as a value the tag of the vertice that it has a relationship with. There are several relationships that entities in Aiida can have: -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| **Entity from** | **Entity to** | **Relationship** | **Deprecated Relationship** | **Explanation** | -+==================+===============+==================+=============================+=================================================+ -| Node | Node | *with_outgoing* | *input_of* | One node as input of another node | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Node | Node | *with_incoming* | *output_of* | One node as output of another node | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Node | Node | *ancestor_of* | | One node as the ancestor of another node (Path) | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Node | Node | *descendant_of* | | One node as descendant of another node (Path) | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Node | Group | *with_node* | *group_of* | The group of a node | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Group | Node | *with_group* | *member_of* | The node is a member of a group | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Node | Computer | *with_node* | *computer_of* | The computer of a node | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Computer | Node | *with_computer* | *has_computer* | The node of a computer | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Node | User | *with_node* | *creator_of* | The creator of a node is a user | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| User | Node | *with_user* | *created_by* | The node was created by a user | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| User | Group | *with_user* | *belongs_to* | The node was created by a user | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ -| Group | User | *with_group* | *owner_of* | The node was created by a user | -+------------------+---------------+------------------+-----------------------------+-------------------------------------------------+ ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| **Entity from** | **Entity to** | **Relationship** | **Deprecated Relationship** | **Explanation** | ++==================+===============+====================+=============================+=================================================+ +| Node | Node | *with_outgoing* | *input_of* | One node as input of another node | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Node | Node | *with_incoming* | *output_of* | One node as output of another node | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Node | Node | *with_descendants* | *ancestor_of* | One node as the ancestor of another node (Path) | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Node | Node | *with_ancestors* | *descendant_of* | One node as descendant of another node (Path) | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Node | Group | *with_node* | *group_of* | The group of a node | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Group | Node | *with_group* | *member_of* | The node is a member of a group | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Node | Computer | *with_node* | *computer_of* | The computer of a node | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Computer | Node | *with_computer* | *has_computer* | The node of a computer | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Node | User | *with_node* | *creator_of* | The creator of a node is a user | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| User | Node | *with_user* | *created_by* | The node was created by a user | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| User | Group | *with_user* | *belongs_to* | The node was created by a user | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ +| Group | User | *with_group* | *owner_of* | The node was created by a user | ++------------------+---------------+--------------------+-----------------------------+-------------------------------------------------+ Some more examples::