Skip to content

Commit

Permalink
Merge pull request #275 from openforcefield/fix-regex_query_nullfield
Browse files Browse the repository at this point in the history
Fix regular expression matching in `query_networks`
  • Loading branch information
dotsdl authored Jun 5, 2024
2 parents 9365cdd + 7c87edf commit e393b60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions alchemiscale/storage/statestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,19 +856,26 @@ def query_networks(
gufe_key_pattern=None if key is None else str(key),
)

where_params = dict(
name_pattern="an.name",
org_pattern="an.`_org`",
campaign_pattern="an.`_campaign`",
project_pattern="an.`_project`",
state_pattern="nm.state",
gufe_key_pattern="an.`_gufe_key`",
)

conditions = []

for k, v in query_params.items():
if v is None:
query_params[k] = ".*"
if v is not None:
conditions.append(f"{where_params[k]} =~ ${k}")

q = """
where_clause = "WHERE " + " AND ".join(conditions) if len(conditions) else ""

q = f"""
MATCH (an:AlchemicalNetwork)<-[:MARKS]-(nm:NetworkMark)
WHERE
an.name =~ $name_pattern
AND an.`_gufe_key` =~ $gufe_key_pattern
AND an.`_org` =~ $org_pattern
AND an.`_campaign` =~ $campaign_pattern
AND an.`_project` =~ $project_pattern
AND nm.state =~ $state_pattern
{where_clause}
RETURN an._scoped_key as sk
"""

Expand Down
2 changes: 1 addition & 1 deletion alchemiscale/tests/integration/storage/test_statestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_get_network(self, n4js, network_tyk2, scope_test):

def test_query_networks(self, n4js, network_tyk2, scope_test, multiple_scopes):
an = network_tyk2
an2 = AlchemicalNetwork(edges=list(an.edges)[:-2], name="incomplete")
an2 = AlchemicalNetwork(edges=list(an.edges)[:-2], name=None)

sk: ScopedKey = n4js.assemble_network(an, scope_test)[0]
sk2: ScopedKey = n4js.assemble_network(an2, scope_test)[0]
Expand Down

0 comments on commit e393b60

Please sign in to comment.