Example #1
0
def main(pathway, pdb_with_connects, ligand_chain="L", outfilename=None):
    pdb = pm.PDB(pdb_with_connects, chain=ligand_chain)
    ligand = "".join(pdb.get_atoms_of_chain())
    connects = "".join(pdb.read_conect())
    ligand_with_connects = ligand + connects
    # Temporary file to extract the indexes of the ligand
    with open("ligand_with_connects_tmp.pdb", "w") as out:
        out.write(ligand_with_connects)
    pdb = pm.PDB(in_pdb="ligand_with_connects_tmp.pdb", chain=ligand_chain)
    names_dictionary = pdb.get_names_dictionary()
    os.remove("ligand_with_connects_tmp.pdb")
    pathway_snapshots = utilities.getSnapshots(pathway)
    new_pathway = []
    sys.stderr.write("Rebuilding indexes...\n")
    for snap in pathway_snapshots:
        with open("snap_tmp.pdb", "w") as out:
            out.write(snap)
        pdb = pm.PDB(in_pdb="snap_tmp.pdb", chain=ligand_chain)
        os.remove("snap_tmp.pdb")
        ligand = pdb.get_atoms_of_chain()
        complex_no_ligand = sorted(
            list(set(pdb.read_atoms_section()) ^ set(ligand)))
        new_ligand = []
        for index, name in names_dictionary.items():
            for line in ligand:
                pdb_name = pm.get_atom_pdb_name_from_line(line).strip()
                if name == pdb_name:
                    new_line = pm.set_index_to_line(line, index)
                    new_ligand.append(new_line)
        new_ligand_with_connects = "".join(new_ligand) + connects
        new_complex = "".join(complex_no_ligand) + new_ligand_with_connects
        new_pathway.append(new_complex)

    sys.stderr.write("Writing connects...\n")
    if not outfilename:
        outfilename = "{}_connected.pdb".format(pathway.split(".pdb")[0])
    if os.path.exists(outfilename):
        os.remove(outfilename)
    for n, model in enumerate(new_pathway):
        with open(outfilename, "a") as output:
            output.write("MODEL {}\n".format(n))
            output.write(model)
            output.write("ENDMDL\n")
Example #2
0
 def test_file_content(self):
     result_files = glob.glob("results_testing_convert/pdbs/*")
     chains = []
     resnames = []
     resnums = []
     for pdb in result_files:
         pdb_class = pdbm.PDB(pdb)
         for line in pdb_class.read_atoms_section():
             chains.append(pdbm.get_chain_from_line(line))
             resnames.append(pdbm.get_resname_from_line(line).strip())
             resnums.append(pdbm.get_resnum_from_line(line).strip())
     assert list(set(chains)) == [self.CHAIN] and list(set(resnames)) == [self.RESNAME] \
            and list(set(resnums)) == [str(self.RESNUM)]
Example #3
0
 def prepare_frag_pele_instructions(self):
     instructions = []
     lib_manager.LibraryChecker.check_library_format(self)
     for pdb in self.library_files:
         try:
             atom_idx = self.select_atom_to_grow(pdb)
             pdb_obj = pdb_modifier.PDB(pdb)
             instruction_line = "{}   {}  {}".format(
                 os.path.abspath(pdb), self.heavy_atom_pdb_complex,
                 pdb_obj.find_pdb_atom_name_of_idx(atom_idx).strip())
             print(instruction_line)
             instructions.append(instruction_line)
         except Exception as e:
             print(e)
     self.instructions = "\n".join(instructions)
 def prepare_library(self, chain, resname, resnum):
     if self.format == ".pdb":
         for pdb in self.get_files():
             pdb_object = pdb_modifier.PDB(in_pdb=pdb, chain=chain, resname=resname, resnum=resnum)
             pdb_object.modify_pdb()
             pdb_object.overwrite_pdb()
 def get_names_dictionary_from_ligand(self):
     if not os.path.exists("tmp/ligand.pdb"):
         self.tmp_ligand()
     pdb_ligand = pdm.PDB("tmp/ligand.pdb", self.chain)
     dictionary_names = pdb_ligand.get_names_dictionary()
     return dictionary_names