예제 #1
0
파일: merge.py 프로젝트: Xin-1991/q2mm
def merge(struct_1, struct_2):
    """
    Takes two Schrödinger structures and combines them.

    Uses structure properties containing the string "pattern" to determine which
    atoms to overlap. If there are multiple pattern matches, it will try to use
    all of them.

    Arguments
    ---------
    struct_1 : Schrödinger structure object
    struct_2 : Schrödinger structure object

    Yields
    ------
    Schrödinger structure objects
    """
    # Determine the structures that overlap.
    match_1s, match_2s = get_overlapping_atoms_in_both(struct_1, struct_2)
    print('MATCHES FROM STRUCTURE 1: {}'.format(match_1s))
    print('MATCHES FROM STRUCTURE 2: {}'.format(match_2s))
    seen = set()
    for match_1 in match_1s:
        # Eliminate duplicates 1st.
        for match_2 in match_2s:
            print('-' * 80)
            # Remove the zero's if they exist.
            new_match_1, new_match_2 = remove_index_from_both_if_equals_zero(
                match_1, match_2)
            print('TRIMMED: {} {}'.format(new_match_1, new_match_2))
            tup = tuple(new_match_2)
            if tup not in seen:
                seen.add(tup)
                if struct_2.property.get('b_cs_first_match_only', False):
                    seen.add(tup[::-1])
                print(' - Unique! Continuing.')
                # Just to look good.
                print('-' * 80)
                print(' * ALIGNING:')
                print('   * {:<30} {} {}'.format(
                    struct_1._getTitle(),
                    new_match_1,
                    [struct_1.atom[x].atom_type_name for x in new_match_1]))
                print('   * {:<30} {} {}'.format(
                    struct_2._getTitle(),
                    new_match_2,
                    [struct_2.atom[x].atom_type_name for x in new_match_2]))
                # Real work below.
                rmsd.superimpose(struct_1, new_match_1, struct_2, new_match_2)
                yield merge_structures_from_matching_atoms(
                    struct_1, new_match_1, struct_2, new_match_2)
            else:
                print(' - Not unique! Skipping.')
예제 #2
0
파일: merge.py 프로젝트: nsf-c-cas/q2mm-2
def merge(struct_1, struct_2):
    """
    Takes two Schrödinger structures and combines them.

    Uses structure properties containing the string "pattern" to determine which
    atoms to overlap. If there are multiple pattern matches, it will try to use
    all of them.

    Arguments
    ---------
    struct_1 : Schrödinger structure object
    struct_2 : Schrödinger structure object

    Yields
    ------
    Schrödinger structure objects
    """
    # Determine the structures that overlap.
    match_1s, match_2s = get_overlapping_atoms_in_both(struct_1, struct_2)
    print('MATCHES FROM STRUCTURE 1: {}'.format(match_1s))
    print('MATCHES FROM STRUCTURE 2: {}'.format(match_2s))
    seen = set()
    for match_1 in match_1s:
        # Eliminate duplicates 1st.
        for match_2 in match_2s:
            print('-' * 80)
            # Remove the zero's if they exist.
            new_match_1, new_match_2 = remove_index_from_both_if_equals_zero(
                match_1, match_2)
            print('TRIMMED: {} {}'.format(new_match_1, new_match_2))
            tup = tuple(new_match_2)
            if tup not in seen:
                seen.add(tup)
                if struct_2.property.get('b_cs_first_match_only', False):
                    seen.add(tup[::-1])
                    print(' - Unique! Continuing.')
                    # Just to look good.
                print('-' * 80)
                print(' * ALIGNING:')
                print('   * {:<30} {} {}'.format(
                    struct_1.title,
                    new_match_1,
                    [struct_1.atom[x].atom_type_name for x in new_match_1]))
                print('   * {:<30} {} {}'.format(
                    struct_2.title,
                    new_match_2,
                    [struct_2.atom[x].atom_type_name for x in new_match_2]))
                    # Real work below.
                rmsd.superimpose(struct_1, new_match_1, struct_2, new_match_2)
                yield merge_structures_from_matching_atoms(
                    struct_1, new_match_1, struct_2, new_match_2)
            else:
                print(' - Not unique! Skipping.')
