Skip to content
Snippets Groups Projects
Commit ec09274b authored by Gerardo Tauriello's avatar Gerardo Tauriello
Browse files

SCHWED-4246: Documented mol.QueryQuoteName function.

parent a3f3f3ab
No related branches found
No related tags found
No related merge requests found
...@@ -48,13 +48,15 @@ Both the selection statements that have been used so far take strings as their a ...@@ -48,13 +48,15 @@ Both the selection statements that have been used so far take strings as their a
n_term = model.Select('rnum<=20') n_term = model.Select('rnum<=20')
If you want to supply arguments with special characters they need to be put in If you want to supply arguments with special characters they need to be put in
quotation marks. For instance, this is needed to select the chain named "_" or quotation marks (' or "). For instance, this is needed for any chain name
for any chain name conatining ".", " " or ",". Hence, chain "_" can be selected containing spaces as in:
with:
.. code-block:: python .. code-block:: python
model.Select('cname="_"') model.Select('cname=" "')
Almost any name can be quoted with :meth:`QueryQuoteName`.
Combining predicates Combining predicates
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -305,3 +307,22 @@ In the following, the interface of the query class is described. In general, you ...@@ -305,3 +307,22 @@ In the following, the interface of the query class is described. In general, you
* ``NO_BONDS`` - do not include any bonds (by default bonds are included) * ``NO_BONDS`` - do not include any bonds (by default bonds are included)
* ``MATCH_RESIDUES`` - include all atoms of a residue if any of its atoms is * ``MATCH_RESIDUES`` - include all atoms of a residue if any of its atoms is
selected (by default only selected atoms are included) selected (by default only selected atoms are included)
.. method:: QueryQuoteName(name)
Adds appropriate quotation marks to use *name* in a :class:`Query`. For
instance the following code snippet would generate a query string selecting
all chains from a list of chain names:
.. code-block:: python
query = "cname=" + ','.join(mol.QueryQuoteName(name) for name in names)
Note that there is some limited support of wild card symbols (* and ?) which
may have undesired effects in a query such as the code above.
:param name: Name to put in quotation marks
:type name: :class:`str`
:rtype: :class:`str`
:raises: :exc:`~exceptions.Exception` if *name* cannot be used in queries.
This happens if *name* includes both ' and " or if it ends with \\.
...@@ -124,14 +124,14 @@ inline String DLLEXPORT_OST_MOL QueryQuoteName(const String& name) { ...@@ -124,14 +124,14 @@ inline String DLLEXPORT_OST_MOL QueryQuoteName(const String& name) {
char quote = '\''; char quote = '\'';
if (name.find('\'') != String::npos) { if (name.find('\'') != String::npos) {
if (name.find('"') != String::npos) { if (name.find('"') != String::npos) {
throw Error("Cannot quote chain name " + name + " because it contains '" throw Error("Cannot quote chain name " + name + " because it contains "
" and \" in its name."); "both ' and \" in its name.");
} }
quote = '"'; quote = '"';
} }
// check problematic \ at end (escapes quotation mark and breaks logic) // check problematic \ at end (escapes quotation mark and breaks logic)
if (name[name.length() - 1] == '\\') { if (name[name.length() - 1] == '\\') {
throw Error("Cannot quote chain name " + name + "because it ends in \\."); throw Error("Cannot quote chain name " + name + " because it ends in \\.");
} }
return quote + name + quote; return quote + name + quote;
} }
...@@ -139,4 +139,3 @@ inline String DLLEXPORT_OST_MOL QueryQuoteName(const String& name) { ...@@ -139,4 +139,3 @@ inline String DLLEXPORT_OST_MOL QueryQuoteName(const String& name) {
}} // ns }} // ns
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment