1
from nbody_graph_search import Ugraph
3
# To find 4-body "improper" interactions,
4
# (by default, most of the time), we would use this subgraph:
6
# * 1st bond connects atoms 0 and 1
7
# | => 2nd bond connects atoms 0 and 2
8
# _.*._ 3rd bond connects atoms 0 and 3
13
bond_pattern = Ugraph([(0,1), (0,2), (0,3)])
14
# (Ugraph atom indices begin at 0, not 1)
17
def canonical_order(match):
19
When searching for atoms with matching bond patterns GraphMatcher
20
often returns redundant results. We must define a "canonical_order"
21
function which sorts the atoms and bonds in a way which is consistent
22
with the type of N-body interaction being considered.
23
The atoms (and bonds) in a candidate match are rearranged by the
24
canonical_order(). Then the re-ordered list of atom and bond ids is
25
tested against the list of atom/bond ids in the matches-found-so-far,
26
before it is added to the list of interactions found so far.
27
(For example, it does not make sense to define a separate 4-body improper-
28
angle interaction between atoms 1, 2, 3, 4 AND 1, 3, 2, 4.
29
The improper-angle is usually defined as the angle between planes formed
30
by atoms 1,2,3 & 2,3,4. Alternately, it may instead be defined as the
31
angle between the 1,2,3 plane and atom 4. Either way, this angle does
32
not change when swapping the middle pair of atoms so we arbitrarily
33
sort them so that the second atom has a lower atomID than the third atom.)
40
# match[1][0:2] contains the ID numbers for the 3 bonds
45
#return ((atom0,atom1,atom2,atom3), (bond0, bond1, bond2))
46
# But this is the same thing as:
49
return ((atom0,atom2,atom1,atom3), (bond1, bond0, bond2))