コード例 #1
0
try:
    from ..nbody_graph_search import Ugraph
except:
    # not installed as a module
    from nbody_graph_search import Ugraph

#    To find 4-body "improper" interactions, we would use this subgraph:
#           3
#           *                  1st bond connects atoms 0 and 1
#           |              =>  2nd bond connects atoms 0 and 2
#         _.*._                3rd bond connects atoms 0 and 3
#       *'  0  `*
#      1         2
#

bond_pattern = Ugraph([(0, 1), (0, 2), (0, 3)])
# (Note: Ugraph atom-index counters begin at 0, not 1)


def canonical_order(match):
    """
    When searching for atoms with matching bond patterns GraphMatcher
    often returns redundant results. We must define a "canonical_order"
    function which sorts the atoms and bonds in a way which is consistent
    with the type of N-body interaction being considered.
    The atoms (and bonds) in a candidate match are rearranged by the
    canonical_order().  Then the re-ordered list of atom and bond ids is
    tested against the list of atom/bond ids in the matches-found-so-far,
    before it is added to the list of interactions found so far.  In this
    case we assume the second atom is the central atom (the "hub"), and the
    energy is invariant with respect to permutations of the other 3 atoms.
コード例 #2
0
from nbody_graph_search import Ugraph

#    To find 4-body "dihedral" interactions, we would use this subgraph:
#
#                              1st bond connects atoms 0 and 1
#       *---*---*---*      =>  2nd bond connects atoms 1 and 2
#       0   1   2   3          3rd bond connects atoms 2 and 3
#

bond_pattern = Ugraph([(0, 1), (1, 2), (2, 3)])
# (Ugraph atom indices begin at 0, not 1)


def canonical_order(match):
    """
    When searching for atoms with matching bond patterns GraphMatcher
    often returns redundant results. We must define a "canonical_order"
    function which sorts the atoms and bonds in a way which is consistent 
    with the type of N-body interaction being considered.
    However, some dihedral_styles (such as dihedral_style class2)
    have no symmetry (at least not for arbitrary choices of parameters).
    These force-field styles, the different permulations of atom-order
    are not equivalent.  So we do not want to rearrange the order of
    the atoms (and bonds) in the match, because the formula for the 
    interaction between atoms 1,2,3,4 is not the same as the formula 
    for the interaction between atoms 4,3,2,1.
    In this case, this function returns
    the original "match" argument unmodified.

    """
コード例 #3
0
def GenInteractions_str(
        bond_pairs,
        g_bond_pattern,
        typepattern_to_coefftypes,
        canonical_order,  # function to sort atoms and bonds
        atomids_str,
        atomtypes_str,
        bondids_str,
        bondtypes_str,
        report_progress=False,  # print messages to sys.stderr?
        check_undefined=False):

    assert (len(atomids_str) == len(atomtypes_str))
    assert (len(bondids_str) == len(bondtypes_str))
    # The atomids and atomtypes and bondtypes are strings.
    # First we assign a unique integer id to each string.

    atomids_str2int = {}
    atomtypes_str2int = {}
    atomtypes_int2str = []
    atomtype_int = 0
    for i in range(0, len(atomids_str)):
        if atomids_str[i] in atomids_str2int:
            raise InputError('Error: multiple atoms have the same id (' +
                             str(atomids_str[i]) + ')')
        atomids_str2int[atomids_str[i]] = i
        #atomtypes_int = len(atomtypes_int)+1
        if (not (atomtypes_str[i] in atomtypes_str2int)):
            atomtypes_str2int[atomtypes_str[i]] = atomtype_int
            atomtypes_int2str.append(atomtypes_str[i])
            atomtype_int += 1
        # atomtypes_int.append(atomtype_int)

    bondids_str2int = {}
    bondtypes_str2int = {}
    bondtypes_int2str = []
    bondtype_int = 0
    for i in range(0, len(bondids_str)):
        if bondids_str[i] in bondids_str2int:
            raise InputError('Error: multiple bonds have the same id (' +
                             str(bondids_str[i]) + ')')
        bondids_str2int[bondids_str[i]] = i
        #bondtype_int = len(bondtypes_int)+1
        if (not (bondtypes_str[i] in bondtypes_str2int)):
            bondtypes_str2int[bondtypes_str[i]] = bondtype_int
            bondtypes_int2str.append(bondtypes_str[i])
            bondtype_int += 1

    # Now convert "bond_pairs" into the UGraph format
    G_system = Ugraph()
    for iv in range(0, len(atomtypes_str)):
        G_system.AddVertex(iv, atomtypes_str2int[atomtypes_str[iv]])

    for ie in range(0, len(bond_pairs)):
        atomid1_str = bond_pairs[ie][0]
        atomid2_str = bond_pairs[ie][1]
        if (atomid1_str not in atomids_str2int):
            raise InputError('Error in Bonds Section:\n'
                             '  ' + atomid1_str +
                             ' is not defined in Atoms section\n')
        if (atomid2_str not in atomids_str2int):
            raise InputError('Error in Bonds Section:\n'
                             '  ' + atomid2_str +
                             ' is not defined in Atoms section\n')
        G_system.AddEdge(atomids_str2int[atomid1_str],
                         atomids_str2int[atomid2_str],
                         bondtypes_str2int[bondtypes_str[ie]])

    coefftype_to_atomids_int = GenInteractions_int(
        G_system, g_bond_pattern, typepattern_to_coefftypes, canonical_order,
        atomtypes_int2str, bondtypes_int2str, report_progress,
        (atomids_str if check_undefined else None))

    coefftype_to_atomids_str = OrderedDict()
    for coefftype, atomidss_int in coefftype_to_atomids_int.items():
        if report_progress:
            sys.stderr.write('    processing coefftype: ' + str(coefftype) +
                             '\n')
        for atomids_int in atomidss_int:
            if coefftype in coefftype_to_atomids_str:
                coefftype_to_atomids_str[coefftype].append(
                    [atomids_str[iv] for iv in atomids_int])
            else:
                coefftype_to_atomids_str[coefftype] = \
                    [[atomids_str[iv] for iv in atomids_int]]
        # gc.collect()

    return coefftype_to_atomids_str
コード例 #4
0
ファイル: nbody_Bonds.py プロジェクト: BoyangGu/Temporary_CAC
try:
    from .nbody_graph_search import Ugraph
except (SystemError, ValueError):
    # not installed as a package
    from nbody_graph_search import Ugraph

#    To find 2-body "bond" interactions, we would use this subgraph:
#
#
#       *---*           =>  one bond connects atoms 0 and 1
#       0   1
#

bond_pattern = Ugraph([(0, 1)])

# (Ugraph atom indices begin at 0, not 1)


#    The next function eliminates the redundancy between 0-1 and 1-0:
def canonical_order(match):
    """
    It does not make sense to define a separate bond between atoms 1 and 2,
    and between atoms 2 and 1.  This function will swap the atoms in the bond
    if the first atom > second atom.

    """
    # match[0][0:2] contains the ID numbers for the 2 atoms in the match
    atom0 = match[0][0]
    atom1 = match[0][1]
    # match[1][0:1] contains the ID numbers for the 1 bond
    bond0 = match[1][0]
コード例 #5
0
ファイル: cenJswapIL.py プロジェクト: BoyangGu/Temporary_CAC
    from nbody_graph_search import Ugraph

#    To find 4-body "improper" interactions,
#    (by default, most of the time), we would use this subgraph:
#           0
#           *                  1st bond connects atoms 1 and 0
#           |              =>  2nd bond connects atoms 1 and 2
#         _.*._                3rd bond connects atoms 1 and 3
#       *'  1  `*
#      2         3
#
# In OPLS, the central atom is the second atom ("1").
# This differs from other force-fields.
# We take this detail into account in the line below:

bond_pattern = Ugraph([(1, 0), (1, 2), (1, 3)])

# As with other force-fields, the improper-angle is the angle between the planes
# defined by the first three atoms (0,1,2) and last three atoms (1,2,3).
# (This is implemented in LAMMPS using an improper_style which requires
#  that the atoms in the interaction will be listed in this order: 0,1,2,3.)


def canonical_order(match):
    """
    Before defining a new interaction, we must check to see if an
    interaction between these same 4 atoms has already been created
     (perhaps listed in a different, but equivalent order).
    If we don't check for this this, we will create many unnecessary redundant
    interactions (which can slow down he simulation).
    To avoid this, I define a "canonical_order" function which sorts the atoms
コード例 #6
0
#    To find 4-body "improper" interactions,
#    (by default, most of the time), we would use this subgraph:
#           0
#           *                  1st bond connects atoms 2 and 0
#           |              =>  2nd bond connects atoms 2 and 1
#         _.*._                3rd bond connects atoms 2 and 3
#       *'  2  `*
#      1         3
#
# In AMBER/GAFF, the central atom is the third atom ("2").
# http://archive.ambermd.org/201307/0519.html
# This differs from other force-fields.
# We take this detail into account in the line below:

bond_pattern = Ugraph([(2, 0), (2, 1), (2, 3)])

# As with other force-fields, the improper-angle is the angle between the planes
# defined by the first three atoms (0,1,2) and last three atoms (1,2,3).
# (This is implemented in LAMMPS using an improper_style which requires
#  that the atoms in the interaction will be listed in this order: 0,1,2,3.)


def canonical_order(match):
    """
    Before defining a new interaction, we must check to see if an
    interaction between these same 4 atoms has already been created
     (perhaps listed in a different, but equivalent order).
    If we don't check for this this, we will create many unnecessary redundant
    interactions (which can slow down he simulation).
    To avoid this, I define a "canonical_order" function which sorts the atoms