Ejemplo n.º 1
0
def analyse_mols(mols, target, specified_site=False, site_description=None):
    """Analyse a list of molecules for a given target

    :param mols: the Django molecules to analyse
    :param target: the Django target
    :param specified_site:
    :param site_description:
    :return: None
    """
    rd_mols = [Chem.MolFromMolBlock(x.sdf_info) for x in mols]
    if not specified_site:

        cluster_mols(rd_mols, mols, target)

    else:

        centre = process_site(rd_mols)

        # look for molgroup with same target and description
        mol_group = search_for_molgroup_by_description(
            target=target.title, description=site_description)

        if not mol_group:
            mol_group = MolGroup()
        mol_group.group_type = "MC"
        mol_group.target_id = target
        mol_group.x_com = centre[0]
        mol_group.y_com = centre[1]
        mol_group.z_com = centre[2]
        mol_group.description = site_description
        mol_group.save()

        ids = [m.id for m in mols]

        print([a['id'] for a in mol_group.mol_id.values()])

        for mol_id in ids:
            if mol_id not in [a['id'] for a in mol_group.mol_id.values()]:
                print(mol_id)
                this_mol = Molecule.objects.get(id=mol_id)
                mol_group.mol_id.add(this_mol)

    get_vectors(mols)
Ejemplo n.º 2
0
def cluster_mols(rd_mols, mols, target):
    """
    Cluster a series of 3D molecules
    :param rd_mols: the RDKit molecules to cluster
    :param mols:  the Django moleculs they refer to
    :param target:  the Django target it refers to
    :return: None
    """
    id_mols = [x.pk for x in mols]
    out_data = run_lig_cluster(rd_mols, id_mols)
    for clust_type in out_data:
        for cluster in out_data[clust_type]:
            # look for molgroup with same coords - need to implement tolerance?
            mol_group = search_for_molgroup_by_coords(coords=[out_data[clust_type][cluster]["centre_of_mass"][0],
                                                              out_data[clust_type][cluster]["centre_of_mass"][1],
                                                              out_data[clust_type][cluster]["centre_of_mass"][2]],
                                                      target=target.title)
            if not mol_group:
                mol_group = MolGroup()
            if clust_type != "c_of_m":
                mol_group.group_type = "PC"
            else:
                mol_group.group_type = "MC"
            mol_group.target_id = target
            mol_group.x_com = out_data[clust_type][cluster]["centre_of_mass"][0]
            mol_group.y_com = out_data[clust_type][cluster]["centre_of_mass"][1]
            mol_group.z_com = out_data[clust_type][cluster]["centre_of_mass"][2]
            mol_group.description = clust_type
            mol_group.save()
            for mol_id in out_data[clust_type][cluster]["mol_ids"]:
                if mol_id not in [a['id'] for a in mol_group.mol_id.values()]:
                    this_mol = Molecule.objects.get(id=mol_id)
                    mol_group.mol_id.add(this_mol)