Пример #1
0
def main():
    if len(sys.argv) != 3: # if no input
        print "Syntax: python db2_to_mol2.py db2file.db2 outprefix ";
        return

    filename  = sys.argv[1];
    outfileprefix  = sys.argv[2];

    print "filename: " + filename 

    db2mols = read_Moldb2_file(filename)
    allmol2s = convert_db2_to_mol2(db2mols)
    filecount = 0
    for mol2mols in allmol2s:
       outfilename = outfileprefix + "." + str(filecount) + ".mol2"
       print "writing "+ outfilename 
       count = 0
       for mol2mol in mol2mols:
          if count == 0: 
             mol2.write_mol2(mol2mol,outfilename)
          else:
             mol2.append_mol2(mol2mol,outfilename)
          count = count + 1
       filecount = filecount + 1
    return;
Пример #2
0
def main():
    if len(sys.argv) != 6:  # if no input
        print(" This script needs the following:")
        print(" (1) input mol2 file")
        print(" (2) output mol2 file")
        print(" (3-5) x, y, z rotation angles")
        print(" rotation order: x, y, then z with be rotated in that order. ")
        return

    mol2file = sys.argv[1]
    outputfile = sys.argv[2]
    xangle = float(sys.argv[3])
    yangle = float(sys.argv[4])
    zangle = float(sys.argv[5])

    cos_x = math.cos(xangle)
    xsign = 1.0
    if xangle < 0.0:
        xsign = -1.0

    cos_y = math.cos(yangle)
    ysign = 1.0
    if yangle < 0.0:
        ysign = -1.0

    cos_z = math.cos(zangle)
    zsign = 1.0
    if zangle < 0.0:
        zsign = -1.0

    mols = mol2.read_Mol2_file(mol2file)
    first = True
    for m in mols:
        center = mol2.centre_of_mass(m)
        translate(m, -center[0], -center[1], -center[2])
        rotate_x(m.atom_list, cos_x, xsign)
        rotate_y(m.atom_list, cos_y, ysign)
        rotate_z(m.atom_list, cos_z, zsign)
        translate(m, center[0], center[1], center[2])
        if first:
            mol2.write_mol2(m, outputfile)
            first = False
        else:
            mol2.append_mol2(m, outputfile)

    return
def main():


   if len(sys.argv) != 6: # if no input
       print ("ERORR:")
       print ("syntex: distance_cal_no_precomput.py mol2_file(docked poses) mol2_file(find poses close to) threshold hname output ")
       return
 

   infilemol2_poses     = sys.argv[1]
   infilemol2_ref       = sys.argv[2]
   dist_threshold       = float(sys.argv[3])
   hname                = sys.argv[4]
   outfile              = sys.argv[5]

   print ("input file (poses)     = ", infilemol2_poses)
   print ("input file (reference) = ", infilemol2_ref)
   print ("threshold =", dist_threshold)
   print ("head_name =", hname)
   print ("outputprefix =", outfile)
   #mol2_vector  = mol2.read_Mol2_file(infilemol2_poses)
   mol2_vector  = mol2.read_Mol2_file_head(infilemol2_poses)
   mol2_ref  = mol2.read_Mol2_file(infilemol2_ref)[0]


   count = 0
   for mol in mol2_vector: 
       min_dist = 100000
       count_atom_lt_thes = 0
       for atom in mol.atom_list: 
           if (atom.type == 'H'): 
               continue
           #dist = cal_dist_closest_grid_point(grid_dist,gridscale,xn,yn,zn,origin,atom)
           #dist = cal_dist_tri_linear(grid_dist,gridscale,xn,yn,zn,origin,atom)
           dist =  cal_min_dist_atom_mol(atom,mol2_ref)
           if dist < min_dist: 
              min_dist = dist
           if dist < dist_threshold: 
               count_atom_lt_thes = count_atom_lt_thes + 1   
       if min_dist < dist_threshold: 
          print("mol %d,dist=%f,num_atom_lt_threshold=%d"%(count,min_dist,count_atom_lt_thes))
          #close_mol2.append(mol)
          mol.header = mol.header+"##########  %s_dist:                    %f\n"%(hname,min_dist)
          mol.header = mol.header+"##########  %s_num_atom_lt_threshold:   %d\n"%(hname,count_atom_lt_thes)
          mol2.append_mol2(mol, outfile+'.mol2')
       count = count + 1
Пример #4
0
def multimol2_removeH(input, output):
    #print "This file requires the mol2 library written by Trent Balius (AKA Xiaobo Wan) and sudipto mukherjee"

    #print "syntex: multimol2_removeH.py input_file output_file"

    infile = input
    outfile = output

    file = open(outfile, 'w')  # overwrite
    file.close()

    mol_list = mol2.read_Mol2_file_head(infile)
    #print len(mol_list)

    for i in range(len(mol_list)):
        #print "mol ", i
        mol = mol2.remove_hydrogens(mol_list[i])
        mol2.append_mol2(mol, outfile)
