示例#1
0
def similarity(request):
    if request.method == 'POST':
        smiles = request.POST.get("smiles", None)
        method = request.POST.get('similarity_method', None)
        threshold = request.POST.get('threshold', None)
        searched_image = create_compound_image(smiles, smiles=True)
        if searched_image:
            searched_img_tag = create_image_tag(searched_image)
            returned_compounds = similarity_search(smiles,
                                                   method=method.lower(),
                                                   threshold=float(threshold))
            if not returned_compounds:
                return render(
                    request, 'cmpd_reg/similarity.html', {
                        'searched_smiles': smiles,
                        'searched_compound_image': searched_img_tag,
                        'no_matches': True,
                    })
            matched_output = []
            id_list = []
            for structure in returned_compounds:
                cmpd_obj = {}
                cmpd_obj['id'] = str(structure.id)
                id_list.append(str(structure.id))
                cmpd_obj['smiles'] = structure.smiles
                cmpd_obj['inchi'] = structure.inchi
                cmpd_obj['property'] = structure.property
                pil_image = create_compound_image(structure.molecule)
                cmpd_obj['image'] = create_image_tag(pil_image)
                matched_output.append(cmpd_obj)
            return render(
                request, 'cmpd_reg/similarity.html', {
                    'searched_smiles':
                    smiles,
                    'searched_compound_image':
                    searched_img_tag,
                    'matched_structures':
                    matched_output,
                    'id_list':
                    mark_safe(json.dumps(id_list, cls=DjangoJSONEncoder)),
                })
        else:
            return render(
                request, 'cmpd_reg/similarity.html', {
                    'smiles_error':
                    "Error! Could not convert SMILES '{}' to image".format(
                        smiles),
                })

    return render(request, 'cmpd_reg/similarity.html', {})
示例#2
0
def creg_index(request):
    if request.method == 'POST':
        smiles = request.POST.get("smiles", None)
        inchi = request.POST.get("inchi", False)
        inchi_check = True if inchi == 'on' else False
        if not smiles:
            return render(request, 'cmpd_reg/cmpd-reg.html', {})
        try:
            result_compound, is_new = get_or_create_compound(
                smiles, clean=True, inchi_standard=inchi_check)
        except Exception, e:
            print str(e)
            return render(
                request, 'cmpd_reg/cmpd-reg.html', {
                    'smiles_error':
                    "Error! Could not convert SMILES '{}' to molecule object".
                    format(smiles),
                })
        searched_image = create_compound_image(smiles, smiles=True)
        if searched_image:
            img_tag = create_image_tag(searched_image)
            return render(
                request, 'cmpd_reg/cmpd-reg.html', {
                    'searched_smiles': smiles,
                    'searched_compound_image': img_tag,
                    'returned_compound': str(result_compound.id),
                    'is_new': str(is_new),
                })
        else:
            return render(
                request, 'cmpd_reg/cmpd-reg.html', {
                    'smiles_error':
                    "Error! Could not convert SMILES '{}' to image".format(
                        smiles),
                })
示例#3
0
def creg_index(request):
	if request.method == 'POST':
		smiles = request.POST.get("smiles", None)
		inchi = request.POST.get("inchi", False)
		inchi_check = True if inchi == 'on' else False
		if not smiles:
			return render(request, 'cmpd_reg/cmpd-reg.html', {})
		try:
			result_compound, is_new = get_or_create_compound(smiles, clean=True, inchi_standard=inchi_check)
		except Exception, e:
			print str(e)
			return render(request, 'cmpd_reg/cmpd-reg.html', {
				'smiles_error': "Error! Could not convert SMILES '{}' to molecule object".format(smiles),
			})
		searched_image = create_compound_image(smiles, smiles=True)
		if searched_image:
			img_tag = create_image_tag(searched_image)
			return render(request, 'cmpd_reg/cmpd-reg.html', {
				'searched_smiles': smiles,
				'searched_compound_image': img_tag,
				'returned_compound': str(result_compound.id),
				'is_new': str(is_new),
			})
		else:
			return render(request, 'cmpd_reg/cmpd-reg.html', {
				'smiles_error': "Error! Could not convert SMILES '{}' to image".format(smiles),
			})