예제 #3
0
def main(args):
    parser = return_parser()
    opts = parser.parse_args(args)

    # Remove. Only for testing. Or if you're too lazy to use the command line,
    # here's another way to do things.
    # opts.input = INPUT
    # opts.output = OUTPUT
    # opts.merge = MERGE
    # opts.remove_from_input = REMOVE_FROM_INPUT
    # opts.remove_from_merge = REMOVE_FROM_MERGE
    # opts.bonds = BONDS
    
    if opts.remove_from_input:
        opts.remove_from_input.sort()
    if opts.remove_from_merge:
        opts.remove_from_merge.sort()

    reader_input = sch_struct.StructureReader(opts.input)
    reader_merge = sch_struct.StructureReader(opts.merge)
    writer = sch_struct.StructureWriter(opts.output)

    # Currently only designed to merge one structure.
    # In other words, no 2D combination arrays (although going that step
    # further wouldn't be challenging).
    structure_merge_orig = list(reader_merge)[0]
    # structure_merge.deleteAtoms(opts.remove_from_merge)
    # Moved this to make merging easier.
    
    if opts.superimpose:
        # Figure out superimpose atoms.
        superimpose_atoms_merge = []
        superimpose_atoms_input = []
        for superimpose_atoms in opts.superimpose:
            atom_input, atom_merge = map(int, superimpose_atoms.split('-'))
            superimpose_atoms_input.append(atom_input)
            superimpose_atoms_merge.append(atom_merge)

    # Work on input structures.
    for i, structure in enumerate(reader_input):
        # Refresh structure.
        structure_merge = deepcopy(structure_merge_orig)

        # It's ugly to do this inside of the loop, but I want to access the
        # structures inside reader_input.
        if i == 0:
            # The ordering of these lists is important.
            atom_input_new = []
            atom_merge_new = []
            # Figure out what the new atom numbers should be.
            # It's kind of a pain because we have to figure out where the atom
            # number exists post-deletion and post-merge.
            for bond in opts.bonds:
                # For the input structure.
                atom_input, atom_merge = map(int, bond.split('-'))
                atoms_less_than = sum(
                    x < atom_input for x in opts.remove_from_input)
                atom_input_new.append(atom_input - atoms_less_than)
                # For the merge structure.
                atoms_less_than = sum(
                    x < atom_merge for x in opts.remove_from_merge)
                atom_merge_new.append(
                    atom_merge - atoms_less_than + len(structure.atom) \
                        - len(opts.remove_from_input))

        if opts.superimpose:
            # Superposition before deletion. Should be easier.
            sch_rmsd.superimpose(
                structure_merge, superimpose_atoms_merge,
                structure, superimpose_atoms_input)

        # Moved to after superimpose.
        structure_merge.deleteAtoms(opts.remove_from_merge)

        # May want to comment out.
        for prop in PROPERTIES_TO_REMOVE:
            structure.property.pop(prop, None)
        structure.deleteAtoms(opts.remove_from_input)
        structure_new = structure.merge(structure_merge, copy_props=True)
        for x, y in zip(atom_input_new, atom_merge_new):
            # Default is to form a single bond. Could make this more fancy
            # later by expanding the argument parsing.
            structure_new.addBond(x, y, 1)
        writer.append(structure_new)

    writer.close()
    reader_merge.close()
    reader_input.close()
