def build_ligand_properties(self): lp = LigandProperities() lt = LigandType.objects.get(name = 'small molecule') lp.ligand_type = lt lp.smiles = None lp.inchikey = None lp.sequence= None lp.mw = None lp.rotatable_bonds = None lp.hacc = None lp.hdon = None lp.logp = None lp.save() self.logger.info("Could not create ligand, empty is returned") return lp
def main_func(self, positions, iteration, count, lock): # print(positions,iteration,count,lock) ligands = self.ligand_dump while count.value < len(ligands): with lock: l = ligands[count.value] count.value += 1 if count.value % 10000 == 0: print('{} Status {} out of {}'.format( datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'), count.value, len(ligands))) if 'logp' not in l: # temp skip to only use "full" annotated ligands continue lp = LigandProperities.objects.filter( inchikey=l['inchikey']).first() ligand = None if lp: # Check if inchikey is there ligand = Ligand.objects.filter( name=l['name'], properities=lp).prefetch_related( 'properities__ligand_type', 'properities__web_links', 'properities__vendors').first() # The name with corresponding inchikey is there, assume all is good and skip. # Will add links to make sure they're there. if not ligand: if lp: print(l['name'], 'is there! (but not by name, only inchi') ligand = Ligand() ligand.properities = lp ligand.name = l['name'] ligand.canonical = l['canonical'] ligand.ambigious_alias = l['ambigious_alias'] ligand.save() else: # No ligand seems to match by inchikey -- start creating it. # Make LigandProperities first lt, created = LigandType.objects.get_or_create( slug=l['ligand_type__slug'], defaults={'name': l['ligand_type__name']}) lp = LigandProperities() lp.inchikey = l['inchikey'] lp.smiles = l['smiles'] lp.mw = l['mw'] lp.logp = l['logp'] lp.rotatable_bonds = l['rotatable_bonds'] lp.hacc = l['hacc'] lp.hdon = l['hdon'] lp.ligand_type = lt lp.save() ligand = Ligand() ligand.properities = lp ligand.name = l['name'] ligand.canonical = l['canonical'] ligand.ambigious_alias = l['ambigious_alias'] ligand.save() # create links - impossible to make duplicates so no need to check if there already if ligand.properities.web_links.count() < len(l['web_links']): for link in l['web_links']: wr = WebResource.objects.get(slug=link['web_resource']) wl, created = WebLink.objects.get_or_create( index=link['index'], web_resource=wr) ligand.properities.web_links.add(wl) # create vendors - impossible to make duplicates so no need to check if there already if ligand.properities.vendors.count() < len(l['vendors']): for link in l['vendors']: lv = LigandVendors.objects.get(slug=link['vendor_slug']) check = LigandVendorLink.objects.filter( sid=link['sid']).exists() if not check: lvl = LigandVendorLink() lvl.sid = link['sid'] lvl.vendor = lv lvl.lp = ligand.properities lvl.vendor_external_id = link['vendor_external_id'] lvl.url = link['url'] lvl.save()
def main_func(self, positions, iteration,count,lock): # print(positions,iteration,count,lock) ligands = self.ligand_dump while count.value<len(ligands): with lock: l = ligands[count.value] count.value +=1 if count.value % 10000 == 0: print('{} Status {} out of {}'.format( datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'), count.value, len(ligands))) if 'logp' not in l: # temp skip to only use "full" annotated ligands continue lp = LigandProperities.objects.filter(inchikey=l['inchikey']).first() ligand = None if lp: # Check if inchikey is there ligand = Ligand.objects.filter(name=l['name'], properities=lp).prefetch_related('properities__ligand_type','properities__web_links','properities__vendors').first() # The name with corresponding inchikey is there, assume all is good and skip. # Will add links to make sure they're there. if not ligand: if lp: print(l['name'],'is there! (but not by name, only inchi') ligand = Ligand() ligand.properities = lp ligand.name = l['name'] ligand.canonical = l['canonical'] ligand.ambigious_alias = l['ambigious_alias'] ligand.save() else: # No ligand seems to match by inchikey -- start creating it. # Make LigandProperities first lt, created = LigandType.objects.get_or_create(slug=l['ligand_type__slug'],defaults = {'name':l['ligand_type__name']}) lp = LigandProperities() lp.inchikey = l['inchikey'] lp.smiles = l['smiles'] lp.mw = l['mw'] lp.logp = l['logp'] lp.rotatable_bonds = l['rotatable_bonds'] lp.hacc = l['hacc'] lp.hdon = l['hdon'] lp.ligand_type = lt lp.save() ligand = Ligand() ligand.properities = lp ligand.name = l['name'] ligand.canonical = l['canonical'] ligand.ambigious_alias = l['ambigious_alias'] ligand.save() # create links - impossible to make duplicates so no need to check if there already if ligand.properities.web_links.count()<len(l['web_links']): for link in l['web_links']: wr = WebResource.objects.get(slug=link['web_resource']) wl, created = WebLink.objects.get_or_create(index=link['index'], web_resource=wr) ligand.properities.web_links.add(wl) # create vendors - impossible to make duplicates so no need to check if there already if ligand.properities.vendors.count()<len(l['vendors']): for link in l['vendors']: lv = LigandVendors.objects.get(slug = link['vendor_slug']) check = LigandVendorLink.objects.filter(sid=link['sid']).exists() if not check: lvl = LigandVendorLink() lvl.sid = link['sid'] lvl.vendor = lv lvl.lp = ligand.properities lvl.vendor_external_id = link['vendor_external_id'] lvl.url = link['url'] lvl.save()