コード例 #1
0
 def test_save_method_handles_no_cid_number_found(self, pcp_patch):
     pcp_patch.side_effect = IndexError
     data = deepcopy(self.cpd_data)
     data.update({'cid_number': ''})
     compound = Odorant(**data)
     with self.assertRaises(ValidationError):
         compound.save()
コード例 #2
0
 def test_supplier_clean_field_method(self, pcp_patch):
     pcp_patch.return_value = [MockPubChemPyObject('synonyms', cid=5678)]
     data = self.cpd_data.copy()
     data.update({'supplier': Odorant.supplier_choices[0][0]})
     compound = Odorant(**data)
     with self.assertRaises(ValidationError):
         compound.save()
コード例 #3
0
 def odorant_set(self):
     qs = Odorant.substructure_matches(self.smiles) | Odorant.name_matches(
         self.iupac_name_pattern, self.name)
     if self.excludes:
         chars = [i for i in self.excludes]
         for s in chars:
             qs = qs.exclude(smiles__icontains=s)
     if self.includes:
         chars = [i for i in self.includes]
         for s in chars:
             qs = qs.filter(smiles__icontains=s)
     if self.max_carbons:
         return [a for a in qs if a.carbon_count <= self.max_carbons]
     return qs
コード例 #4
0
ファイル: substructure_detail.py プロジェクト: paulosjd/frags
 def get_queryset(self):
     notes_qs = UserOdorant.objects.filter(user=self.request.user.profile).values('compound')
     if not notes_qs:
         return Odorant.objects.none()
     cpd_id_list = [a['compound'] for a in notes_qs]
     queryset = Odorant.objects.filter(id__in=cpd_id_list)
     return Odorant.substructure_matches(self.object.smiles, queryset)
コード例 #5
0
def process_cas(request):
    cas_no = request.GET.get('cas_number')
    try:
        obj = Odorant.objects.get(cas_number__exact=cas_no)
        data = {
            'object_exists': obj.get_absolute_url(),
            'object_exists_name': str(obj),
        }
        return JsonResponse(data)
    except ObjectDoesNotExist:
        pass
    try:
        smiles = cirpy.query(cas_no, 'smiles')[0].value
        pcp_query = pcp.get_compounds(smiles, 'smiles')[0]
        cid_no = pcp_query.cid
    except IndexError:
        return JsonResponse({
            'error': 'No compound found for this CAS number'
        })
    if smiles and cid_no:
        data = {
            'chemical_name': Odorant.scrape_compound_name(cid_no),
            'iupac_name': pcp_query.iupac_name,
            'structure_url': 'https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid={}&amp;t=l'.format(cid_no),
            'hidden_cid': cid_no,
            'smiles': smiles,
        }
        return JsonResponse(data)
コード例 #6
0
 def test_substructure_matches_for_valid_matching_smiles_string(self):
     output = Odorant.substructure_matches('CCCCCC(O)')
     self.assertIn(self.compound.id, [a.id for a in output])
     self.assertIsNone(Odorant.substructure_matches('invalid_smiles'))
コード例 #7
0
 def test_save_method_raises_validation_error_if_incomplete_data(self):
     compound = Odorant(cas_number='123-456-78')
     with self.assertRaises(ValidationError):
         compound.save()
コード例 #8
0
ファイル: substructure_detail.py プロジェクト: paulosjd/frags
 def get_queryset(self):
     unfiltered = super(ChemFilterSubstructureDetail, self).get_queryset
     filter_method = getattr(Odorant.objects, self.kwargs['chem_type'], unfiltered)
     return Odorant.substructure_matches(self.object.smiles, filter_method())