frag_pele/Growing/add_fragment_from_pdbs.py
def check_collision(merged_structure, bond, theta, theta_interval, core_bond, list_of_atoms, fragment_bond,
                    core_structure, fragment_structure, pdb_complex, pdb_fragment, chain_complex, chain_fragment,
                    output_path, threshold_clash=None, only_grow=False, debug=False):
    """
    Given a structure composed by a core and a fragment, it checks that there is not collisions between the atoms of
    both. If it finds a collision, the molecule will be rotated "theta_interval" radians and the checking will be
    repeated. If it is not possible to find a conformation without atom collisions, it will print a warning.
    :param merged_structure: ProDy molecule with the core_structure and the fragment_structure concatenated.
    :param bond: Bio.PDB.Atom list composed by two elements: [heavy atom of the core, heavy atom of the fragment]
    :param theta: Initial rotation angle in rads.
    :param theta_interval: Rotation angle that will be added to theta.
    :param core_bond: Bio.PDB.Atom list with two elements: [heavy atom, hydrogen atom]. These two atoms have to be the
    ones participating in the bond of the core that we would like to use as linking point between core and fragment.
    :param list_of_atoms: list_of_atoms: Bio.PDB.Atom list with all the atoms of the fragment. These atoms have to contain
    coordinates.
    :param fragment_bond: Bio.PDB.Atom list with two elements: [hydrogen atom, heavy atom]. These two atoms have to be the
    ones participating in the bond of the fragment that we would like to use as linking point between fragment and core.
    :param core_structure: ProDy molecule that contain only the core ligand.
    :param fragment_structure: ProDy molecule that contain only the fragment ligand.
    :return: ProDy molecule with the core_structure and the fragment_structure (rotated and without intra-molecular
    clashes) around the axis of the bond.
    """
    core_resname = bond[0].get_parent().get_resname()
    frag_resname = bond[1].get_parent().get_resname()
    print(core_resname, frag_resname)
    if core_resname is frag_resname:
        logger.critical("The resname of the core and the fragment is the same. Please, change one of both")
    print("resname {} and within {} of resname {}".format(core_resname,
                                                          threshold_clash,
                                                          frag_resname))
    check_possible_collision = merged_structure.select("resname {} and within {} of resname {}".format(core_resname,
                                                                                                       threshold_clash,
                                                                                                        frag_resname))
    # This list only should have the atom of the fragment that will be bonded to the core, so if not we will have to
    # solve it
    if len(check_possible_collision.getNames()) > 1 or check_possible_collision.getNames()[0] != bond[0].name:
        print("We have a collision between atoms of the fragment {} and the core {} within {} A!" 
              " Rotating the fragment to solve it...".format(frag_resname, core_resname, threshold_clash))
        theta = theta + theta_interval
        if theta >= math.pi*2:
            print("Not possible solution, decreasing the angle of rotation...")
        else:
            rotated_structure = rotation_thought_axis(bond, theta, core_bond, list_of_atoms, fragment_bond, core_structure,
                                                      fragment_structure, pdb_complex, pdb_fragment, chain_complex, chain_fragment,
                                                      output_path=output_path, only_grow=only_grow)
            if debug:
                print(theta)
                prody.writePDB("testing_{}.pdb".format(theta), rotated_structure[0])
            recall = check_collision(merged_structure=rotated_structure[0], bond=bond, theta=theta, theta_interval=theta_interval, 
                                     core_bond=core_bond, list_of_atoms=list_of_atoms, fragment_bond=fragment_bond, core_structure=core_structure,
                                     fragment_structure=fragment_structure, pdb_complex=pdb_complex, pdb_fragment=pdb_fragment, 
                                     chain_complex=chain_complex, chain_fragment=chain_fragment,
                                     output_path=output_path, threshold_clash=threshold_clash, only_grow=only_grow, debug=debug)
            return recall
    else:
        return merged_structure

    Given a structure composed by a core and a fragment, it checks that there is not collisions between the atoms of
    both. If it finds a collision, the molecule will be rotated "theta_interval" radians and the checking will be
    repeated. If it is not possible to find a conformation without atom collisions, it will print a warning.
    :param merged_structure: ProDy molecule with the core_structure and the fragment_structure concatenated.
    :param bond: Bio.PDB.Atom list composed by two elements: [heavy atom of the core, heavy atom of the fragment]
    :param theta: Initial rotation angle in rads.
    :param theta_interval: Rotation angle that will be added to theta.
    :param core_bond: Bio.PDB.Atom list with two elements: [heavy atom, hydrogen atom]. These two atoms have to be the
    ones participating in the bond of the core that we would like to use as linking point between core and fragment.
    :param list_of_atoms: list_of_atoms: Bio.PDB.Atom list with all the atoms of the fragment. These atoms have to contain
    coordinates.
    :param fragment_bond: Bio.PDB.Atom list with two elements: [hydrogen atom, heavy atom]. These two atoms have to be the
    ones participating in the bond of the fragment that we would like to use as linking point between fragment and core.
    :param core_structure: ProDy molecule that contain only the core ligand.
    :param fragment_structure: ProDy molecule that contain only the fragment ligand.
    :return: ProDy molecule with the core_structure and the fragment_structure (rotated and without intra-molecular
    clashes) around the axis of the bond.
    