예제 #4
0
            ligand = items[0]
            print(ligand)
            score = items[2].rstrip()
            cen_num = 0  #there's only one receptor because this is the OE xtal docking

            recep_name = glob.glob(path + 'XTAL_docking/receptor_pdbs/*.pdb')
            for pdb in recep_name:
                recep = struct.Structure.read(
                    pdb)  #defining the corresponding receptor in the epv file
            rec_atoms = analyze.evaluate_asl(
                recep, '(( backbone ) ) AND (res.num 3-218)'
            )  #defining the backbone atoms of the corresponding receptor
            print(len(rec_atoms))
            rmsd.superimpose(
                recep, rec_atoms, xtal, xtal_rec, move_which=rmsd.CT
            )  #superimposing the coxtal structure's backbone atoms on the atoms of the current receptor

            lig = struct.Structure.read(path +
                                        'XTAL_docking/ligand_poses_pdbs/' +
                                        ligand + '.pdb')
            indices = analyze.evaluate_smarts_canvas(
                lig,
                'C1NNC(C12)CCNC2')  #getting the core indices of the ligand
            for index in indices:  #because the nested list gives the rmsd calculation big problems......
                lig_core = index

            xtal_lig = analyze.evaluate_asl(
                xtal, '(res.ptype "BC7 ")'
            )  #getting the indices of the coxtal ligand after superposition
            xtal_lig_struct = (struct._AtomCollection(
예제 #5
0
            for r in valid_r_s2:
                s2index = r_to_i_map_s2[r]

                if paired_str_s2[s2index] == paired_str_s1[s2index]:
                    if r not in final_r_list_s2:
                        final_r_list_s2.append(r)

                    if i_to_r_map_s1[s2index] not in final_r_list_s1:
                        final_r_list_s1.append(i_to_r_map_s1[s2index])

            a_list_s1 = get_atom_list(s1, final_r_list_s1)
            a_list_s2 = get_atom_list(s2, final_r_list_s2)

            final_a_list_s1 = []
            final_a_list_s2 = []

            for k in range(len(a_list_s1)):
                if len(a_list_s1[k]) == len(a_list_s2[k]):
                    final_a_list_s1 += a_list_s1[k]
                    final_a_list_s2 += a_list_s2[k]

            arr.append(
                rmsd.superimpose(s1, final_a_list_s1, s2, final_a_list_s2))

        rmsds.append(arr)

    print(rmsds)
    outfile = open('/home/users/sidhikab/MAPK14_pairwise_struc_rmsds', 'wb')
    pickle.dump(rmsds, outfile)
    outfile.close()
예제 #6
0
def rmsdRef():
    lines = []
    with open('v92.finalResult', 'r') as f:
        lines = f.readlines()[1:]
    seeds = []
    energies = []
    nativeRMSDs = []
    for line in lines:
        terms = line.split()
        seeds.append(int(terms[0]))
        energies.append(float(terms[8]))
        nativeRMSDs.append(terms[9])
    energies, seeds, nativeRMSDs = (list(t) for t in \
    zip(*sorted(zip(energies, seeds, nativeRMSDs))))

    cwd = os.getcwd()

    pattern = None
    with open('v92.con', 'r') as f:
        conLines = f.readlines()
    for line in conLines:
        if 'subjob_control' in line:
            terms = line.split()
            pattern = terms[2]

    structs = []
    for i in range(len(seeds)):
        for dir in os.listdir(os.path.join(cwd, 'subJobs')):
            if dir.split('_')[0] == str(seeds[i]):
                os.chdir(os.path.join(cwd, 'subJobs', dir))
                if 'plop.stdout' in os.listdir('.'):
                    stName = '4KUZ-p' + str(
                        pattern) + '-' + nativeRMSDs[i] + '_template.maegz'
                    structs.append(next(structure.StructureReader(stName)))
                os.chdir(cwd)
    minStruct = copy.deepcopy(structs[0])

    ALLINDICES = analyze.evaluate_asl(minStruct, ALLINDICES_asl)
    LOOPENVINDICES = analyze.evaluate_asl(minStruct, LOOPENVINDICES_asl)
    NONLOOPINDICES = analyze.evaluate_asl(minStruct, NONLOOPINDICES_asl)

    rmsds = []
    for i in range(0, len(structs)):
        curStruct = structs[i]
        rmsd.superimpose(minStruct, NONLOOPINDICES, curStruct, NONLOOPINDICES)
        RMSD = rmsd.calculate_in_place_rmsd(minStruct, LOOPENVINDICES,
                                            curStruct, LOOPENVINDICES)
        rmsds.append(RMSD)

    # What about Hbond patterns?
    hbonds = []
    for i in range(0, len(structs)):
        curStruct = structs[i]
        hbonds.append(hbond.get_hydrogen_bonds(curStruct, LOOPENVINDICES))

    hbondIndices = []
    for i in range(0, len(hbonds)):
        structIndices = []
        hbondIndices.append(structIndices)
        for j in range(0, len(hbonds[i])):
            pairIndices = []
            hbondIndices[i].append(pairIndices)
            for k in range(0, 2):
                hbondIndices[i][j].append(hbonds[i][j][k].index)

    min_hb_indices = copy.deepcopy(hbondIndices[0])
    hbond_overlaps = []
    for i in range(0, len(hbondIndices)):
        li1 = [tuple(lst) for lst in min_hb_indices]
        li2 = [tuple(lst) for lst in hbondIndices[i]]

        overlap = []
        for pair in li1:
            if pair in li2:
                overlap.append(pair)
        sm = difflib.SequenceMatcher(None, li1, li2)
        hbond_overlaps.append(round(sm.ratio(), 5))

    # What about salt bridge interactions?
    bridges = []
    for i in range(0, len(structs)):
        curStruct = structs[i]
        bridges.append(salt_bridge.get_salt_bridges(curStruct, LOOPENVINDICES))

    bridgeIndices = []
    for i in range(0, len(bridges)):
        structIndices = []
        bridgeIndices.append(structIndices)
        for j in range(0, len(bridges[i])):
            pairIndices = []
            bridgeIndices[i].append(pairIndices)
            for k in range(0, 2):
                bridgeIndices[i][j].append(bridges[i][j][k].index)

    min_bridge_indices = copy.deepcopy(bridgeIndices[0])
    salt_bridge_overlaps = []
    for i in range(0, len(bridgeIndices)):
        li1 = [tuple(lst) for lst in min_bridge_indices]
        li2 = [tuple(lst) for lst in bridgeIndices[i]]

        overlap = []
        for pair in li1:
            if pair in li2:
                overlap.append(pair)
        sm = difflib.SequenceMatcher(None, li1, li2)
        salt_bridge_overlaps.append(round(sm.ratio(), 5))

    # Hydrophobic interactions

    print('SEED\t\tRMSD\t\tHBOND_OVERLAP\tSALTBR_OVERLAP\tENERGY')
    for i in range(0, len(rmsds)):
        print(
            str(seeds[i]) + '\t\t' + str(round(rmsds[i], 3)) + '\t\t' +
            str(hbond_overlaps[i] * 100) + '\t\t' +
            str(salt_bridge_overlaps[i] * 100) + '\t\t' + str(energies[i]))