Skip to content

Commit 8f957b8

Browse files
authored
Attempt to detect delocalized atoms (#439)
1 parent f31e79f commit 8f957b8

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

layer1/P.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,9 @@ static T const* get_member_pointer(S const* instance, size_t offset)
615615
* Should be equivalent to:
616616
* OBAtom::GetExplicitValence() [Open Babel 3.0]
617617
*/
618-
static int getExplicitValence(ObjectMolecule const* obj, size_t atm)
618+
unsigned getExplicitValence(ObjectMolecule const* obj, size_t atm)
619619
{
620-
int value = 0;
620+
unsigned value = 0;
621621

622622
for (auto const& item : AtomNeighbors(obj, atm)) {
623623
int const order = obj->Bond[item.bond].order;
@@ -643,7 +643,7 @@ static int getExplicitValence(ObjectMolecule const* obj, size_t atm)
643643
* RDKit::Atom::getDegree()
644644
* OBAtom::GetExplicitDegree() [Open Babel 3.0]
645645
*/
646-
static unsigned getExplicitDegree(ObjectMolecule const* obj, size_t atm)
646+
unsigned getExplicitDegree(ObjectMolecule const* obj, size_t atm)
647647
{
648648
return AtomNeighbors(obj, atm).size();
649649
}

layer1/P.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Z* -------------------------------------------------------------------
5656
#define cPRunType_alter_state 2
5757
#define cPRunType_label 3
5858

59+
unsigned getExplicitValence(ObjectMolecule const* obj, size_t atm);
60+
unsigned getExplicitDegree(ObjectMolecule const* obj, size_t atm);
5961

6062
int PLabelExprUsesVariable(PyMOLGlobals * G, const char *expr, const char *var);
6163

layer3/Selector.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Z* -------------------------------------------------------------------
5454
#include"OVLexicon.h"
5555
#include"Parse.h"
5656

57+
#include "P.h"
5758
#include"ListMacros.h"
5859

5960
#ifdef _PYMOL_IP_PROPERTIES
@@ -410,6 +411,7 @@ static int SelectorGetObjAtmOffset(
410411
#define SELE_LABs ( 0x5500 | STYP_SEL1 | 0x80 )
411412
#define SELE_PROz ( 0x5600 | STYP_SEL0 | 0x90 )
412413
#define SELE_NUCz ( 0x5700 | STYP_SEL0 | 0x90 )
414+
#define SELE_DESz ( 0x5800 | STYP_SEL0 | 0x90 )
413415

414416
#define SEL_PREMAX 0x8
415417

@@ -604,6 +606,9 @@ static WordKeyValue Keyword[] = {
604606
{"acceptors", SELE_ACCz},
605607
{"acc.", SELE_ACCz},
606608

609+
{"delocalized", SELE_DESz},
610+
{"deloc.", SELE_DESz},
611+
607612
{"pepseq", SELE_PEPs},
608613
{"ps.", SELE_PEPs},
609614

@@ -7471,7 +7476,7 @@ static int SelectorSelect0(PyMOLGlobals * G, EvalElem * passed_base)
74717476
case SELE_HBDs:
74727477
case SELE_DONz:
74737478
case SELE_ACCz:
7474-
7479+
case SELE_DESz:
74757480
{
74767481
/* first, verify chemistry for all atoms... */
74777482
ObjectMolecule *lastObj = nullptr, *obj;
@@ -7494,7 +7499,14 @@ static int SelectorSelect0(PyMOLGlobals * G, EvalElem * passed_base)
74947499
for(a = cNDummyAtoms; a < I->Table.size(); a++)
74957500
base[0].sele[a] = I->Obj[I->Table[a].model]->AtomInfo[I->Table[a].atom].hb_donor;
74967501
break;
7497-
7502+
case SELE_DESz:
7503+
for (a = cNDummyAtoms; a < I->Table.size(); a++) {
7504+
const auto* m = I->Obj[I->Table[a].model];
7505+
const auto at_i = I->Table[a].atom;
7506+
const auto deloc = (float) getExplicitDegree(m, at_i) / (float) getExplicitValence(m, at_i);
7507+
base[0].sele[a] = floor(deloc) != deloc;
7508+
}
7509+
break;
74987510
}
74997511
break;
75007512
case SELE_NONz:

testing/tests/api/querying.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def testCountAtoms(self):
2929
# used in many tests
3030
pass
3131

32+
def testSelectDelocalized(self):
33+
cmd.fragment("phe")
34+
count = cmd.count_atoms("deloc.")
35+
self.assertEqual(count, 8)
36+
count = cmd.count_atoms("delocalized")
37+
self.assertEqual(count, 8)
38+
3239
def testCountFrames(self):
3340
self.assertEqual(cmd.count_frames(), 0)
3441
cmd.pseudoatom("m1")

0 commit comments

Comments
 (0)