示例#4
0
def similarity(request):
	if request.method == 'POST':
		smiles = request.POST.get("smiles", None)
		method = request.POST.get('similarity_method', None)
		threshold = request.POST.get('threshold', None)
		searched_image = create_compound_image(smiles, smiles=True)
		if searched_image:
			searched_img_tag = create_image_tag(searched_image)
			returned_compounds = similarity_search(smiles, method=method.lower(), threshold=float(threshold))
			if not returned_compounds:
				return render(request, 'cmpd_reg/similarity.html', {
					'searched_smiles': smiles,
					'searched_compound_image': searched_img_tag,
					'no_matches': True,
				})
			matched_output = []
			id_list = []
			for structure in returned_compounds:
				cmpd_obj = {}
				cmpd_obj['id'] = str(structure.id)
				id_list.append(str(structure.id))
				cmpd_obj['smiles'] = structure.smiles
				cmpd_obj['inchi'] = structure.inchi
				cmpd_obj['property'] = structure.property
				pil_image = create_compound_image(structure.molecule)
				cmpd_obj['image'] = create_image_tag(pil_image)
				matched_output.append(cmpd_obj)
			return render(request, 'cmpd_reg/similarity.html', {
				'searched_smiles': smiles,
				'searched_compound_image': searched_img_tag,
				'matched_structures': matched_output,
				'id_list': mark_safe(json.dumps(id_list, cls=DjangoJSONEncoder)),
			})
		else:
			return render(request, 'cmpd_reg/similarity.html', {
				'smiles_error': "Error! Could not convert SMILES '{}' to image".format(smiles),
			})

	return render(request, 'cmpd_reg/similarity.html', {})
示例#5
0
def substructure(request):
    if request.method == 'POST':
        smiles = request.POST.get("smiles", None)
        smarts = request.POST.get("smarts", None)
        search_type = request.POST.get("search_type", None)
        search_type_options = {'Normal': False, 'Inverted': True}
        if smarts:
            print "Using SMARTS pattern: {}".format(smarts)
            matched_substructures = substructure_search(
                smarts,
                is_smarts=True,
                inverted=search_type_options[search_type])
            if not matched_substructures:
                return render(request, 'cmpd_reg/substructure.html', {
                    'searched_smiles': smarts,
                    'no_matches': True,
                })
            matched_output = []
            id_list = []
            for substruct in matched_substructures:
                cmpd_obj = {}
                cmpd_obj['id'] = str(substruct.id)
                id_list.append(str(substruct.id))
                cmpd_obj['smiles'] = substruct.smiles
                cmpd_obj['inchi'] = substruct.inchi
                cmpd_obj['property'] = substruct.property
                pil_image = create_substruct_image(substruct.molecule, smarts)
                cmpd_obj['image'] = create_image_tag(pil_image)
                matched_output.append(cmpd_obj)
            return render(
                request, 'cmpd_reg/substructure.html', {
                    'searched_smiles':
                    smarts,
                    'matched_substructures':
                    matched_output,
                    'id_list':
                    mark_safe(json.dumps(id_list, cls=DjangoJSONEncoder)),
                })
        searched_image = create_compound_image(smiles, smiles=True)
        if searched_image:
            searched_img_tag = create_image_tag(searched_image)
            matched_substructures = substructure_search(
                smiles, inverted=search_type_options[search_type])
            if not matched_substructures:
                return render(
                    request, 'cmpd_reg/substructure.html', {
                        'searched_smiles': smiles,
                        'searched_compound_image': searched_img_tag,
                        'no_matches': True,
                    })
            matched_output = []
            id_list = []
            for substruct in matched_substructures:
                cmpd_obj = {}
                cmpd_obj['id'] = str(substruct.id)
                id_list.append(str(substruct.id))
                cmpd_obj['smiles'] = substruct.smiles
                cmpd_obj['inchi'] = substruct.inchi
                cmpd_obj['property'] = substruct.property
                pil_image = create_substruct_image(substruct.molecule, smiles)
                cmpd_obj['image'] = create_image_tag(pil_image)
                matched_output.append(cmpd_obj)
            return render(
                request, 'cmpd_reg/substructure.html', {
                    'searched_smiles':
                    smiles,
                    'searched_compound_image':
                    searched_img_tag,
                    'matched_substructures':
                    matched_output,
                    'id_list':
                    mark_safe(json.dumps(id_list, cls=DjangoJSONEncoder)),
                })
        else:
            return render(
                request, 'cmpd_reg/substructure.html', {
                    'smiles_error':
                    "Error! Could not convert SMILES '{}' to image".format(
                        smiles),
                })
    return render(request, 'cmpd_reg/substructure.html', {})
