Ejemplo n.º 1
0
def get_params(smiles, request):
    try:
        smiles = canon_input(smiles)
    except:
        smiles = ""
    height = None
    mol = None
    bond_id_list = []
    highlightBondColors = {}
    if "height" in request.GET:
        height = int(request.GET["height"])
    width = None
    if "width" in request.GET:
        width = int(request.GET["width"])
    if "atom_indices" in request.GET:
        mol = Chem.MolFromSmiles(smiles)
        bond_id_list, highlightBondColors, mol = parse_atom_ids(
            request.GET["atom_indices"], mol)
    if "Xe" in smiles:
        bond_id_list, highlightBondColors, mol = parse_xenons(smiles)
    img_type = request.GET.get("img_type", None)
    get_mol = draw_mol(
        smiles,
        width=width,
        height=height,
        img_type=img_type,
        highlightBonds=bond_id_list,
        mol=mol,
        bondcolors=highlightBondColors,
    )
    if type(get_mol) == HttpResponse:
        return get_mol
    return HttpResponse(get_mol)
Ejemplo n.º 2
0
def get_full_graph(smiles,
                   graph_url="neo4j",
                   graph_auth="neo4j/neo4j",
                   isomericSmiles=True):
    """
    For the given smiles and graph credentials, query the Neo4j database
    :param: smiles
    :param: graph_url - note that for local Neo4j graphs, this can be set to 'localhost'
    :param: graph_auth - username/password.
    :param: isomericSmiles True/False
    :return: Output dictionary - This is returned "as-is" from the Fragalysis-Backend api/graph query.
    """

    msg = f"get_full_graph(\"{smiles}\", graph_url={graph_url}, isomericSmiles={isomericSmiles})"
    smiles = canon_input(smiles, isomericSmiles)
    msg += f" canon_smiles=\"{smiles}\""

    driver = get_driver(graph_url, graph_auth)
    records = []
    with driver.session() as session:

        debug_proximal_num_records = 0
        for record in session.run(find_proximal_query(smiles)):
            debug_proximal_num_records += 1
            ans = define_proximal_type(record)
            records.append(ans)
        msg += f" n_proximals={debug_proximal_num_records}"
        debug_double_edge_num_records = 0
        for record in session.run(find_double_edge_query(smiles)):
            debug_double_edge_num_records += 0
            ans = define_double_edge_type(record)
            records.append(ans)
        msg += f" n_double_edge={debug_double_edge_num_records}"
        for label in list(set([x.label for x in records])):
            # Linkers are meaningless
            if "." in label:
                continue

    if records:
        orga_dict = organise(records, None)
        orga_dict_len = len(orga_dict)

        msg += f" orga_dict_len={orga_dict_len}"
        logger.info(f"GRAPH -> {msg}")
        return orga_dict

    msg += f" (fall-through) ret=None"
    logger.info(f"GRAPH -> {msg}")
    return None
Ejemplo n.º 3
0
def get_full_graph(smiles, graph_url="neo4j"):
    smiles = canon_input(smiles)
    driver = get_driver(graph_url)
    with driver.session() as session:
        records = []
        for record in session.read_transaction(find_proximal, smiles):
            ans = define_proximal_type(record)
            records.append(ans)
        for record in session.read_transaction(find_double_edge, smiles):
            ans = define_double_edge_type(record)
            records.append(ans)
        for label in list(set([x.label for x in records])):
            # Linkers are meaningless
            if "." in label:
                continue
        if records:
            orga_dict = organise(records, None)
            return orga_dict
        else:
            print("Nothing found for input: " + smiles)
Ejemplo n.º 4
0
def get_picks(smiles, num_picks, graph_url="neo4j", graph_auth="neo4j/neo4j"):
    smiles = canon_input(smiles)
    driver = get_driver(graph_url, graph_auth)
    with driver.session() as session:
        records = []
        for record in session.run(find_proximal_query(smiles)):
            ans = define_proximal_type(record)
            records.append(ans)
        for record in session.run(find_double_edge_query(smiles)):
            ans = define_double_edge_type(record)
            records.append(ans)
        for label in list(set([x.label for x in records])):
            # Linkers are meaningless
            if "." in label:
                continue
        if records:
            orga_dict = organise(records, num_picks)
            return orga_dict
        else:
            print("Nothing found for input: " + smiles)