From d6de54f2b23454c94eb7c3189699bd80a7f98432 Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Thu, 20 May 2021 21:23:16 +0100 Subject: [PATCH] Use Select so that property map can be passed through to search. --- python/BioSimSpace/_SireWrappers/_molecule.py | 14 +++++++++++--- python/BioSimSpace/_SireWrappers/_residue.py | 14 +++++++++++--- python/BioSimSpace/_SireWrappers/_system.py | 12 ++++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/python/BioSimSpace/_SireWrappers/_molecule.py b/python/BioSimSpace/_SireWrappers/_molecule.py index 2f89846ab..c2f37accc 100644 --- a/python/BioSimSpace/_SireWrappers/_molecule.py +++ b/python/BioSimSpace/_SireWrappers/_molecule.py @@ -458,7 +458,7 @@ def toSystem(self): """ return _System(self) - def search(self, query): + def search(self, query, property_map={}): """Search the molecule for atoms and residues. Search results will be reduced to their minimal representation, i.e. a residue containing a single atom will be returned as a atom. @@ -469,6 +469,11 @@ def search(self, query): query : str The search query. + property_map : dict + A dictionary that maps system "properties" to their user defined + values. This allows the user to refer to properties with their + own naming scheme, e.g. { "charge" : "my-charge" } + Returns ------- @@ -495,12 +500,15 @@ def search(self, query): if type(query) is not str: raise TypeError("'query' must be of type 'str'") + if type(property_map) is not dict: + raise TypeError("'property_map' must be of type 'dict'") + # Intialise a list to hold the search results. results = [] try: - # Query the Sire system. - search_result = self._sire_object.search(query) + # Query the Sire molecule. + search_result = _SireMol.Select(query)(self._sire_object, property_map) except Exception as e: msg = "'Invalid search query: %r" % query diff --git a/python/BioSimSpace/_SireWrappers/_residue.py b/python/BioSimSpace/_SireWrappers/_residue.py index 51537dfb7..709ceba05 100644 --- a/python/BioSimSpace/_SireWrappers/_residue.py +++ b/python/BioSimSpace/_SireWrappers/_residue.py @@ -253,7 +253,7 @@ def toMolecule(self): """ return _Molecule(_SireMol.PartialMolecule(self._sire_object).extract().molecule()) - def search(self, query): + def search(self, query, property_map={}): """Search the residue for atoms and residues. Parameters @@ -262,6 +262,11 @@ def search(self, query): query : str The search query. + property_map : dict + A dictionary that maps system "properties" to their user defined + values. This allows the user to refer to properties with their + own naming scheme, e.g. { "charge" : "my-charge" } + Returns ------- @@ -283,12 +288,15 @@ def search(self, query): if type(query) is not str: raise TypeError("'query' must be of type 'str'") + if type(property_map) is not dict: + raise TypeError("'property_map' must be of type 'dict'") + # Intialise a list to hold the search results. results = [] try: - # Query the Sire system. - search_result = self._sire_object.search(query) + # Query the Sire residue. + search_result = _SireMol.Select(query)(self._sire_object, property_map) except Exception as e: msg = "'Invalid search query: %r" % query diff --git a/python/BioSimSpace/_SireWrappers/_system.py b/python/BioSimSpace/_SireWrappers/_system.py index 755c7180b..dac78af4c 100644 --- a/python/BioSimSpace/_SireWrappers/_system.py +++ b/python/BioSimSpace/_SireWrappers/_system.py @@ -682,7 +682,7 @@ def nPerturbableMolecules(self): """ return len(self.getPerturbableMolecules()) - def search(self, query): + def search(self, query, property_map={}): """Search the system for atoms, residues, and molecules. Search results will be reduced to their minimal representation, i.e. a molecule containing a single residue will be returned as a residue. @@ -693,6 +693,11 @@ def search(self, query): query : str The search query. + property_map : dict + A dictionary that maps system "properties" to their user defined + values. This allows the user to refer to properties with their + own naming scheme, e.g. { "charge" : "my-charge" } + Returns ------- @@ -728,12 +733,15 @@ def search(self, query): if type(query) is not str: raise TypeError("'query' must be of type 'str'") + if type(property_map) is not dict: + raise TypeError("'property_map' must be of type 'dict'") + # Intialise a list to hold the search results. results = [] try: # Query the Sire system. - search_result = self._sire_object.search(query) + search_result = _SireMol.Select(query)(self._sire_object, property_map) except Exception as e: msg = "'Invalid search query: %r" % query