Given a structure composed by a core and a fragment, it checks that there is not collisions between the atoms of
both. If it finds a collision, the molecule will be rotated "theta_interval" radians and the checking will be
repeated. If it is not possible to find a conformation without atom collisions, it will print a warning.
Given a structure composed by a core and a fragment it checks that there is not collisions between the atoms of both . If it finds a collision the molecule will be rotated " theta_interval " radians and the checking will be repeated . If it is not possible to find a conformation without atom collisions it will print a warning .
def check_collision(merged_structure, bond, theta, theta_interval, core_bond, list_of_atoms, fragment_bond,
                    core_structure, fragment_structure, pdb_complex, pdb_fragment, chain_complex, chain_fragment,
                    output_path, threshold_clash=None, only_grow=False, debug=False):
    core_resname = bond[0].get_parent().get_resname()
    frag_resname = bond[1].get_parent().get_resname()
    print(core_resname, frag_resname)
    if core_resname is frag_resname:
        logger.critical("The resname of the core and the fragment is the same. Please, change one of both")
    print("resname {} and within {} of resname {}".format(core_resname,
                                                          threshold_clash,
                                                          frag_resname))
    check_possible_collision = merged_structure.select("resname {} and within {} of resname {}".format(core_resname,
                                                                                                       threshold_clash,
                                                                                                        frag_resname))
    if len(check_possible_collision.getNames()) > 1 or check_possible_collision.getNames()[0] != bond[0].name:
        print("We have a collision between atoms of the fragment {} and the core {} within {} A!" 
              " Rotating the fragment to solve it...".format(frag_resname, core_resname, threshold_clash))
        theta = theta + theta_interval
        if theta >= math.pi*2:
            print("Not possible solution, decreasing the angle of rotation...")
        else:
            rotated_structure = rotation_thought_axis(bond, theta, core_bond, list_of_atoms, fragment_bond, core_structure,
                                                      fragment_structure, pdb_complex, pdb_fragment, chain_complex, chain_fragment,
                                                      output_path=output_path, only_grow=only_grow)
            if debug:
                print(theta)
                prody.writePDB("testing_{}.pdb".format(theta), rotated_structure[0])
            recall = check_collision(merged_structure=rotated_structure[0], bond=bond, theta=theta, theta_interval=theta_interval, 
                                     core_bond=core_bond, list_of_atoms=list_of_atoms, fragment_bond=fragment_bond, core_structure=core_structure,
                                     fragment_structure=fragment_structure, pdb_complex=pdb_complex, pdb_fragment=pdb_fragment, 
                                     chain_complex=chain_complex, chain_fragment=chain_fragment,
                                     output_path=output_path, threshold_clash=threshold_clash, only_grow=only_grow, debug=debug)
            return recall
    else:
        return merged_structure