示例#6
0
def substructure(request):
	if request.method == 'POST':
		smiles = request.POST.get("smiles", None)
		smarts = request.POST.get("smarts", None)
		search_type = request.POST.get("search_type", None)
		search_type_options = {
			'Normal': False,
			'Inverted': True
		}
		if smarts:
			print "Using SMARTS pattern: {}".format(smarts)
			matched_substructures = substructure_search(smarts, is_smarts=True, inverted=search_type_options[search_type])
			if not matched_substructures:
				return render(request, 'cmpd_reg/substructure.html', {
					'searched_smiles': smarts,
					'no_matches': True,
				})
			matched_output = []
			id_list = []
			for substruct in matched_substructures:
				cmpd_obj = {}
				cmpd_obj['id'] = str(substruct.id)
				id_list.append(str(substruct.id))
				cmpd_obj['smiles'] = substruct.smiles
				cmpd_obj['inchi'] = substruct.inchi
				cmpd_obj['property'] = substruct.property
				pil_image = create_substruct_image(substruct.molecule, smarts)
				cmpd_obj['image'] = create_image_tag(pil_image)
				matched_output.append(cmpd_obj)
			return render(request, 'cmpd_reg/substructure.html', {
				'searched_smiles': smarts,
				'matched_substructures': matched_output,
				'id_list': mark_safe(json.dumps(id_list, cls=DjangoJSONEncoder)),
			})
		searched_image = create_compound_image(smiles, smiles=True)
		if searched_image:
			searched_img_tag = create_image_tag(searched_image)
			matched_substructures = substructure_search(smiles, inverted=search_type_options[search_type])
			if not matched_substructures:
				return render(request, 'cmpd_reg/substructure.html', {
					'searched_smiles': smiles,
					'searched_compound_image': searched_img_tag,
					'no_matches': True,
				})
			matched_output = []
			id_list = []
			for substruct in matched_substructures:
				cmpd_obj = {}
				cmpd_obj['id'] = str(substruct.id)
				id_list.append(str(substruct.id))
				cmpd_obj['smiles'] = substruct.smiles
				cmpd_obj['inchi'] = substruct.inchi
				cmpd_obj['property'] = substruct.property
				pil_image = create_substruct_image(substruct.molecule, smiles)
				cmpd_obj['image'] = create_image_tag(pil_image)
				matched_output.append(cmpd_obj)
			return render(request, 'cmpd_reg/substructure.html', {
				'searched_smiles': smiles,
				'searched_compound_image': searched_img_tag,
				'matched_substructures': matched_output,
				'id_list': mark_safe(json.dumps(id_list, cls=DjangoJSONEncoder)),
			})
		else:
			return render(request, 'cmpd_reg/substructure.html', {
				'smiles_error': "Error! Could not convert SMILES '{}' to image".format(smiles),
			})
	return render(request, 'cmpd_reg/substructure.html', {})