Beispiel #1
0
def generate_rigid_groups(axislist, matrix):
    """
    Generates rigid groups from the list of rotation axis and checks
    every group's suitability for an attached rigid group
    """
    rigid_groups = []
    for axis in axislist:
        rigid_groups.append(cg.framework_crawler(axis[0], axis[1]))
    vals = []
    printer('\nChecking potential groups\' rigidity.')
    for group in rigid_groups:
        printer()
        vals.append(check_rigidity(group, matrix))
    accepted_groups = []
    printer('\n')
    for _ in range(len(vals)):
        bestgroup = min(vals)
        if bestgroup > RIGIDITY_THRESHOLD:
            if len(accepted_groups) == 0:
                printer('No suitable rigid groups detected.')
            break
        i = vals.index(bestgroup)
        potential_group = rigid_groups[i]
        print
        if too_close(potential_group, accepted_groups):
            printer('\nKill too similar group:', [k.name for k in potential_group])
            vals[i] = 999
            continue
        accepted_groups.append(potential_group)
        printer('Accepted rigid group:', [k.name for k in potential_group])
        vals[i] = 999

    return accepted_groups
Beispiel #2
0
def segment(srb):
    """
    Function to segment a molecule in rigid groups that are allowed to
    rotate against each other arround a defined axis.
    """
    # atom1,atom2,axis=get_user_input()
    tls_definitions = get_user_input(srb)
    rigid_groups, rigid_namess, axiss = [], [], []
    for tls_definition in tls_definitions:
        rigid_groups.append(cg.framework_crawler(tls_definition[1], tls_definition[2]))
        axiss.append(tls_definition[0])
        rigid_names = []
        for atom in rigid_groups[-1]:
            rigid_names.append(atom.name)
        #raw_matrix=raw_rotation_matrix(data,axis,rigid_group)
        rigid_namess.append(rigid_names)

    if len(rigid_namess) > 100:
        namesets = []
        for group in rigid_namess:
            evalstring = '{'
            for string in group:
                evalstring += '\'' + string
                evalstring += '\','
            evalstring += '}'
            nameset = eval(evalstring)
            namesets.append(nameset)

        hierachy = []
        for i in range(len(namesets)):
            hierachy.append([0, i])
            group1 = namesets[i]
            for j in range(len(namesets)):
                group2 = namesets[j]
                if not group1 == group2:
                    if group1.issubset(group2):
                        hierachy[j][0] += 1

        hierachy = sorted(hierachy, key=lambda hierachy: hierachy[0], reverse=True)
        sorted_rigid_groups = []
        sorted_rigid_names = []
        sorted_axiss = []
        for hierach in hierachy:
            sorted_rigid_groups.append(rigid_groups[hierach[1]])
            sorted_rigid_names.append(rigid_names[hierach[1]])
            sorted_axiss.append(axiss[hierach[1]])
        #sys.exit()
        print([i for i in sorted_rigid_names])

    else:
        sorted_rigid_groups = rigid_groups
        sorted_rigid_names = rigid_names
        sorted_axiss = axiss

    return sorted_rigid_groups, sorted_rigid_names, sorted_axiss