def main(): if len(sys.argv) != 6: # if no input print("ERORR:") print( "syntex: mol2_energy_filter mol2_file(docked poses) energy_threshold energyname cnum output " ) print( " energyname is the name of the energy term and cnum is the column, eg 'Total Energy' where cnum is 4 or 'Footprint_Similarity_Score:' where cnum is 3" ) return infilemol2_poses = sys.argv[1] val = float(sys.argv[2]) ename = sys.argv[3] cnum = int(sys.argv[4]) outfile = sys.argv[5] print("input file (poses) = %s" % infilemol2_poses) print("energy threshold = %f" % val) print("outputprefix = %s" % outfile) if infilemol2_poses.split('.')[-1] == 'mol2': print("reading in mol2") #mol2_vector = mol2.read_Mol2_file(infilemol2_poses) mol2_vector = mol2.read_Mol2_file_head(infilemol2_poses) if infilemol2_poses.split('.')[-1] == 'gz': print("reading in gz mol2 file") mol2_vector = mol2.read_Mol2_file_head_gz(infilemol2_poses) count = 0 for mol in mol2_vector: #print(mol.header) lines = mol.header.split('\n') #file1.close() for line in lines: #print(line) if ename in line: #print(line) splitline = line.split() energy = float(splitline[cnum - 1]) #print(energy) if energy < val: print(energy) mol2.append_mol2(mol, outfile + '.mol2')
def main(): if len(sys.argv) != 4: # if no input print("ERORR:") print( "syntex: mol2_energy_filter mol2_file(docked poses) energy_threshold output " ) return infilemol2_poses = sys.argv[1] val = float(sys.argv[2]) outfile = sys.argv[3] print("input file (poses) = %s" % infilemol2_poses) print("energy threshold = %f" % val) print("outputprefix = %s" % outfile) if infilemol2_poses.split('.')[-1] == 'mol2': print("reading in mol2") #mol2_vector = mol2.read_Mol2_file(infilemol2_poses) mol2_vector = mol2.read_Mol2_file_head(infilemol2_poses) if infilemol2_poses.split('.')[-1] == 'gz': print("reading in gz mol2 file") mol2_vector = mol2.read_Mol2_file_head_gz(infilemol2_poses) count = 0 for mol in mol2_vector: #print(mol.header) lines = mol.header.split('\n') #file1.close() for line in lines: #print(line) if 'Total' in line: #print(line) splitline = line.split() energy = float(splitline[3]) #print(energy) if energy < val: print(energy) mol2.append_mol2(mol, outfile + '.mol2')
def main(): if len(sys.argv) != 3: # if no input print("ERORR:") print("syntex: mol2_energy_sort mol2_file(docked poses) output ") return infilemol2_poses = sys.argv[1] outfile = sys.argv[2] print("input file (poses) = %s" % infilemol2_poses) print("outputprefix = %s" % outfile) if infilemol2_poses.split('.')[-1] == 'mol2': print("reading in mol2") #mol2_vector = mol2.read_Mol2_file(infilemol2_poses) mol2_vector = mol2.read_Mol2_file_head(infilemol2_poses) if infilemol2_poses.split('.')[-1] == 'gz': print("reading in gz mol2 file") mol2_vector = mol2.read_Mol2_file_head_gz(infilemol2_poses) count = 0 energy_vec = [] for mol in mol2_vector: lines = mol.header.split('\n') #file1.close() for line in lines: if 'Total' in line: splitline = line.split() energy = float(splitline[3]) energy_vec.append(energy) energy_vec_sort = sorted(enumerate(energy_vec), key=lambda x: x[1]) #energy_vec_sort = sorted(enumerate(energy_vec), key=lambda x: -x[1]) for entry in energy_vec_sort: print(entry) print(entry[0]) mol2.append_mol2(mol2_vector[entry[0]], outfile + '.mol2')
print("wrong number of arguments. there must be 5 or 6, not %d. " % len(sys.argv)) exit() infile = sys.argv[1] outfile = sys.argv[2] a1_ori = sys.argv[3] # ori a2_rep = sys.argv[4] a3_search = sys.argv[5] if (len(sys.argv) == 7): a2_name = sys.argv[6] #new atom name else: a2_name = "NONE" print( 'infile=%s,\noutfile=%s,\na1_ori=%s,\na2_rep=%s,\na3_search=%s\na2_name=%s\n' % (infile, outfile, a1_ori, a2_rep, a3_search, a2_name)) mol_list = mol2.read_Mol2_file(infile) print(len(mol_list)) count = 0 for mol in mol_list: moln = loop_bonds(a1_ori, a2_rep, a3_search, a2_name, mol) if (count == 0): mol2.write_mol2(moln, outfile) else: mol2.append_mol2(moln, outfile) count = count + 1 print("processed %d mol2 entries" % count)
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].type == 'Si': print (mol.atom_list[i].type, mol.atom_list[i].name) Si_atoms_index.append(i) #if len(Si_atoms_index) != 2: if len(Si_atoms_index) != 1: 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 if count_h[0] == 3: #atom.name = 'D2' atom.name = 'D1' elif count_h[0] == 2: #atom.name = 'D1' print ("error") exit() # if atom.num-1 == Si2: # atom.type = 'Du' # atom.Q = 0.0 # if count_h[1] == 3: # atom.name = 'D2' # elif count_h[1] == 2: # # 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 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