def ligand_preparation(ligand, output): ligand_filename = None verbose = None add_bonds = False repairs = "" charges_to_add = 'gasteiger' preserve_charge_types='' cleanup = "nphs_lps" allowed_bonds = "backbone" root = 'auto' outputfilename = output check_for_fragments = False bonds_to_inactivate = "" inactivate_all_torsions = False attach_nonbonded_fragments = False attach_singletons = False mode = 'automatic' dict = None mols = Read(ligand) mol = mols[0] mol.buildBondsByDistance() LPO = AD4LigandPreparation(mol, mode, repairs, charges_to_add, cleanup, allowed_bonds, root, outputfilename=output, dict=dict, check_for_fragments=check_for_fragments, bonds_to_inactivate=bonds_to_inactivate, inactivate_all_torsions=inactivate_all_torsions, attach_nonbonded_fragments=attach_nonbonded_fragments, attach_singletons=attach_singletons)
def prepare_ligand(self, molecule): path = '{}_ligand.pdb'.format(self.tmpfile) pathqt = path + 'qt' pdb = molecule.write(absolute=path, filetype='pdb') self._paths.append(path) mol = MolKit.Read(path)[0] mol.buildBondsByDistance() RPO = AD4LigandPreparation(mol, outputfilename=pathqt) # inactivate_all_torsions=True) self._paths.append(pathqt) return pathqt
if o in ('-h', '--'): usage() sys.exit() if not pdbqt_filename: print 'repair_ligand4: pdbqt_filename must be specified.' usage() sys.exit() mol = Read(pdbqt_filename)[0] if verbose: print 'read ', pdbqt_filename mol.buildBondsByDistance() mol.LPO = AD4LigandPreparation(mol, mode='interactive', repairs='', charges_to_add=None, root=0, outputfilename=outputfilename, cleanup='') #rebuild torTree allAts = mol.allAtoms for b in allAts.bonds[0]: if b.activeTors: b.activeTors = 0 torscount = 0 tM = mol.torTree.torsionMap for i in range(len(tM)): bnum0, bnum1 = tM[i].bond a0 = allAts.get(lambda x: x.number == bnum0 + 1)[0] a0.tt_ind = bnum0 a1 = allAts.get(lambda x: x.number == bnum1 + 1)[0] a1.tt_ind = bnum1
print "key=", key print "val =", val if verbose: print "setting up LPO with mode=", mode, print "and outputfilename= ", outputfilename print "and check_for_fragments=", check_for_fragments print "and bonds_to_inactivate=", bonds_to_inactivate LPO = AD4LigandPreparation( mol, mode, repairs, charges_to_add, cleanup, allowed_bonds, root, outputfilename=outputfilename, dict=dict, check_for_fragments=check_for_fragments, bonds_to_inactivate=bonds_to_inactivate, inactivate_all_torsions=inactivate_all_torsions, attach_nonbonded_fragments=attach_nonbonded_fragments, attach_singletons=attach_singletons) #do something about atoms with too many bonds (?) #FIX THIS: could be peptide ligand (???) # ??use isPeptide to decide chargeSet?? if charges_to_add is not None: #restore any previous charges for atom, chargeList in preserved.items(): atom._charges[chargeList[0]] = chargeList[1] atom.chargeSet = chargeList[0]
def preprocess_ligand(ligand_filename, outputfilename): verbose = None repairs = "" #"hydrogens_bonds" charges_to_add = 'gasteiger' preserve_charge_types='' cleanup = "" allowed_bonds = "backbone" root = 'auto' check_for_fragments = True bonds_to_inactivate = "" inactivate_all_torsions = True attach_nonbonded_fragments = True attach_singletons = True mode = "automatic" dict = None mols = Read(ligand_filename) if verbose: print 'read ', ligand_filename mol = mols[0] if len(mols)>1: ctr = 1 for m in mols[1:]: ctr += 1 if len(m.allAtoms)>len(mol.allAtoms): mol = m coord_dict = {} for a in mol.allAtoms: coord_dict[a] = a.coords mol.buildBondsByDistance() if charges_to_add is not None: preserved = {} preserved_types = preserve_charge_types.split(',') for t in preserved_types: if not len(t): continue ats = mol.allAtoms.get(lambda x: x.autodock_element==t) for a in ats: if a.chargeSet is not None: preserved[a] = [a.chargeSet, a.charge] LPO = AD4LigandPreparation(mol, mode, repairs, charges_to_add, cleanup, allowed_bonds, root, outputfilename=outputfilename, dict=dict, check_for_fragments=check_for_fragments, bonds_to_inactivate=bonds_to_inactivate, inactivate_all_torsions=inactivate_all_torsions, attach_nonbonded_fragments=attach_nonbonded_fragments, attach_singletons=attach_singletons) if charges_to_add is not None: for atom, chargeList in preserved.items(): atom._charges[chargeList[0]] = chargeList[1] atom.chargeSet = chargeList[0] bad_list = [] for a in mol.allAtoms: if a in coord_dict.keys() and a.coords!=coord_dict[a]: bad_list.append(a) if len(bad_list): print len(bad_list), ' atom coordinates changed!' for a in bad_list: print a.name, ":", coord_dict[a], ' -> ', a.coords else: if verbose: print "No change in atomic coordinates" if mol.returnCode!=0: sys.stderr.write(mol.returnMsg+"\n")
#to write output #(2) setup default output filename if necessary #-g : rigid output filename if rigid_filename == None: rigid_filename = rM.name + '_rigid.pdbqt' if verbose: print("rigid filename is %s" % rigid_filename) #-x : flexible output filename if flexres_filename == None: flexres_filename = rM.name + '_flex.pdbqt' if verbose: print("flexible residue filename is %s" % flexres_filename) #(3) use this class in AutoDockTools for writing formatted outputfiles... frp = AD4FlexibleReceptorPreparation(rM, mode='interactive', rigid_filename=rigid_filename, residues=[resP], flexres_filename=flexres_filename) frp.write_flex([resP], flexres_filename) frp.write_rigid(rM, rigid_filename) if new_flexres_filename is None: new_flexres_filename = "new_" + flexres_filename flexresMol = Read(flexres_filename)[0] LPO = AD4LigandPreparation(flexresMol, root=0, outputfilename=new_flexres_filename) # To execute this command type: # prepare_covalent_flexres.py -l filename -r receptor_filename -l ligand_to_superimpose_filename -b atom1_atom2 -R residue #specific example: #python -i prepare_covalent_flexres.py -r 1pwc-protein.pdbqt -l 1pwc-ligand.pdbqt -b OG_CB -R SER62 -g 1pwc_rigid.pdbqt -x 1pwc_flex.pdbqt