~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to tools/moltemplate/src/nbody_alternate_symmetry/nbody_ImpropersIJIKILswapJK.py

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from nbody_graph_search import Ugraph
2
 
 
3
 
#    To find 4-body "improper" interactions, 
4
 
#    (by default, most of the time), we would use this subgraph:
5
 
#           3
6
 
#           *                  1st bond connects atoms 0 and 1
7
 
#           |              =>  2nd bond connects atoms 0 and 2
8
 
#         _.*._                3rd bond connects atoms 0 and 3
9
 
#       *'  0  `*              
10
 
#      1         2
11
 
#
12
 
 
13
 
bond_pattern = Ugraph([(0,1), (0,2), (0,3)])
14
 
# (Ugraph atom indices begin at 0, not 1)
15
 
 
16
 
 
17
 
def canonical_order(match):
18
 
    """
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.)
34
 
 
35
 
    """
36
 
    atom0 = match[0][0]
37
 
    atom1 = match[0][1]
38
 
    atom2 = match[0][2]
39
 
    atom3 = match[0][3]
40
 
    # match[1][0:2] contains the ID numbers for the 3 bonds
41
 
    bond0 = match[1][0]
42
 
    bond1 = match[1][1]
43
 
    bond2 = match[1][2]
44
 
    if atom1 <= atom2:
45
 
        #return ((atom0,atom1,atom2,atom3), (bond0, bond1, bond2))
46
 
        # But this is the same thing as:
47
 
        return match
48
 
    else:
49
 
        return ((atom0,atom2,atom1,atom3), (bond1, bond0, bond2))