Пример #5
0
def modify_mol2_file(mol2file, outputprefix):
    ## read in mol2 file
    frist = True
    mollist = mol2.read_Mol2_file(mol2file)
    for mol in mollist:
        ori_formal_charge = mol2.formal_charge(mol)
        n = len(mol.atom_list)
        Si_atoms_index = []
        for i in range(n):
            if mol.atom_list[i].name == 'CB' or mol.atom_list[i].name == 'SG':
                print(mol.atom_list[i].type, mol.atom_list[i].name)
                Si_atoms_index.append(i)

        if len(Si_atoms_index) != 2:
            print("error")
            exit()

        count_h = [0,
                   0]  # remember how meny atoms are connected to the both Si
        Hlist = [
        ]  # remember which the atom index that are the connected bonds.
        Si1 = Si_atoms_index[0]
        Si2 = Si_atoms_index[1]
        for bond in mol.bond_list:
            if bond.a1_num - 1 == Si1:
                if (mol.atom_list[bond.a2_num - 1].type == 'H'):
                    count_h[0] = count_h[0] + 1
                    Hlist.append(bond.a2_num)
            if bond.a2_num - 1 == Si1:
                if (mol.atom_list[bond.a1_num - 1].type == 'H'):
                    count_h[0] = count_h[0] + 1
                    Hlist.append(bond.a1_num)
            if bond.a1_num - 1 == Si2:
                if (mol.atom_list[bond.a2_num - 1].type == 'H'):
                    count_h[1] = count_h[1] + 1
                    Hlist.append(bond.a2_num)
            if bond.a2_num - 1 == Si2:
                if (mol.atom_list[bond.a1_num - 1].type == 'H'):
                    count_h[1] = count_h[1] + 1
                    Hlist.append(bond.a1_num)
        print(Hlist)
        print(count_h)

        # (1) remove 5 hydrogen atoms,
        # (2) change Si to Du and the atom name,

        new_atomlist = []
        for i, atom in enumerate(mol.atom_list):
            print(i, atom.num)
            #exit()
            if atom.num in Hlist:
                continue
            if atom.num - 1 == Si1:
                atom.type = 'Du'
                atom.Q = 0.0
                print("Hcount ==", count_h[0])
                if count_h[0] == 3:
                    atom.name = 'D2'
                elif count_h[0] == 0:  # SG will just have no H
                    #elif count_h[0] == 2:
                    atom.name = 'D1'
            if atom.num - 1 == Si2:
                atom.type = 'Du'
                atom.Q = 0.0
                print("Hcount ==", count_h[1])
                if count_h[1] == 3:
                    atom.name = 'D2'
                #elif count_h[1] == 2: #
                elif count_h[1] == 0:  # SG will just have no H
                    atom.name = 'D1'

            new_atomlist.append(copy.copy(atom))
        # (3) generate mapping from old to new atom numbering to be used in the bond modification.
        atom_num_map = {}
        for i, atom in enumerate(new_atomlist):
            atom_num_map[atom.num] = i + 1
            atom.num = i + 1

        # (4) remove bonds that contain any of the removed hydrogens.
        new_bondlist = []
        for i, bond in enumerate(mol.bond_list):
            if bond.a1_num in Hlist or bond.a2_num in Hlist:
                continue
            new_bondlist.append(copy.copy(bond))

        # (5) renumber the bonds, map old atom numbering to new atom number for bonds
        i = 1
        for bond in new_bondlist:
            bond.num = i
            bond.a1_num = atom_num_map[bond.a1_num]
            bond.a2_num = atom_num_map[bond.a2_num]
            i = i + 1

        mol.atom_list = new_atomlist
        mol.bond_list = new_bondlist

        # ajust Si-Si-C bond angle.  Looks like it is 90 deg.
        #ajust_angle(mol,ang)

        # ajust the partial charge to make it an integer.
        make_integer_charge(mol, ori_formal_charge)

        #exit()
        filename = outputprefix + '.mol2'
        if frist:
            mol2.write_mol2(mol, filename)
            frist = False
        else:
            mol2.append_mol2(mol, filename)

    return
for j, mol_3 in enumerate(mol_3list):
    print "molecule %d" % (j)
    #mol_3_new = copy.deepcopy(mol_3)
    atomlist = []
    for i, move in enumerate(maping):
        #print i,move,maping[i]
        atom = mol_3.atom_list[move]
        atom.num = i + 1
        atomlist.append(atom)

    #mol_3_new.atom_list = atomlist
    #bondlist     = copy.deepcopy(mol_2.bond_list)
    bondlist = mol_2.bond_list
    header = mol_3.header
    name = mol_3.name
    residuelist = mol_3.residue_list
    mol_3_new = mol2.Mol(header, name, atomlist, bondlist, residuelist)
    print mol_3.header, mol_3_new.header
    #  for bond in mol_3_new.bond_list:
    #      print bond.a1_num, bond.a2_num, bond.num, bond.type
    #      print atomlist[bond.a1_num-1].num, atomlist[bond.a2_num-1].num, bond.num, bond.type
    if j == 0:
        mol2.write_mol2(mol_3_new, outfile)
    else:
        mol2.append_mol2(mol_3_new, outfile)

#print len(mol_list)
#mol = mol2.remove_hydrogens( mol_list[0] )
#mol2.write_mol2(mol,outfile)
import mol2
import sys

print "this file requiers the mol2 libary writen by trent balius and sudipto mukherjee"

print "syntex: multimol2_removeH.py input_file output_file"

infile = sys.argv[1]
outfile = sys.argv[2]

file = open(outfile, 'w')  # overwrite
file.close()

mol_list = mol2.read_Mol2_file_head(infile)
print len(mol_list)

for i in range(len(mol_list)):
    print "mol ", i
    mol = mol2.remove_hydrogens(mol_list[i])
    mol2.append_mol2(mol, outfile)