Code Monkey home page Code Monkey logo

Comments (5)

hkmztrk avatar hkmztrk commented on July 16, 2024

@wmmxk Have you solved this?

from chembl_webresource_client.

wmmxk avatar wmmxk commented on July 16, 2024

It turned out my code got stuck when fetching descriptor for one molecule. So I put my code in a try except statement. Now it is OK.

pbar = tqdm(enumerate(InchiKeys,1), total = len(InchiKeys))
descriptor_all = {}
molecule = new_client.molecule
for i, InchiKey in pbar:
try:
SMILE = molecule.get(InchiKey)['molecule_structures']['canonical_smiles']
chemical = utils.smiles2ctab(SMILE)
log_p = json.loads(utils.logP(chemical))[0]
descriptors = json.loads(utils.descriptors(chemical))[0]
descriptors["log_p"] = log_p
descriptor_all[InchiKey] = descriptors
except:
bad_keys.append(InchiKey)

from chembl_webresource_client.

hkmztrk avatar hkmztrk commented on July 16, 2024

thank you @wmmxk , using try except blocks worked for me as well :)

from chembl_webresource_client.

juanfmx2 avatar juanfmx2 commented on July 16, 2024

Hi @wmmxk, @hkmztrk, sorry it took me a while to get back to you, but I am in charge of other projects and I have not been able to work on the webs services lately, yes, the issue here is you are getting 404 when there are no molecules in the database with that inchi key, so the try/except is the right way to go. However, take into account that our smiles2ctab/logP/etc service is based on top of rdkit, but we are not sure sure wether it could fail for a given complex molecule. so if you want to know for sure wether the inchi key is in our database the try/except should only surround the molecule.get

pbar = tqdm(enumerate(inchi_keys,1), total = len(inchi_keys))
descriptor_all = {}
molecule = new_client.molecule
for i, inchi_key in pbar:
  try:
    smiles_i = molecule.get(inchi_key)['molecule_structures']['canonical_smiles']
  except:
    # Inchi key was not found in ChEMBL
    bad_keys.append(inchi_key)

  try:
    molecule_ctab_i = utils.smiles2ctab(smiles_i)
    log_p = json.loads(utils.logP(molecule_ctab_i))[0]
    descriptors = json.loads(utils.descriptors(molecule_ctab_i))[0]
    descriptors["log_p"] = log_p
    descriptor_all[inchi_key] = descriptors
  except:
    # smiles2ctab, logP or something else failed
    pass

from chembl_webresource_client.

wmmxk avatar wmmxk commented on July 16, 2024

Hi @juanfmx2 . No worries. I totally understand a programmer is usually working on a few projects. Yes, I agree I need to test the particular molecule which fails my code. Initially, I thought it is because the website does not allow too many visit from one IP in a very short time.

from chembl_webresource_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.