def check_collision ( merged_structure , bond , theta , theta_interval , core_bond , list_of_atoms , fragment_bond , core_structure , fragment_structure , pdb_complex , pdb_fragment , chain_complex , chain_fragment , output_path , threshold_clash = None , only_grow = False , debug = False ) : core_resname = bond [ 0 ] . get_parent ( ) . get_resname ( ) frag_resname = bond [ 1 ] . get_parent ( ) . get_resname ( ) print ( core_resname , frag_resname ) if core_resname is frag_resname : logger . critical ( "The resname of the core and the fragment is the same. Please, change one of both" ) print ( "resname {} and within {} of resname {}" . format ( core_resname , threshold_clash , frag_resname ) ) check_possible_collision = merged_structure . select ( "resname {} and within {} of resname {}" . format ( core_resname , threshold_clash , frag_resname ) ) if len ( check_possible_collision . getNames ( ) ) > 1 or check_possible_collision . getNames ( ) [ 0 ] != bond [ 0 ] . name : print ( "We have a collision between atoms of the fragment {} and the core {} within {} A!" " Rotating the fragment to solve it..." . format ( frag_resname , core_resname , threshold_clash ) ) theta = theta + theta_interval if theta >= math . pi * 2 : print ( "Not possible solution, decreasing the angle of rotation..." ) else : rotated_structure = rotation_thought_axis ( bond , theta , core_bond , list_of_atoms , fragment_bond , core_structure , fragment_structure , pdb_complex , pdb_fragment , chain_complex , chain_fragment , output_path = output_path , only_grow = only_grow ) if debug : print ( theta ) prody . writePDB ( "testing_{}.pdb" . format ( theta ) , rotated_structure [ 0 ] ) recall = check_collision ( merged_structure = rotated_structure [ 0 ] , bond = bond , theta = theta , theta_interval = theta_interval , core_bond = core_bond , list_of_atoms = list_of_atoms , fragment_bond = fragment_bond , core_structure = core_structure , fragment_structure = fragment_structure , pdb_complex = pdb_complex , pdb_fragment = pdb_fragment , chain_complex = chain_complex , chain_fragment = chain_fragment , output_path = output_path , threshold_clash = threshold_clash , only_grow = only_grow , debug = debug ) return recall else : return merged_structure
Given a structure composed by a core and a fragment, it checks that there is not collisions between the atoms of
both.
Given a structure composed by a core and a fragment it checks that there is not collisions between the atoms of both .
"""
    Given a structure composed by a core and a fragment, it checks that there is not collisions between the atoms of
    both. If it finds a collision, the molecule will be rotated "theta_interval" radians and the checking will be
    repeated. If it is not possible to find a conformation without atom collisions, it will print a warning.
    :param merged_structure: ProDy molecule with the core_structure and the fragment_structure concatenated.
    :param bond: Bio.PDB.Atom list composed by two elements: [heavy atom of the core, heavy atom of the fragment]
    :param theta: Initial rotation angle in rads.
    :param theta_interval: Rotation angle that will be added to theta.
    :param core_bond: Bio.PDB.Atom list with two elements: [heavy atom, hydrogen atom]. These two atoms have to be the
    ones participating in the bond of the core that we would like to use as linking point between core and fragment.
    :param list_of_atoms: list_of_atoms: Bio.PDB.Atom list with all the atoms of the fragment. These atoms have to contain
    coordinates.
    :param fragment_bond: Bio.PDB.Atom list with two elements: [hydrogen atom, heavy atom]. These two atoms have to be the
    ones participating in the bond of the fragment that we would like to use as linking point between fragment and core.
    :param core_structure: ProDy molecule that contain only the core ligand.
    :param fragment_structure: ProDy molecule that contain only the fragment ligand.
    :return: ProDy molecule with the core_structure and the fragment_structure (rotated and without intra-molecular
    clashes) around the axis of the bond.
    """ # This list only should have the atom of the fragment that will be bonded to the core, so if not we will have to # solve it
ProDy molecule with the core_structure and the fragment_structure (rotated and without intra-molecular
clashes) around the axis of the bond.
ProDy molecule with the core_structure and the fragment_structure ( rotated and without intra - molecular clashes ) around the axis of the bond .
merged_structure
ProDy molecule with the core_structure and the fragment_structure concatenated.
ProDy molecule with the core_structure and the fragment_structure concatenated .
bond
Bio.PDB.Atom list composed by two elements: [heavy atom of the core, heavy atom of the fragment]
Bio . PDB . Atom list composed by two elements : [ heavy atom of the core heavy atom of the fragment ]
theta
Initial rotation angle in rads.
Initial rotation angle in rads .
theta_interval
Rotation angle that will be added to theta.
Rotation angle that will be added to theta .
core_bond
Bio.PDB.Atom list with two elements: [heavy atom, hydrogen atom]. These two atoms have to be the
ones participating in the bond of the core that we would like to use as linking point between core and fragment.
Bio . PDB . Atom list with two elements : [ heavy atom hydrogen atom ] . These two atoms have to be the ones participating in the bond of the core that we would like to use as linking point between core and fragment .
list_of_atoms
Bio.PDB.Atom list with all the atoms of the fragment. These atoms have to contain
coordinates.
Bio . PDB . Atom list with all the atoms of the fragment . These atoms have to contain coordinates .
fragment_bond
Bio.PDB.Atom list with two elements: [hydrogen atom, heavy atom]. These two atoms have to be the
ones participating in the bond of the fragment that we would like to use as linking point between fragment and core.
Bio . PDB . Atom list with two elements : [ hydrogen atom heavy atom ] . These two atoms have to be the ones participating in the bond of the fragment that we would like to use as linking point between fragment and core .
core_structure
ProDy molecule that contain only the core ligand.
ProDy molecule that contain only the core ligand .
fragment_structure
ProDy molecule that contain only the fragment ligand.
ProDy molecule that contain only the fragment ligand .
pdb_complex
pdb_fragment
chain_complex
chain_fragment
output_path
threshold_clash
only_grow
debug