frag_pele/Growing/template_selector.py
def change_ligandname(input_file, output):
    """
    From an input pdb file this function replace the first character of the ligand name
    string to the next one in alphabetic order
    """
    # Creating a list of capital letters
    letters = list(string.ascii_uppercase)
    with open(output, 'w') as output_f:
        with open(input_file) as input_f:
            for line in input_f:
                # We only want to read lines that contain information about the ligand
                if line.startswith("HETATM"):
                    # This is the ligandname of the original file, column 4.
                    ligandname_old = line.split()[3]

                    # We will transform this name into a list of letters (strings in python are unmutable)
                    ligandname_new = list(ligandname_old)

                    # Now, the index that we will select is the first letter of the ligandname
                    index = letters.index(ligandname_old[0])

                    # Doing this we are going to transform the first letter of the ligand name into
                    # the next in the alphabet. F.ex: CMB -> DMB
                    new_letter = letters[index+1]
                    ligandname_new[0] = new_letter

                    # Join again all the letters into a string
                    ligandname_new = "".join(ligandname_new)

                    # Write it in the file
                    output_f.write(line.replace(ligandname_old, ligandname_new))
                else:
                    # The rest of the file that don't have information about the ligand will stay unchanged
                    output_f.write(line)
    # We would like to delete the temporary input files
    os.remove(input_file)

    From an input pdb file this function replace the first character of the ligand name
    string to the next one in alphabetic order
    
From an input pdb file this function replace the first character of the ligand name
string to the next one in alphabetic order
From an input pdb file this function replace the first character of the ligand name string to the next one in alphabetic order
def change_ligandname(input_file, output):
    letters = list(string.ascii_uppercase)
    with open(output, 'w') as output_f:
        with open(input_file) as input_f:
            for line in input_f:
                if line.startswith("HETATM"):
                    ligandname_old = line.split()[3]
                    ligandname_new = list(ligandname_old)
                    index = letters.index(ligandname_old[0])
                    new_letter = letters[index+1]
                    ligandname_new[0] = new_letter
                    ligandname_new = "".join(ligandname_new)
                    output_f.write(line.replace(ligandname_old, ligandname_new))
                else:
                    output_f.write(line)
    os.remove(input_file)
def change_ligandname ( input_file , output ) : letters = list ( string . ascii_uppercase ) with open ( output , 'w' ) as output_f : with open ( input_file ) as input_f : for line in input_f : if line . startswith ( "HETATM" ) : ligandname_old = line . split ( ) [ 3 ] ligandname_new = list ( ligandname_old ) index = letters . index ( ligandname_old [ 0 ] ) new_letter = letters [ index + 1 ] ligandname_new [ 0 ] = new_letter ligandname_new = "" . join ( ligandname_new ) output_f . write ( line . replace ( ligandname_old , ligandname_new ) ) else : output_f . write ( line ) os . remove ( input_file )
From an input pdb file this function replace the first character of the ligand name
string to the next one in alphabetic order
From an input pdb file this function replace the first character of the ligand name string to the next one in alphabetic order
"""
    From an input pdb file this function replace the first character of the ligand name
    string to the next one in alphabetic order
    """ # Creating a list of capital letters # We only want to read lines that contain information about the ligand # This is the ligandname of the original file, column 4. # We will transform this name into a list of letters (strings in python are unmutable) # Now, the index that we will select is the first letter of the ligandname # Doing this we are going to transform the first letter of the ligand name into # the next in the alphabet. F.ex: CMB -> DMB # Join again all the letters into a string # Write it in the file # The rest of the file that don't have information about the ligand will stay unchanged # We would like to delete the temporary input files
input_file
output